From b28b6ced1c06fef3d1bb47fc7887f6ca0378330c Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 26 Nov 2021 14:19:40 +0800 Subject: [PATCH 01/90] Support multiple AP vap on test platform Port most codes from dut sample --- indigo_api_callback_tp.c | 219 ++++++++++++++++++++++++++++++++------- vendor_specific_tp.c | 65 +++++++++--- 2 files changed, 234 insertions(+), 50 deletions(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 3f1115c..5840f80 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -29,6 +29,7 @@ #include "indigo_api_callback.h" struct sta_platform_config sta_hw_config = {PHYMODE_AUTO, CHWIDTH_AUTO, false, false}; +struct interface_info* band_transmitter[16]; #ifdef _WTS_OPENWRT_ int rrm = 0, he_mu_edca = 0; @@ -120,6 +121,10 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re stop_loopback_data(NULL); + /* reset interfaces info */ + if (clear_interfaces_resource()) { + } + if (reset == RESET_TYPE_INIT) { len = unlink(get_hapd_conf_file()); if (len) { @@ -141,6 +146,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re system("uci -q delete wireless.@wifi-iface[0].own_ie_override"); system("uci -q delete wireless.@wifi-iface[1].own_ie_override"); #endif + memset(band_transmitter, 0, sizeof(band_transmitter)); } fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); @@ -211,7 +217,7 @@ static void add_mu_edca_params(char *output) { strcat(output, "he_mu_edca_ac_vo_timer=255\n"); } -static int generate_hostapd_config(char *output, int output_size, struct packet_wrapper *wrapper, char *ifname) { +static int generate_hostapd_config(char *output, int output_size, struct packet_wrapper *wrapper, struct interface_info* wlanp) { int i, ctrl_iface = 0; char buffer[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; #ifdef _WTS_OPENWRT_ @@ -227,8 +233,16 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ struct tlv_to_config_name* cfg = NULL; struct tlv_hdr *tlv = NULL; + int has_owe = 0; - sprintf(output, "ctrl_interface_group=0\ninterface=%s\n", ifname); +#if HOSTAPD_SUPPORT_MBSSID + if (wlanp->mbssid_enable && !wlanp->transmitter) + sprintf(output, "bss=%s\n", wlanp->ifname); + else + sprintf(output, "ctrl_interface_group=0\ninterface=%s\n", wlanp->ifname); +#else + sprintf(output, "ctrl_interface_group=0\ninterface=%s\n", wlanp->ifname); +#endif #ifdef _RESERVED_ /* The function is reserved for the defeault hostapd config */ @@ -302,14 +316,48 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ memcpy(ie_override, tlv->value, tlv->len); } #endif - + if (tlv->id == TLV_WPA_KEY_MGMT && strstr(tlv->value, "OWE")) { + has_owe = 1; + } memset(buffer, 0, sizeof(buffer)); - memcpy(buffer, tlv->value, tlv->len); - /* FILS discovery enable to set max interval 20 */ - if (tlv->id == TLV_HE_FILS_DISCOVERY_TX) - snprintf(buffer, sizeof(buffer), "20"); - sprintf(cfg_item, "%s=%s\n", cfg->config_name, buffer); - strcat(output, cfg_item); + memset(cfg_item, 0, sizeof(cfg_item)); + if (tlv->id == TLV_OWE_TRANSITION_BSS_IDENTIFIER) { + struct bss_identifier_info bss_info; + struct interface_info *wlan; + int bss_identifier; + char bss_identifier_str[8]; + memset(&bss_info, 0, sizeof(bss_info)); + memset(bss_identifier_str, 0, sizeof(bss_identifier_str)); + memcpy(bss_identifier_str, tlv->value, tlv->len); + bss_identifier = atoi(bss_identifier_str); + parse_bss_identifier(bss_identifier, &bss_info); + wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); + if (NULL == wlan) { + wlan = assign_wireless_interface_info(&bss_info); + } + printf("TLV_OWE_TRANSITION_BSS_IDENTIFIER: TLV_BSS_IDENTIFIER 0x%x identifier %d mapping ifname %s\n", + bss_identifier, + bss_info.identifier, + wlan ? wlan->ifname : "n/a" + ); + if (wlan) { + memcpy(buffer, wlan->ifname, strlen(wlan->ifname)); + sprintf(cfg_item, "%s=%s\n", cfg->config_name, buffer); + strcat(output, cfg_item); + if (has_owe) { + memset(cfg_item, 0, sizeof(cfg_item)); + sprintf(cfg_item, "ignore_broadcast_ssid=1\n"); + strcat(output, cfg_item); + } + } + } else { + memcpy(buffer, tlv->value, tlv->len); + /* FILS discovery enable to set max interval 20 */ + if (tlv->id == TLV_HE_FILS_DISCOVERY_TX) + snprintf(buffer, sizeof(buffer), "20"); + sprintf(cfg_item, "%s=%s\n", cfg->config_name, buffer); + strcat(output, cfg_item); + } if (tlv->id == TLV_CONTROL_INTERFACE) { ctrl_iface = 1; @@ -324,6 +372,11 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ indigo_logger(LOG_LEVEL_ERROR, "No Remote UDP ctrl interface TLV for TP"); return 0; } +#if HOSTAPD_SUPPORT_MBSSID + if (wlanp->mbssid_enable && wlanp->transmitter) { + strcat(output, "multiple_bssid=1\n"); + } +#endif #ifdef _WTS_OPENWRT_ if (!strncmp(band, "a", 1)) { @@ -400,38 +453,88 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe char *message = "DUT configured as AP : Configuration file created"; struct tlv_hdr *tlv; struct interface_info* wlan = NULL; + char bss_identifier_str[16]; + struct bss_identifier_info bss_info; + int bss_identifier = 0; - /* Single wlan case */ - tlv = find_wrapper_tlv_by_id(req, TLV_HW_MODE); + memset(buffer, 0, sizeof(buffer)); + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_IDENTIFIER); + memset(&bss_info, 0, sizeof(bss_info)); if (tlv) { - memset(hw_mode_str, 0, sizeof(hw_mode_str)); - memcpy(hw_mode_str, tlv->value, tlv->len); - if (!strncmp(hw_mode_str, "a", 1)) { - band = BAND_5GHZ; - tlv = find_wrapper_tlv_by_id(req, TLV_OP_CLASS); - if (tlv) { - memset(op_class, 0, sizeof(op_class)); - memcpy(op_class, tlv->value, tlv->len); - if (atoi(op_class) >= OP_CLASS_6G_20 && atoi(op_class) <= OP_CLASS_6G_160) - band = BAND_6GHZ; + /* Multiple wlans configure must carry TLV_BSS_IDENTIFIER */ + memset(bss_identifier_str, 0, sizeof(bss_identifier_str)); + memcpy(bss_identifier_str, tlv->value, tlv->len); + bss_identifier = atoi(bss_identifier_str); + parse_bss_identifier(bss_identifier, &bss_info); + wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); + if (NULL == wlan) { + wlan = assign_wireless_interface_info(&bss_info); + } + if (wlan && bss_info.mbssid_enable) { + configure_ap_enable_mbssid(); + if (bss_info.transmitter) { + band_transmitter[bss_info.band] = wlan; } - } else { - band = BAND_24GHZ; } - set_default_wireless_interface_info(band); + printf("TLV_BSS_IDENTIFIER 0x%x band %d multiple_bssid %d transmitter %d identifier %d\n", + bss_identifier, + bss_info.band, + bss_info.mbssid_enable, + bss_info.transmitter, + bss_info.identifier + ); + } else { + /* Single wlan case */ + tlv = find_wrapper_tlv_by_id(req, TLV_HW_MODE); + if (tlv) + { + memset(hw_mode_str, 0, sizeof(hw_mode_str)); + memcpy(hw_mode_str, tlv->value, tlv->len); + if (!strncmp(hw_mode_str, "a", 1)) { + band = BAND_5GHZ; + tlv = find_wrapper_tlv_by_id(req, TLV_OP_CLASS); + if (tlv) { + memset(op_class, 0, sizeof(op_class)); + memcpy(op_class, tlv->value, tlv->len); + if (atoi(op_class) >= OP_CLASS_6G_20 && atoi(op_class) <= OP_CLASS_6G_160) + band = BAND_6GHZ; + } + } else { + band = BAND_24GHZ; + } + /* Single wlan use ID 1 */ + bss_info.band = band; + bss_info.identifier = 1; + wlan = assign_wireless_interface_info(&bss_info); + } } - strcpy(ifname, get_default_wireless_interface_info()); + if (wlan) { + printf("ifname %s hostapd conf file %s\n", + wlan ? wlan->ifname : "n/a", + wlan ? wlan->hapd_conf_file: "n/a" + ); + len = generate_hostapd_config(buffer, sizeof(buffer), req, wlan); + if (len) + { +#if HOSTAPD_SUPPORT_MBSSID + if (bss_info.mbssid_enable && !bss_info.transmitter) { + if (band_transmitter[bss_info.band]) { + append_file(band_transmitter[bss_info.band]->hapd_conf_file, buffer, len); + } + memset(wlan->hapd_conf_file, 0, sizeof(wlan->hapd_conf_file)); + } + else +#endif + write_file(wlan->hapd_conf_file, buffer, len); + } + } + show_wireless_interface_info(); #ifdef _WTS_OPENWRT_ /* Handle the platform dependency */ tlv = find_wrapper_tlv_by_id(req, TLV_MBO); rrm = tlv ? 1 : 0; #endif - /* Generate the hostapd configuration and write to configuration */ - len = generate_hostapd_config(buffer, sizeof(buffer), req, ifname); - if (len) { - write_file(get_hapd_conf_file(), buffer, len); - } fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, len > 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); @@ -446,6 +549,7 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r char buffer[S_BUFFER_LEN], g_ctrl_iface[64], log_level[TLV_VALUE_SIZE]; int len; struct tlv_hdr *tlv; + int swap_hostapd = 0; sprintf(g_ctrl_iface, "%s", get_hapd_global_ctrl_path()); @@ -498,10 +602,12 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r g_ctrl_iface, get_hostapd_debug_arguments(), HAPD_LOG_FILE, - get_hapd_conf_file()); + get_all_hapd_conf_files(&swap_hostapd)); len = system(buffer); sleep(1); + bridge_init(BRIDGE_WLANS); + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, len == 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); @@ -527,7 +633,11 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr goto response; } - ifname = get_wireless_interface(); + if (is_bridge_created()) { + ifname = BRIDGE_WLANS; + } else { + ifname = get_wireless_interface(); + } /* Release IP address from interface */ reset_interface_ip(ifname); @@ -552,14 +662,49 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr // ACK: Bytes from DUT : 01 00 01 00 ee ff ff a0 01 01 30 a0 00 15 41 43 4b 3a 20 43 6f 6d 6d 61 6e 64 20 72 65 63 65 69 76 65 64 // RESP: {: '0', : '9c:b6:d0:19:40:c7', : '9c:b6:d0:19:40:c7'} static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - char buffer[64]; + char mac_addr[S_BUFFER_LEN]; + struct bss_identifier_info bss_info; + char bss_identifier_str[16]; + int bss_identifier = 0; + struct tlv_hdr *tlv; + struct interface_info* wlan = NULL; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_NOT_OK; - get_mac_address(buffer, sizeof(buffer), get_wireless_interface()); + printf("req->tlv_num %d\n", req->tlv_num); //remove me + + memset(&bss_info, 0, sizeof(bss_info)); + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_IDENTIFIER); + if (tlv) { + memset(bss_identifier_str, 0, sizeof(bss_identifier_str)); + memcpy(bss_identifier_str, tlv->value, tlv->len); + bss_identifier = atoi(bss_identifier_str); + parse_bss_identifier(bss_identifier, &bss_info); + + printf("TLV_BSS_IDENTIFIER 0x%x identifier %d band %d\n", + bss_identifier, + bss_info.identifier, + bss_info.band); + wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); + if (wlan) { + get_mac_address(mac_addr, sizeof(mac_addr), wlan->ifname); + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + } + } else { + get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + } fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); - fill_wrapper_tlv_byte(resp, TLV_STATUS, TLV_VALUE_STATUS_OK); - fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(buffer), buffer); - fill_wrapper_tlv_bytes(resp, TLV_DUT_MAC_ADDR, strlen(buffer), buffer); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + if (status == TLV_VALUE_STATUS_OK) { + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(mac_addr), mac_addr); + fill_wrapper_tlv_bytes(resp, TLV_DUT_MAC_ADDR, strlen(mac_addr), mac_addr); + } else { + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + } return 0; } diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 1db6add..9a3c0eb 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -23,6 +23,10 @@ #include "vendor_specific.h" #include "utils.h" +#ifdef HOSTAPD_SUPPORT_MBSSID_WAR +extern int use_openwrt_wpad; +#endif + #ifdef _TEST_PLATFORM_ extern struct sta_platform_config sta_hw_config; const struct sta_driver_ops *sta_drv_ops = NULL; @@ -105,24 +109,12 @@ int detect_third_radio() { } #endif -/* Be invoked when start controlApp */ -void vendor_init() { - /* Make sure native hostapd/wpa_supplicant is inactive */ - system("killall hostapd 1>/dev/null 2>/dev/null"); - sleep(1); - system("killall wpa_supplicant 1>/dev/null 2>/dev/null"); - sleep(1); - +void interfaces_init() { #if defined(_OPENWRT_) && !defined(_WTS_OPENWRT_) char buffer[BUFFER_LEN]; char mac_addr[S_BUFFER_LEN]; int third_radio = 0; - /* Vendor: add codes to let ControlApp have full control of hostapd */ - /* Avoid hostapd being invoked by procd */ - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, "/etc/init.d/wpad stop >/dev/null 2>/dev/null"); - system(buffer); third_radio = detect_third_radio(); memset(buffer, 0, sizeof(buffer)); @@ -173,6 +165,32 @@ void vendor_init() { set_mac_address("ath21", mac_addr); } sleep(1); +#endif +} + +/* Be invoked when start controlApp */ +void vendor_init() { + /* Make sure native hostapd/wpa_supplicant is inactive */ + system("killall hostapd 1>/dev/null 2>/dev/null"); + sleep(1); + system("killall wpa_supplicant 1>/dev/null 2>/dev/null"); + sleep(1); + +#if defined(_OPENWRT_) && !defined(_WTS_OPENWRT_) + char buffer[BUFFER_LEN]; + /* Vendor: add codes to let ControlApp have full control of hostapd */ + /* Avoid hostapd being invoked by procd */ + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "/etc/init.d/wpad stop >/dev/null 2>/dev/null"); + system(buffer); + + interfaces_init(); +#if HOSTAPD_SUPPORT_MBSSID +#ifdef HOSTAPD_SUPPORT_MBSSID_WAR + system("cp /overlay/hostapd /usr/sbin/hostapd"); + use_openwrt_wpad = 0; +#endif +#endif #else detect_sta_vendor(); #endif @@ -190,6 +208,27 @@ void vendor_deinit() { system(buffer); } +/* Called by configure_ap_handler() */ +void configure_ap_enable_mbssid() { +#ifdef _WTS_OPENWRT_ + /* + * the following uci commands need to reboot openwrt + * so it can not be configured by controlApp + * + * Manually enable MBSSID on OpenWRT when need to test MBSSID + * + system("uci set wireless.qcawifi=qcawifi"); + system("uci set wireless.qcawifi.mbss_ie_enable=1"); + system("uci commit"); + */ +#elif defined(_OPENWRT_) +#ifdef HOSTAPD_SUPPORT_MBSSID_WAR + system("cp /rom/usr/sbin/wpad /usr/sbin/hostapd"); + use_openwrt_wpad = 1; +#endif +#endif +} + int set_channel_width() { int ret = -1; From e986cfd797e9a80b2838b272deede969d8c60ab5 Mon Sep 17 00:00:00 2001 From: Kenny Date: Mon, 29 Nov 2021 15:49:57 +0800 Subject: [PATCH 02/90] Remove unused if statement --- indigo_api_callback_dut.c | 3 +-- indigo_api_callback_tp.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index fa82b6e..7f4b13c 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -192,8 +192,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re } /* reset interfaces info */ - if (clear_interfaces_resource()) { - } + clear_interfaces_resource(); if (reset == RESET_TYPE_INIT) { system("rm -rf /var/log/hostapd.log >/dev/null 2>/dev/null"); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 5840f80..21de0d9 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -122,8 +122,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re stop_loopback_data(NULL); /* reset interfaces info */ - if (clear_interfaces_resource()) { - } + clear_interfaces_resource(); if (reset == RESET_TYPE_INIT) { len = unlink(get_hapd_conf_file()); From fad11cb9e712eeb34c060f435d7f1172d0a139cb Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 1 Dec 2021 13:28:24 +0800 Subject: [PATCH 03/90] controlapp can specify bridge name with parameters --- indigo_api_callback_dut.c | 20 ++++++++++---------- indigo_api_callback_tp.c | 5 +++-- main.c | 15 ++++++++++++--- utils.c | 13 +++++++++++++ utils.h | 2 ++ vendor_specific.h | 1 + 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 7f4b13c..399717f 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -118,7 +118,7 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe if (strlen(log_level)) { set_hostapd_debug_level(get_debug_level(atoi(log_level))); } - reset_bridge(BRIDGE_WLANS); + reset_bridge(get_wlans_bridge()); /* reset interfaces info */ clear_interfaces_resource(); } @@ -701,7 +701,7 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r iterate_all_wlan_interfaces(start_ap_set_wlan_params); #endif - bridge_init(BRIDGE_WLANS); + bridge_init(get_wlans_bridge()); fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, len == 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); @@ -730,11 +730,11 @@ static int create_bridge_network_handler(struct packet_wrapper *req, struct pack } /* Create new bridge */ - create_bridge(BRIDGE_WLANS); + create_bridge(get_wlans_bridge()); - add_all_wireless_interface_to_bridge(BRIDGE_WLANS); + add_all_wireless_interface_to_bridge(get_wlans_bridge()); - set_interface_ip(BRIDGE_WLANS, static_ip); + set_interface_ip(get_wlans_bridge(), static_ip); response: fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); @@ -763,7 +763,7 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr } if (is_bridge_created()) { - ifname = BRIDGE_WLANS; + ifname = get_wlans_bridge(); } else { ifname = get_wireless_interface(); } @@ -969,10 +969,10 @@ static int start_loopback_server(struct packet_wrapper *req, struct packet_wrapp char *message = TLV_VALUE_LOOPBACK_SVR_START_NOT_OK; char tool_udp_port[16]; - /* Find network interface. If BRIDGE_WLANS exists, then use it. Otherwise, it uses the initiation value. */ + /* Find network interface. If bridge exists, then use it. Otherwise, it uses the initiation value. */ memset(local_ip, 0, sizeof(local_ip)); - if (find_interface_ip(local_ip, sizeof(local_ip), BRIDGE_WLANS)) { - indigo_logger(LOG_LEVEL_DEBUG, "use %s", BRIDGE_WLANS); + if (find_interface_ip(local_ip, sizeof(local_ip), get_wlans_bridge())) { + indigo_logger(LOG_LEVEL_DEBUG, "use %s", get_wlans_bridge()); } else if (find_interface_ip(local_ip, sizeof(local_ip), get_wireless_interface())) { indigo_logger(LOG_LEVEL_DEBUG, "use %s", get_wireless_interface()); // #ifdef __TEST__ @@ -1348,7 +1348,7 @@ static int get_ip_addr_handler(struct packet_wrapper *req, struct packet_wrapper char *message = NULL; char buffer[64]; - if (find_interface_ip(buffer, sizeof(buffer), BRIDGE_WLANS)) { + if (find_interface_ip(buffer, sizeof(buffer), get_wlans_bridge())) { status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; } else if (find_interface_ip(buffer, sizeof(buffer), get_wireless_interface())) { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 21de0d9..cc7b086 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -116,6 +116,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re indigo_logger(LOG_LEVEL_ERROR, "Can't get tool IP address"); } + reset_bridge(get_wlans_bridge()); reset_interface_ip(get_wireless_interface()); } @@ -605,7 +606,7 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r len = system(buffer); sleep(1); - bridge_init(BRIDGE_WLANS); + bridge_init(get_wlans_bridge()); fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, len == 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); @@ -633,7 +634,7 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr } if (is_bridge_created()) { - ifname = BRIDGE_WLANS; + ifname = get_wlans_bridge(); } else { ifname = get_wireless_interface(); } diff --git a/main.c b/main.c index 3c148b8..c34fc48 100755 --- a/main.c +++ b/main.c @@ -166,6 +166,7 @@ static void usage() { printf("app [-h] [-p] [-i|-i:[,:]] [-a] [-s]\n\n"); printf("usage:\n"); printf(" -a = specify hostapd path\n"); + printf(" -b = specify bridge name for wireless interfaces\n"); printf(" -d = debug received and sent message\n"); printf(" -i = specify the interface. E.g., -i wlan0. Or, :.\n band can be 2 for 2.4GHz, 5 for 5GHz and 6 for 6GHz. E.g., -i 2:wlan0,2:wlan1,5:wlan32,5:wlan33\n"); printf(" -p = port number of the application\n"); @@ -189,18 +190,22 @@ static void print_welcome() { /* Parse the commandline parameters */ static int parse_parameters(int argc, char *argv[]) { - int c, ifs_configured = 0; + int c, ifs_configured = 0, bridge_configured = 0; char buf[128]; #ifdef _VERSION_ - while ((c = getopt(argc, argv, "a:s:i:hp:dcv")) != -1) { + while ((c = getopt(argc, argv, "a:b:s:i:hp:dcv")) != -1) { #else - while ((c = getopt(argc, argv, "a:s:i:hp:dc")) != -1) { + while ((c = getopt(argc, argv, "a:b:s:i:hp:dc")) != -1) { #endif switch (c) { case 'a': set_hapd_full_exec_path(optarg); break; + case 'b': + set_wlans_bridge(optarg); + bridge_configured = 1; + break; case 'c': capture_packet = 1; break; @@ -251,6 +256,10 @@ static int parse_parameters(int argc, char *argv[]) { #endif } + if (bridge_configured == 0) { + set_wlans_bridge(BRIDGE_WLANS); + } + return 0; } diff --git a/utils.c b/utils.c index e28251b..467794f 100644 --- a/utils.c +++ b/utils.c @@ -55,6 +55,8 @@ struct interface_info interfaces[8]; int band_mbssid_cnt[16]; struct interface_info* default_interface; static struct loopback_info loopback = {}; +/* bridge used for wireless interfaces */ +char wlans_bridge[32]; #ifdef HOSTAPD_SUPPORT_MBSSID_WAR int use_openwrt_wpad = 0; @@ -731,6 +733,17 @@ int set_mac_address(char *ifname, char *mac) { int bridge_created = 0; +char* get_wlans_bridge() { + return wlans_bridge; +} +int set_wlans_bridge(char* br) { + memset(wlans_bridge, 0, sizeof(wlans_bridge)); + snprintf(wlans_bridge, sizeof(wlans_bridge), "%s", br); + printf("\nwlans_bridge = %s.\n", wlans_bridge); + + return 0; +} + int is_bridge_created() { return bridge_created; } diff --git a/utils.h b/utils.h index 17fa0aa..8f881fd 100644 --- a/utils.h +++ b/utils.h @@ -137,6 +137,8 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet int stop_loopback_data(int *pkt_sent); int send_broadcast_arp(char *target_ip, int *send_count, int rate); int send_icmp_data(char *target_ip, int packet_count, int packet_size, double rate); +char* get_wlans_bridge(); +int set_wlans_bridge(char* br); int is_bridge_created(); int create_bridge(char *br); int add_interface_to_bridge(char *br, char *interface); diff --git a/vendor_specific.h b/vendor_specific.h index 8891446..d469763 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -69,6 +69,7 @@ #define WIRELESS_INTERFACE_DEFAULT "wlan0" #define SERVICE_PORT_DEFAULT 9004 +/* Default bridge for wireless interfaces */ #define BRIDGE_WLANS "br-wlans" #ifdef _WTS_OPENWRT_ From 19215075e057185915f943b681988f397736893e Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Thu, 2 Dec 2021 11:28:28 +0800 Subject: [PATCH 04/90] Add passpoint common configurations (1) Add passpoint related parameters and ANQP element IDs (2) Support AP passpoint common configurations and STA platform global settings. --- hs2_profile.h | 148 ++++++++++++++++++++++++++++++++++++++ indigo_api.c | 29 ++++++++ indigo_api.h | 29 ++++++++ indigo_api_callback.h | 64 +++++++++++++++++ indigo_api_callback_dut.c | 91 +++++++++++++++++++---- indigo_api_callback_tp.c | 107 +++++++++++++++++++-------- 6 files changed, 426 insertions(+), 42 deletions(-) create mode 100644 hs2_profile.h diff --git a/hs2_profile.h b/hs2_profile.h new file mode 100644 index 0000000..ae7f99b --- /dev/null +++ b/hs2_profile.h @@ -0,0 +1,148 @@ + +/* Copyright (c) 2021 Wi-Fi Alliance */ + +/* Permission to use, copy, modify, and/or distribute this software for any */ +/* purpose with or without fee is hereby granted, provided that the above */ +/* copyright notice and this permission notice appear in all copies. */ + +/* THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL */ +/* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED */ +/* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL */ +/* THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR */ +/* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING */ +/* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF */ +/* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT */ +/* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS */ +/* SOFTWARE. */ + +#ifndef _HS2_PROFILE +#define _HS2_PROFILE + +#define ARRAY_SIZE(x) ((sizeof x) / (sizeof *x)) + +struct tlv_to_profile { + unsigned short tlv_id; + const char **profile; + int size; +}; + +const char * nai_realm[] = { + "", + "nai_realm=0,mail.example.com,21[2:4][5:7]\nnai_realm=0,cisco.com,21[2:4][5:7]\nnai_realm=0,wi-fi.org,13[5:6],21[2:4][5:7]\nnai_realm=0,example.com,13[5:6]\n", + "nai_realm=0,wi-fi.org,21[2:4][5:7]\n", + "nai_realm=0,cisco.com,21[2:4][5:7]\nnai_realm=0,wi-fi.org,13[5:6],21[2:4][5:7]\nnai_realm=0,example.com,13[5:6]\n", + "nai_realm=0,mail.example.com,13[5:6],21[2:4][5:7]\n", + "nai_realm=0,wi-fi.org,21[2:4][5:7]\nnai_realm=0,ruckuswireless.com,21[2:4][5:7]\n", + "nai_realm=0,wi-fi.org,21[2:4][5:7]\nnai_realm=0,mail.example.com,21[2:4][5:7]\n", + "nai_realm=0,wi-fi.org,13[5:6],21[2:4][5:7]\n", +}; + +const char * oper_friendly_name[] = { + "", + "hs20_oper_friendly_name=eng:Wi-Fi Alliance\nhs20_oper_friendly_name=chi:Wi-Fi联盟\n", +}; + +const char * venue_name[] = { + "", + "venue_name=eng:Wi-Fi Alliance 3408 Garrett Drive Santa Clara, CA 950514, USA\nvenue_name=chi:Wi-Fi聯盟實驗室 三四零八 加洛路 聖克拉拉, 加利福尼亞 950514, 美國\n", + "", + "", +}; + +const char * network_auth_type[] = { + "", + "network_auth_type=00https://tandc-server.wi-fi.org/\n", + "network_auth_type=01", +}; + +const char * ipaddr_type_avail[] = { + "", + "ipaddr_type_availability=0c\n", +}; + +const char * hs20_wan_metrics[] = { + "", + "hs20_wan_metrics=01:2560:384:0:0:0\n", + "", + "", + "", + "", +}; + +const char * hs20_conn_capab[] = { + "", + "hs20_conn_capab=6:20:1\nhs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\nhs20_conn_capab=50:0:1\n", + "", + "", + "", + "", +}; + +const char * operating_class_indication[] = { + "", + "", + "", + "", +}; + +const char * osu_providers_list[] = { + "", + "", + "", + "", + "", + "", +}; + +const char * osu_providers_nai_list[] = { + "", + "", + "", + "", + "", +}; + +const char * bss_load[] = { + "", + "", + "", + "", +}; + +const char * venue_url[] = { + "", + "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\nvenue_url=2:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n", + "", +}; + +const char * operator_icon_metadata[] = { + "", + "", +}; + +struct tlv_to_profile hs2_profile[] = { + { TLV_VENUE_NAME, venue_name, ARRAY_SIZE(venue_name) }, + { TLV_NAI_REALM, nai_realm, ARRAY_SIZE(nai_realm) }, + { TLV_HS20_OPERATOR_FRIENDLY_NAME, oper_friendly_name, ARRAY_SIZE(oper_friendly_name) }, + { TLV_NETWORK_AUTH_TYPE, network_auth_type, ARRAY_SIZE(network_auth_type) }, + { TLV_IPADDR_TYPE_AVAILABILITY, ipaddr_type_avail, ARRAY_SIZE(ipaddr_type_avail) }, + { TLV_HS20_WAN_METRICS, hs20_wan_metrics, ARRAY_SIZE(hs20_wan_metrics) }, + { TLV_HS20_CONN_CAPABILITY, hs20_conn_capab, ARRAY_SIZE(hs20_conn_capab) }, + { TLV_OSU_PROVIDERS_LIST, osu_providers_list, ARRAY_SIZE(osu_providers_list) }, + { TLV_OSU_PROVIDERS_NAI_LIST, osu_providers_nai_list, ARRAY_SIZE(osu_providers_nai_list) }, + { TLV_VENUE_URL, venue_url, ARRAY_SIZE(venue_url) }, + { TLV_BSSLOAD_ENABLE, venue_url, ARRAY_SIZE(venue_url) }, + { TLV_OPERATOR_ICON_METADATA, operator_icon_metadata, ARRAY_SIZE(operator_icon_metadata) }, +}; + +struct tlv_to_profile* find_tlv_hs2_profile(int tlv_id) { + int i; + for (i = 0; i < ARRAY_SIZE(hs2_profile); i++) { + if (tlv_id == hs2_profile[i].tlv_id) { + return &hs2_profile[i]; + } + } + return NULL; +} + +#endif // _HS2_PROFILE \ No newline at end of file diff --git a/indigo_api.c b/indigo_api.c index 217e534..4d8080b 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -187,6 +187,35 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_RAND_MAC_ADDR, "RAND_MAC_ADDR" }, { TLV_PREASSOC_RAND_MAC_ADDR, "PREASSOC_RAND_MAC_ADDR" }, { TLV_RAND_ADDR_LIFETIME, "RAND_ADDR_LIFETIME" }, + { TLV_HS20, "HS20" }, + { TLV_ACCESS_NETWORK_TYPE, "ACCESS_NETWORK_TYPE" }, + { TLV_INTERNET, "INTERNET" }, + { TLV_VENUE_GROUP, "VENUE_GROUP" }, + { TLV_VENUE_TYPE, "VENUE_TYPE" }, + { TLV_HESSID, "HESSID" }, + { TLV_ANQP_3GPP_CELL_NETWORK_INFO, "ANQP_3GPP_CELL_NETWORK_INFO" }, + { TLV_OSU_SSID, "OSU_SSID" }, + { TLV_PROXY_ARP, "PROXY_ARP" }, + { TLV_BSSLOAD_ENABLE, "BSSLOAD_ENABLE" }, + { TLV_ROAMING_CONSORTIUM, "ROAMING_CONSORTIUM" }, + { TLV_NETWORK_AUTH_TYPE, "NETWORK_AUTH_TYPE" }, + { TLV_DOMAIN_LIST, "DOMAIN_LIST" }, + { TLV_HS20_OPERATOR_FRIENDLY_NAME, "HS20_OPERATOR_FRIENDLY_NAME" }, + { TLV_NAI_REALM, "NAI_REALM" }, + { TLV_VENUE_NAME, "VENUE_NAME" }, + { TLV_IPADDR_TYPE_AVAILABILITY, "IPADDR_TYPE_AVAILABILITY" }, + { TLV_HS20_WAN_METRICS, "HS20_WAN_METRICS" }, + { TLV_HS20_CONN_CAPABILITY, "HS20_CONN_CAPABILITY"}, + { TLV_VENUE_URL, "VENUE_URL" }, + { TLV_OPERATOR_ICON_METADATA, "OPERATOR_ICON_METADATA" }, + { TLV_OSU_PROVIDERS_LIST, "OSU_PROVIDERS_LIST" }, + { TLV_OSU_PROVIDERS_NAI_LIST, "OSU_PROVIDERS_NAI_LIST" }, + { TLV_REALM, "REALM" }, + { TLV_IMSI, "IMSI" }, + { TLV_MILENAGE, "MILENAGE" }, + { TLV_PPSMO_FILE, "PPSMO_FILE" }, + { TLV_OSU_SERVER_URI, "OSU_SERVER_URI" }, + { TLV_OSU_METHOD, "OSU_METHOD" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 69c8143..82980b4 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -197,6 +197,35 @@ struct indigo_api { #define TLV_HE_6G_ONLY 0x00a6 #define TLV_HE_UNSOL_PR_RESP_CADENCE 0x00a7 #define TLV_HE_FILS_DISCOVERY_TX 0x00a8 +#define TLV_HS20 0x00a9 +#define TLV_ACCESS_NETWORK_TYPE 0x00aa +#define TLV_INTERNET 0x00ab +#define TLV_VENUE_GROUP 0x00ac +#define TLV_VENUE_TYPE 0x00ad +#define TLV_HESSID 0x00ae +#define TLV_OSU_SSID 0x00af +#define TLV_ANQP_3GPP_CELL_NETWORK_INFO 0x00b0 +#define TLV_PROXY_ARP 0x00b1 +#define TLV_BSSLOAD_ENABLE 0x00b2 +#define TLV_ROAMING_CONSORTIUM 0x00b3 +#define TLV_NETWORK_AUTH_TYPE 0x00b4 +#define TLV_DOMAIN_LIST 0x00b5 +#define TLV_HS20_OPERATOR_FRIENDLY_NAME 0x00b6 +#define TLV_NAI_REALM 0x00b7 +#define TLV_VENUE_NAME 0x00b8 +#define TLV_IPADDR_TYPE_AVAILABILITY 0x00b9 +#define TLV_HS20_WAN_METRICS 0x00ba +#define TLV_HS20_CONN_CAPABILITY 0x00bb +#define TLV_VENUE_URL 0x00bc +#define TLV_OPERATOR_ICON_METADATA 0x00bd +#define TLV_OSU_PROVIDERS_LIST 0x00be +#define TLV_OSU_PROVIDERS_NAI_LIST 0x00bf +#define TLV_REALM 0x00c0 +#define TLV_IMSI 0x00c1 +#define TLV_MILENAGE 0x00c2 +#define TLV_PPSMO_FILE 0x00c3 +#define TLV_OSU_SERVER_URI 0x00c4 +#define TLV_OSU_METHOD 0x00c5 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 09f853c..9ed41a9 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -27,6 +27,11 @@ struct tlv_to_config_name { int quoted; }; +struct anqp_tlv_to_config_name { + char element[NAME_SIZE]; + char config[NAME_SIZE]; +}; + struct tlv_to_config_name maps[] = { /* hapds */ { TLV_SSID, "ssid", 0 }, @@ -85,6 +90,18 @@ struct tlv_to_config_name maps[] = { { TLV_HE_UNSOL_PR_RESP_CADENCE, "unsol_bcast_probe_resp_interval", 0 }, { TLV_HE_FILS_DISCOVERY_TX, "fils_discovery_max_interval", 0 }, { TLV_SKIP_6G_BSS_SECURITY_CHECK, "skip_6g_bss_security_check", 0 }, + { TLV_HS20, "hs20", 0 }, + { TLV_ACCESS_NETWORK_TYPE, "access_network_type", 0 }, + { TLV_INTERNET, "internet", 0 }, + { TLV_VENUE_GROUP, "venue_group", 0 }, + { TLV_VENUE_TYPE, "venue_type", 0 }, + { TLV_HESSID, "hessid", 0 }, + { TLV_ANQP_3GPP_CELL_NETWORK_INFO, "anqp_3gpp_cell_net", 0 }, + { TLV_OSU_SSID, "osu_ssid", 0 }, + { TLV_PROXY_ARP, "proxy_arp", 0 }, + { TLV_OSU_SERVER_URI, "osu_server_uri", 0 }, + { TLV_OSU_METHOD, "osu_method_list", 0 }, + { TLV_DOMAIN_LIST, "domain_name", 0 }, /* wpas, seperate? */ { TLV_STA_SSID, "ssid", 1 }, @@ -110,6 +127,39 @@ struct tlv_to_config_name maps[] = { { TLV_PAC_FILE, "pac_file", 1 }, { TLV_STA_OWE_GROUP, "owe_group", 0 }, { TLV_BSSID, "bssid", 0 }, + { TLV_REALM, "realm", 0 }, + { TLV_IMSI, "imsi", 0 }, + { TLV_MILENAGE, "milenage", 0 }, +}; + +struct tlv_to_config_name semicolon_list[] = { + { TLV_ROAMING_CONSORTIUM, "roaming_consortium", 0 }, +}; + +struct anqp_tlv_to_config_name anqp_maps[] = { + { "NeighborReportReq", "272" }, + { "QueryListWithCellPref", "mbo:2" }, + { "ANQPCapaList", "257" }, + { "VenueNameInfo", "258" }, + { "NetworkAuthTypeInfo", "260" }, + { "RoamingConsortium", "261" }, + { "IPAddrTypeInfo", "262" }, + { "NAIRealm", "263" }, + { "3GPPCellNetwork", "264" }, + { "DomainName", "268" }, + { "VenueUrl", "277" }, + { "AdviceOfCharge", "278" }, + { "HSCapaList", "hs20:2" }, + { "OperFriendlyName", "hs20:3" }, + { "WANMetrics", "hs20:4" }, + { "ConnCapa", "hs20:5" }, + { "NAIHomeRealm", "hs20:6" }, + { "OperatingClass", "hs20:7" }, + { "OSUProvidersList", "hs20:8" }, + { "IconReq", "hs20:10" }, + { "IconBinaryFile", "hs20:11" }, + { "OperatorIcon", "hs20:12" }, + { "OSUProvidersNaiList", "hs20:13" }, }; char* find_tlv_config_name(int tlv_id) { @@ -140,6 +190,11 @@ struct tlv_to_config_name wpas_global_maps[] = { { TLV_RAND_MAC_ADDR, "mac_addr", 0 }, { TLV_PREASSOC_RAND_MAC_ADDR, "preassoc_mac_addr", 0 }, { TLV_RAND_ADDR_LIFETIME, "rand_addr_lifetime", 0 }, + { TLV_HS20, "hs20", 0 }, + { TLV_INTERWORKING, "interworking", 0 }, + { TLV_HESSID, "hessid", 0 }, + { TLV_ACCESS_NETWORK_TYPE, "access_network_type", 0 }, + { TLV_FREQ_LIST, "freq_list", 0 }, }; struct tlv_to_config_name* find_wpas_global_config_name(int tlv_id) { @@ -152,6 +207,15 @@ struct tlv_to_config_name* find_wpas_global_config_name(int tlv_id) { return NULL; } +struct tlv_to_config_name* find_generic_tlv_config(int tlv_id, struct tlv_to_config_name* arr, int arr_size) { + int i; + for (i = 0; i < arr_size; i++) { + if (tlv_id == (arr + i)->tlv_id) { + return (arr + i); + } + } + return NULL; +} /* Basic */ static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 7f4b13c..71e6d88 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -24,7 +24,7 @@ #include "utils.h" #include "wpa_ctrl.h" #include "indigo_api_callback.h" - +#include "hs2_profile.h" static char pac_file_path[S_BUFFER_LEN] = {0}; struct interface_info* band_transmitter[16]; @@ -247,13 +247,15 @@ static void append_hostapd_default_config(struct packet_wrapper *wrapper) { static int generate_hostapd_config(char *output, int output_size, struct packet_wrapper *wrapper, struct interface_info* wlanp) { int has_sae = 0, has_wpa = 0, has_pmf = 0, has_owe = 0, has_transition = 0, has_sae_groups = 0; int channel = 0, chwidth = 1, enable_ax = 0, chwidthset = 0, enable_muedca = 0, vht_chwidthset = 0; - int i, enable_ac = 0, enable_11h = 0; + int i, enable_ac = 0, enable_11h = 0, enable_hs20 = 0; char buffer[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; char band[64], value[16]; char country[16]; struct tlv_to_config_name* cfg = NULL; struct tlv_hdr *tlv = NULL; int is_6g_only = 0, unsol_pr_resp_interval = 0; + struct tlv_to_profile *profile = NULL; + int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); #if HOSTAPD_SUPPORT_MBSSID if (wlanp->mbssid_enable && !wlanp->transmitter) @@ -274,6 +276,8 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ /* QCA WTS image doesn't apply 11ax, mu_edca, country, 11d, 11h in hostapd */ for (i = 0; i < wrapper->tlv_num; i++) { tlv = wrapper->tlv[i]; + memset(buffer, 0, sizeof(buffer)); + memset(cfg_item, 0, sizeof(cfg_item)); if (tlv->id == TLV_HE_6G_ONLY) { is_6g_only = 1; @@ -287,6 +291,51 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ continue; } + /* This is used when hostapd will use multiple lines to + * configure multiple items in the same configuration parameter + * (use semicolon to separate multiple configurations) */ + cfg = find_generic_tlv_config(tlv->id, semicolon_list, semicolon_list_size); + if (cfg) { + char *token = NULL, *delimit = ";"; + + memcpy(buffer, tlv->value, tlv->len); + token = strtok(buffer, delimit); + + while(token != NULL) { + sprintf(cfg_item, "%s=%s\n", cfg->config_name, token); + strcat(output, cfg_item); + token = strtok(NULL, delimit); + } + continue; + } + + if (tlv->id == TLV_HESSID && strstr(tlv->value, "self")) { + char mac_addr[64]; + + memset(mac_addr, 0, sizeof(mac_addr)); + get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); + sprintf(cfg_item, "hessid=%s\n", mac_addr); + strcat(output, cfg_item); + continue; + } + + /* profile config */ + profile = find_tlv_hs2_profile(tlv->id); + if (profile) { + char *hs2_config = 0; + memcpy(buffer, tlv->value, tlv->len); + + if (atoi(buffer) > profile->size) { + indigo_logger(LOG_LEVEL_ERROR, "profile index out of bound!: %d, array_size:%d", atoi(buffer), profile->size); + } else { + hs2_config = (char *)profile->profile[atoi(buffer)]; + } + + sprintf(cfg_item, "%s", hs2_config); + strcat(output, cfg_item); + continue; + } + cfg = find_tlv_config(tlv->id); if (!cfg) { indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id); @@ -389,8 +438,10 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ unsol_pr_resp_interval = atoi(value); } - memset(buffer, 0, sizeof(buffer)); - memset(cfg_item, 0, sizeof(cfg_item)); + if (tlv->id == TLV_HS20 && strstr(tlv->value, "1")) { + enable_hs20 = 1; + } + if (tlv->id == TLV_OWE_TRANSITION_BSS_IDENTIFIER) { struct bss_identifier_info bss_info; struct interface_info *wlan; @@ -561,6 +612,12 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, "local_pwr_constraint=3\n"); } #endif + if (enable_hs20) { + strcat(output, "hs20_release=3\n"); + strcat(output, "manage_p2p=1\n"); + strcat(output, "allow_cross_connection=0\n"); + strcat(output, "bss_load_update_period=100\n"); + } /* vendor specific config, not via hostapd */ configure_ap_radio_params(band, country, channel, chwidth); @@ -1797,7 +1854,7 @@ static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_ } static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - int len, status = TLV_VALUE_STATUS_NOT_OK; + int len, status = TLV_VALUE_STATUS_NOT_OK, i; char *message = TLV_VALUE_WPA_S_BTM_QUERY_NOT_OK; char buffer[1024]; char response[1024]; @@ -1806,6 +1863,8 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet struct tlv_hdr *tlv = NULL; struct wpa_ctrl *w = NULL; size_t resp_len; + char *token = NULL; + char *delimit = ";"; /* It may need to check whether to just scan */ memset(buffer, 0, sizeof(buffer)); @@ -1859,19 +1918,27 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet memcpy(anqp_info_id, tlv->value, tlv->len); } + token = strtok(anqp_info_id, delimit); memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, "ANQP_GET %s", bssid); - if (strcmp(anqp_info_id, "NeighborReportReq") == 0) { - strcat(buffer, " 272"); - } else if (strcmp(anqp_info_id, "QueryListWithCellPref") == 0) { - strcat(buffer, " mbo:2"); + sprintf(buffer, "ANQP_GET %s ", bssid); + while(token != NULL) { + for (i = 0; i < sizeof(anqp_maps)/sizeof(struct anqp_tlv_to_config_name); i++) { + if (strcmp(token, anqp_maps[i].element) == 0) { + strcat(buffer, anqp_maps[i].config); + } + } + + token = strtok(NULL, delimit); + if (token != NULL) { + strcat(buffer, ","); + } } /* Send command to wpa_supplicant UDS socket */ resp_len = sizeof(response) - 1; wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); - - printf("%s -> resp: %s\n", buffer, response); + + indigo_logger(LOG_LEVEL_DEBUG, "%s -> resp: %s\n", buffer, response); /* Check response */ if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 21de0d9..acfdf5a 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -27,6 +27,7 @@ #include "utils.h" #include "wpa_ctrl.h" #include "indigo_api_callback.h" +#include "hs2_profile.h" struct sta_platform_config sta_hw_config = {PHYMODE_AUTO, CHWIDTH_AUTO, false, false}; struct interface_info* band_transmitter[16]; @@ -232,7 +233,10 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ struct tlv_to_config_name* cfg = NULL; struct tlv_hdr *tlv = NULL; - int has_owe = 0; + int has_owe = 0, enable_hs20 = 0; + struct tlv_to_profile *profile = NULL; + int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); + #if HOSTAPD_SUPPORT_MBSSID if (wlanp->mbssid_enable && !wlanp->transmitter) @@ -250,6 +254,54 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ for (i = 0; i < wrapper->tlv_num; i++) { tlv = wrapper->tlv[i]; + memset(buffer, 0, sizeof(buffer)); + memset(cfg_item, 0, sizeof(cfg_item)); + + /* This is used when hostapd will use multiple lines to + * configure multiple items in the same configuration parameter + * (use semicolon to separate multiple configurations) */ + cfg = find_generic_tlv_config(tlv->id, semicolon_list, semicolon_list_size); + if (cfg) { + char *token = NULL, *delimit = ";"; + + memcpy(buffer, tlv->value, tlv->len); + token = strtok(buffer, delimit); + + while(token != NULL) { + sprintf(cfg_item, "%s=%s\n", cfg->config_name, token); + strcat(output, cfg_item); + token = strtok(NULL, delimit); + } + continue; + } + + if (tlv->id == TLV_HESSID && strstr(tlv->value, "self")) { + char mac_addr[64]; + + memset(mac_addr, 0, sizeof(mac_addr)); + get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); + sprintf(cfg_item, "hessid=%s\n", mac_addr); + strcat(output, cfg_item); + continue; + } + + /* profile config */ + profile = find_tlv_hs2_profile(tlv->id); + if (profile) { + char *hs2_config = 0; + memcpy(buffer, tlv->value, tlv->len); + + if (atoi(buffer) > profile->size) { + indigo_logger(LOG_LEVEL_ERROR, "profile index out of bound!: %d, array_size:%d", atoi(buffer), profile->size); + } else { + hs2_config = (char *)profile->profile[atoi(buffer)]; + } + + sprintf(cfg_item, "%s", hs2_config); + strcat(output, cfg_item); + continue; + } + cfg = find_tlv_config(tlv->id); if (!cfg) { indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id); @@ -318,8 +370,11 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (tlv->id == TLV_WPA_KEY_MGMT && strstr(tlv->value, "OWE")) { has_owe = 1; } - memset(buffer, 0, sizeof(buffer)); - memset(cfg_item, 0, sizeof(cfg_item)); + + if (tlv->id == TLV_HS20 && strstr(tlv->value, "1")) { + enable_hs20 = 1; + } + if (tlv->id == TLV_OWE_TRANSITION_BSS_IDENTIFIER) { struct bss_identifier_info bss_info; struct interface_info *wlan; @@ -376,6 +431,12 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, "multiple_bssid=1\n"); } #endif + if (enable_hs20) { + strcat(output, "hs20_release=3\n"); + strcat(output, "manage_p2p=1\n"); + strcat(output, "allow_cross_connection=0\n"); + strcat(output, "bss_load_update_period=100\n"); + } #ifdef _WTS_OPENWRT_ if (!strncmp(band, "a", 1)) { @@ -1149,12 +1210,12 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe struct wpa_ctrl *w = NULL; char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; char buffer[S_BUFFER_LEN], response[1024], log_level[TLV_VALUE_SIZE], value[TLV_VALUE_SIZE]; - char freq_list[S_BUFFER_LEN], ssid[S_BUFFER_LEN], preassoc_rand_addr[S_BUFFER_LEN]; - int len, status = TLV_VALUE_STATUS_NOT_OK, i, freq_list_len, ssid_len, preassoc_rand_addr_len; + char ssid[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; + int len, status = TLV_VALUE_STATUS_NOT_OK, i, ssid_len; size_t resp_len; char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; struct tlv_hdr *tlv = NULL; - + struct tlv_to_config_name* cfg = NULL; #ifdef _OPENWRT_ #else system("rfkill unblock wlan"); @@ -1166,22 +1227,6 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe system(buffer); sleep(3); - tlv = find_wrapper_tlv_by_id(req, TLV_FREQ_LIST); - memset(freq_list, 0, sizeof(freq_list)); - if (tlv) { - memset(value, 0, sizeof(value)); - memcpy(value, tlv->value, tlv->len); - freq_list_len = sprintf(freq_list, "freq_list=%s\n", value); - } - - tlv = find_wrapper_tlv_by_id(req, TLV_PREASSOC_RAND_MAC_ADDR); - memset(preassoc_rand_addr, 0, sizeof(preassoc_rand_addr)); - if (tlv) { - memset(value, 0, sizeof(value)); - memcpy(value, tlv->value, tlv->len); - preassoc_rand_addr_len = sprintf(preassoc_rand_addr, "preassoc_mac_addr=%s\n", value); - } - tlv = find_wrapper_tlv_by_id(req, TLV_SSID); memset(ssid, 0, sizeof(ssid)); if (tlv) { @@ -1189,21 +1234,23 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe memcpy(value, tlv->value, tlv->len); ssid_len = sprintf(ssid, "network={\nssid=\"%s\"\nscan_ssid=1\nkey_mgmt=NONE\n}\n", value); } - + tlv = find_wrapper_tlv_by_id(req, TLV_CONTROL_INTERFACE); if (tlv) { memset(buffer, 0, sizeof(buffer)); memset(value, 0, sizeof(value)); memcpy(value, tlv->value, tlv->len); set_wpas_ctrl_path(value); - sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", value); - - if (freq_list_len) { - strcat(buffer, freq_list); - } + sprintf(buffer, "ap_scan=1\n"); - if (preassoc_rand_addr_len) { - strcat(buffer, preassoc_rand_addr); + for (i = 0; i < req->tlv_num; i++) { + cfg = find_wpas_global_config_name(req->tlv[i]->id); + if (cfg) { + memset(value, 0, sizeof(value)); + memcpy(value, req->tlv[i]->value, req->tlv[i]->len); + sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); + strcat(buffer, cfg_item); + } } if (ssid_len) { From 220b06fe0f64cf8ff4c4399b961b1b8b29734e5c Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Mon, 6 Dec 2021 16:32:26 +0800 Subject: [PATCH 05/90] Add P2P basic APIs in TP and DUT --- indigo_api.c | 13 ++ indigo_api.h | 24 ++ indigo_api_callback.h | 9 + indigo_api_callback_dut.c | 470 +++++++++++++++++++++++++++++++++++++- indigo_api_callback_tp.c | 190 ++++++++++++++- utils.c | 11 +- utils.h | 1 + vendor_specific.h | 7 + vendor_specific_dut.c | 66 ++++++ vendor_specific_tp.c | 66 ++++++ 10 files changed, 852 insertions(+), 5 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 4d8080b..0d3f452 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -49,6 +49,12 @@ struct indigo_api indigo_api_list[] = { { API_STA_SET_PHY_MODE, "STA_SET_PHY_MODE", NULL, NULL }, { API_STA_SET_CHANNEL_WIDTH, "STA_SET_CHANNEL_WIDTH", NULL, NULL }, { API_STA_POWER_SAVE, "STA_POWER_SAVE", NULL, NULL }, + { API_P2P_START_UP, "P2P_START_UP", NULL, NULL }, + { API_P2P_FIND, "P2P_FIND", NULL, NULL }, + { API_P2P_LISTEN, "P2P_LISTEN", NULL, NULL }, + { API_P2P_ADD_GROUP, "P2P_ADD_GROUP", NULL, NULL }, + { API_P2P_START_WPS, "P2P_START_WPS", NULL, NULL }, + { API_P2P_CONNECT, "P2P_CONNECT", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, @@ -60,6 +66,8 @@ struct indigo_api indigo_api_list[] = { { API_DEVICE_RESET, "DEVICE_RESET", NULL, NULL }, { API_SEND_LOOP_BACK_DATA, "SEND_LOOP_BACK_DATA", NULL, NULL }, { API_STOP_LOOP_BACK_DATA, "STOP_LOOP_BACK_DATA", NULL, NULL }, + { API_START_DHCP, "START_DHCP", NULL, NULL }, + { API_STOP_DHCP, "STOP_DHCP", NULL, NULL }, }; /* Structure to declare the TLV list */ @@ -216,6 +224,11 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_PPSMO_FILE, "PPSMO_FILE" }, { TLV_OSU_SERVER_URI, "OSU_SERVER_URI" }, { TLV_OSU_METHOD, "OSU_METHOD" }, + { TLV_GO_INTENT, "GO_INTENT" }, + { TLV_WSC_METHOD, "WSC_METHOD" }, + { TLV_PIN_METHOD, "PIN_METHOD" }, + { TLV_PIN_CODE, "PIN_CODE" }, + { TLV_P2P_CONN_TYPE, "P2P_CONN_TYPE" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 82980b4..2d0b69b 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -62,6 +62,12 @@ struct indigo_api { #define API_STA_SET_PHY_MODE 0x2009 #define API_STA_SET_CHANNEL_WIDTH 0x200a #define API_STA_POWER_SAVE 0x200b +#define API_P2P_START_UP 0x200c +#define API_P2P_FIND 0x200d +#define API_P2P_LISTEN 0x200e +#define API_P2P_ADD_GROUP 0x200f +#define API_P2P_START_WPS 0x2010 +#define API_P2P_CONNECT 0x2011 #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -73,6 +79,8 @@ struct indigo_api { #define API_DEVICE_RESET 0x5007 #define API_SEND_LOOP_BACK_DATA 0x5008 #define API_STOP_LOOP_BACK_DATA 0x5009 +#define API_START_DHCP 0x500a +#define API_STOP_DHCP 0x500b /* TLV definition */ #define TLV_SSID 0x0001 @@ -226,6 +234,11 @@ struct indigo_api { #define TLV_PPSMO_FILE 0x00c3 #define TLV_OSU_SERVER_URI 0x00c4 #define TLV_OSU_METHOD 0x00c5 +#define TLV_GO_INTENT 0x00c6 +#define TLV_WSC_METHOD 0x00c7 +#define TLV_PIN_METHOD 0x00c8 +#define TLV_PIN_CODE 0x00c9 +#define TLV_P2P_CONN_TYPE 0x00ca // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT @@ -243,6 +256,7 @@ struct indigo_api { /* TLV Value */ #define DUT_TYPE_STAUT 0x01 #define DUT_TYPE_APUT 0x02 +#define DUT_TYPE_P2PUT 0x03 #define TLV_BAND_24GHZ "2.4GHz" #define TLV_BAND_5GHZ "5GHz" @@ -276,6 +290,7 @@ struct indigo_api { #define TLV_VALUE_BROADCAST_ARP_TEST_NOT_OK "Broadcast ARP test failed" #define TLV_VALUE_CREATE_BRIDGE_OK "Bridge network is created successfully" #define TLV_VALUE_CREATE_BRIDGE_NOT_OK "Failed to create bridge network" +#define TLV_VALUE_START_DHCP_NOT_OK "Failed to start DHCP server or client" #define TLV_VALUE_WPA_S_START_UP_OK "wpa_supplicant is initialized successfully" #define TLV_VALUE_WPA_S_START_UP_NOT_OK "The wpa_supplicant was unable to initialize." @@ -295,11 +310,20 @@ struct indigo_api { #define TLV_VALUE_POWER_SAVE_OK "Set power save value successfully" #define TLV_VALUE_POWER_SAVE_NOT_OK "Failed to set power save value" +#define TLV_VALUE_P2P_FIND_NOT_OK "Failed to trigger P2P find" +#define TLV_VALUE_P2P_LISTEN_NOT_OK "Failed to trigger P2P listen" +#define TLV_VALUE_P2P_ADD_GROUP_NOT_OK "Failed to add P2P group" +#define TLV_VALUE_P2P_START_WPS_NOT_OK "Failed to start WPS on GO interface" +#define TLV_VALUE_P2P_CONNECT_NOT_OK "Failed to trigger P2P connect" + #define RESET_TYPE_INIT 0x01 #define RESET_TYPE_TEARDOWN 0x02 #define WPA_CTRL_OK "OK" +#define P2P_CONN_TYPE_JOIN 0x01 +#define P2P_CONN_TYPE_AUTH 0x02 + struct indigo_api* get_api_by_id(int id); struct indigo_tlv* get_tlv_by_id(int id); char* get_api_type_by_id(int id); diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 9ed41a9..b749bad 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -228,6 +228,8 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int get_ip_addr_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int reset_device_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* AP */ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); @@ -250,4 +252,11 @@ static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_w static int set_sta_phy_mode_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_channel_width_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +/* P2P */ +static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); #endif // __INDIGO_API_CALLBACK diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 9239f85..f9e208f 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -40,6 +40,8 @@ void register_apis() { register_api(API_CREATE_NEW_INTERFACE_BRIDGE_NETWORK, NULL, create_bridge_network_handler); register_api(API_ASSIGN_STATIC_IP, NULL, assign_static_ip_handler); register_api(API_DEVICE_RESET, NULL, reset_device_handler); + register_api(API_START_DHCP, NULL, start_dhcp_handler); + register_api(API_STOP_DHCP, NULL, stop_dhcp_handler); /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); @@ -60,6 +62,12 @@ void register_apis() { /* TODO: Add the handlers */ register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL); register_api(API_STA_POWER_SAVE, NULL, NULL); + register_api(API_P2P_START_UP, NULL, start_up_p2p_handler); + register_api(API_P2P_FIND, NULL, find_p2p_handler); + register_api(API_P2P_LISTEN, NULL, listen_p2p_handler); + register_api(API_P2P_ADD_GROUP, NULL, add_group_p2p_handler); + register_api(API_P2P_START_WPS, NULL, start_wps_p2p_handler); + register_api(API_P2P_CONNECT, NULL, connect_p2p_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -121,6 +129,15 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe reset_bridge(get_wlans_bridge()); /* reset interfaces info */ clear_interfaces_resource(); + } else if (atoi(role) == DUT_TYPE_P2PUT) { + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + system(buffer); + sleep(1); + //reset_interface_ip(get_wireless_interface()); + if (strlen(log_level)) { + set_wpas_debug_level(get_debug_level(atoi(log_level))); + } } if (strcmp(band, TLV_BAND_24GHZ) == 0) { @@ -919,6 +936,16 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe if (atoi(role) == DUT_TYPE_STAUT) { w = wpa_ctrl_open(get_wpas_ctrl_path()); + } else if (atoi(role) == DUT_TYPE_P2PUT) { + /* Get P2P GO/Client or Device MAC */ + if (get_p2p_mac_addr(mac_addr, sizeof(mac_addr))) { + status = TLV_VALUE_STATUS_NOT_OK; + message = "Unable to get mac address of the P2P device"; + } else { + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + } + goto done; } else { wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); w = wpa_ctrl_open(get_hapd_ctrl_path_by_id(wlan)); @@ -1025,10 +1052,13 @@ static int start_loopback_server(struct packet_wrapper *req, struct packet_wrapp int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_LOOPBACK_SVR_START_NOT_OK; char tool_udp_port[16]; + char if_name[32]; /* Find network interface. If bridge exists, then use it. Otherwise, it uses the initiation value. */ memset(local_ip, 0, sizeof(local_ip)); - if (find_interface_ip(local_ip, sizeof(local_ip), get_wlans_bridge())) { + if (get_p2p_group_if(if_name, sizeof(if_name)) == 0 && find_interface_ip(local_ip, sizeof(local_ip), if_name)) { + indigo_logger(LOG_LEVEL_DEBUG, "use %s", if_name); + } else if (find_interface_ip(local_ip, sizeof(local_ip), get_wlans_bridge())) { indigo_logger(LOG_LEVEL_DEBUG, "use %s", get_wlans_bridge()); } else if (find_interface_ip(local_ip, sizeof(local_ip), get_wireless_interface())) { indigo_logger(LOG_LEVEL_DEBUG, "use %s", get_wireless_interface()); @@ -1404,8 +1434,21 @@ static int get_ip_addr_handler(struct packet_wrapper *req, struct packet_wrapper int status = TLV_VALUE_STATUS_NOT_OK; char *message = NULL; char buffer[64]; + struct tlv_hdr *tlv = NULL; + char value[16], if_name[32]; + int role = 0; - if (find_interface_ip(buffer, sizeof(buffer), get_wlans_bridge())) { + memset(value, 0, sizeof(value)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(value, tlv->value, tlv->len); + role = atoi(value); + } + + if (role == DUT_TYPE_P2PUT && get_p2p_group_if(if_name, sizeof(if_name)) == 0 && find_interface_ip(buffer, sizeof(buffer), if_name)) { + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + } else if (find_interface_ip(buffer, sizeof(buffer), get_wlans_bridge())) { status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; } else if (find_interface_ip(buffer, sizeof(buffer), get_wireless_interface())) { @@ -1956,3 +1999,426 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet } return 0; } + +static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; + char buffer[S_BUFFER_LEN]; + int len, status = TLV_VALUE_STATUS_NOT_OK; + +#ifdef _OPENWRT_ +#else + system("rfkill unblock wlan"); + sleep(1); +#endif + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + system(buffer); + sleep(3); + + /* Generate P2P config file */ + sprintf(buffer, "ctrl_interface=%s\n", WPAS_CTRL_PATH_DEFAULT); + /* Add Device name and Device type */ + strcat(buffer, "device_name=WFA P2P Device\n"); + strcat(buffer, "device_type=1-0050F204-1\n"); + len = strlen(buffer); + + if (len) { + write_file(get_wpas_conf_file(), buffer, len); + } + + /* Start WPA supplicant */ + memset(buffer, 0 ,sizeof(buffer)); + sprintf(buffer, "%s -B -t -c %s %s -i %s -f /var/log/supplicant.log", + get_wpas_full_exec_path(), + get_wpas_conf_file(), + get_wpas_debug_arguments(), + get_wireless_interface()); + len = system(buffer); + sleep(2); + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_WPA_S_START_UP_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + return 0; +} + +static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_FIND_NOT_OK; + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + // P2P_FIND + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "P2P_FIND"); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + +static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_LISTEN_NOT_OK; + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + // P2P_LISTEN + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "P2P_LISTEN"); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + +static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + char freq[64]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_ADD_GROUP_NOT_OK; + struct tlv_hdr *tlv = NULL; + + memset(freq, 0, sizeof(freq)); + /* TLV_FREQUENCY (required) */ + tlv = find_wrapper_tlv_by_id(req, TLV_FREQUENCY); + if (tlv) { + memcpy(freq, tlv->value, tlv->len); + } else { + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_INSUFFICIENT_TLV; + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_FREQUENCY"); + goto done; + } + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "P2P_GROUP_ADD freq=%s", freq); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + +static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + char pin_code[64], if_name[32]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_START_WPS_NOT_OK; + struct tlv_hdr *tlv = NULL; + + memset(buffer, 0, sizeof(buffer)); + tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); + if (tlv) { + memset(pin_code, 0, sizeof(pin_code)); + memcpy(pin_code, tlv->value, tlv->len); + sprintf(buffer, "WPS_PIN any %s", pin_code); + } else { + sprintf(buffer, "WPS_PBC"); + } + + /* Open wpa_supplicant UDS socket */ + if (get_p2p_group_if(if_name, sizeof(if_name))) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to get P2P group interface"); + goto done; + } + indigo_logger(LOG_LEVEL_DEBUG, "P2P group interface: %s", if_name); + w = wpa_ctrl_open(get_wpas_if_ctrl_path(if_name)); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(response, 0, sizeof(response)); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Skip response check as response is not OK */ + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + +static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + char pin_code[64], if_name[32]; + char method[16], mac[32], type[16]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_CONNECT_NOT_OK; + struct tlv_hdr *tlv = NULL; + char go_intent[32]; + int intent_value = P2P_GO_INTENT; + + memset(buffer, 0, sizeof(buffer)); + memset(mac, 0, sizeof(mac)); + memset(method, 0, sizeof(method)); + memset(type, 0, sizeof(type)); + tlv = find_wrapper_tlv_by_id(req, TLV_ADDRESS); + if (tlv) { + memcpy(mac, tlv->value, tlv->len); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ADDRESS"); + goto done; + } + tlv = find_wrapper_tlv_by_id(req, TLV_GO_INTENT); + if (tlv) { + memset(go_intent, 0, sizeof(go_intent)); + memcpy(go_intent, tlv->value, tlv->len); + intent_value = atoi(go_intent); + } + tlv = find_wrapper_tlv_by_id(req, TLV_P2P_CONN_TYPE); + if (tlv) { + memcpy(type, tlv->value, tlv->len); + if (atoi(type) == P2P_CONN_TYPE_JOIN) { + snprintf(type, sizeof(type), " join"); + memset(go_intent, 0, sizeof(go_intent)); + } else if (atoi(type) == P2P_CONN_TYPE_AUTH) { + snprintf(type, sizeof(type), " auth"); + snprintf(go_intent, sizeof(go_intent), " go_intent=%d", intent_value); + } + } else { + snprintf(go_intent, sizeof(go_intent), " go_intent=%d", intent_value); + } + tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); + if (tlv) { + memset(pin_code, 0, sizeof(pin_code)); + memcpy(pin_code, tlv->value, tlv->len); + tlv = find_wrapper_tlv_by_id(req, TLV_PIN_METHOD); + if (tlv) { + memcpy(method, tlv->value, tlv->len); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV PIN_METHOD???"); + } + sprintf(buffer, "P2P_CONNECT %s %s %s%s%s", mac, pin_code, method, type, go_intent); + } else { + tlv = find_wrapper_tlv_by_id(req, TLV_WSC_METHOD); + if (tlv) { + memcpy(method, tlv->value, tlv->len); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV WSC_METHOD"); + } + sprintf(buffer, "P2P_CONNECT %s %s%s%s", mac, method, type, go_intent); + } + indigo_logger(LOG_LEVEL_DEBUG, "Command: %s", buffer); + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(response, 0, sizeof(response)); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + + +static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_START_DHCP_NOT_OK; + char buffer[S_BUFFER_LEN]; + char param_value[256], role[8]; + struct tlv_hdr *tlv = NULL; + FILE *fp; + char if_name[32]; + + memset(role, 0, sizeof(role)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(role, tlv->value, tlv->len); + if (atoi(role) == DUT_TYPE_P2PUT) { + get_p2p_group_if(if_name, sizeof(if_name)); + } else { + indigo_logger(LOG_LEVEL_ERROR, "DHCP only supports in P2PUT"); + goto done; + } + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); + goto done; + } + + /* TLV: TLV_STATIC_IP */ + memset(param_value, 0, sizeof(param_value)); + tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); + if (tlv) { + memcpy(param_value, tlv->value, tlv->len); + if (!strcmp("0.0.0.0", param_value)) { + snprintf(buffer, sizeof(buffer), "%s/24", DHCP_SERVER_IP); + } else { /* Need to update dhcp conf when using specific IP */ + snprintf(buffer, sizeof(buffer), "%s/24", param_value); + } + set_interface_ip(if_name, buffer); + /* Assign specific IF for DHCP Server */ + snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); + indigo_logger(LOG_LEVEL_DEBUG, buffer); + system(buffer); + snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); + system(buffer); + } else { + snprintf(buffer, sizeof(buffer), "dhclient -4 %s &", if_name); + system(buffer); + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + + return 0; +} + +static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_NOT_OK; + char buffer[S_BUFFER_LEN]; + char role[8]; + struct tlv_hdr *tlv = NULL; + char if_name[32]; + + memset(role, 0, sizeof(role)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(role, tlv->value, tlv->len); + if (atoi(role) == DUT_TYPE_P2PUT) { + get_p2p_group_if(if_name, sizeof(if_name)); + } else { + indigo_logger(LOG_LEVEL_ERROR, "DHCP only supports in P2PUT"); + goto done; + } + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); + goto done; + } + + /* TLV: TLV_STATIC_IP */ + tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); + if (tlv) { /* DHCP Server */ + snprintf(buffer, sizeof(buffer), "systemctl stop isc-dhcp-server.service"); + system(buffer); + } else { /* DHCP Client */ + snprintf(buffer, sizeof(buffer), "killall dhclient 1>/dev/null 2>/dev/null"); + system(buffer); + } + reset_interface_ip(if_name); + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + + return 0; +} diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 4fb8912..cf9fc07 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -46,6 +46,8 @@ void register_apis() { register_api(API_STOP_LOOP_BACK_DATA, NULL, stop_loopback_data_handler); /* TODO: API_CREATE_NEW_INTERFACE_BRIDGE_NETWORK */ register_api(API_ASSIGN_STATIC_IP, NULL, assign_static_ip_handler); + register_api(API_START_DHCP, NULL, start_dhcp_handler); + register_api(API_STOP_DHCP, NULL, stop_dhcp_handler); /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); @@ -59,6 +61,7 @@ void register_apis() { register_api(API_STA_SET_PHY_MODE, NULL, set_sta_phy_mode_handler); register_api(API_STA_SET_CHANNEL_WIDTH, NULL, set_sta_channel_width_handler); register_api(API_STA_POWER_SAVE, NULL, set_sta_power_save_handler); + register_api(API_P2P_START_UP, NULL, start_up_p2p_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -731,6 +734,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe struct interface_info* wlan = NULL; int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_NOT_OK; + char role[16]; printf("req->tlv_num %d\n", req->tlv_num); //remove me @@ -753,7 +757,22 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe message = TLV_VALUE_OK; } } else { - get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); + /* TLV: TLV_ROLE */ + memset(role, 0, sizeof(role)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(role, tlv->value, tlv->len); + if (atoi(role) == DUT_TYPE_P2PUT) { + /* Get P2P GO/Client or Device MAC */ + if (get_p2p_mac_addr(mac_addr, sizeof(mac_addr))) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to get TP P2P MAC address!"); + get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); + } + } + } else { + get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); + } + status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; } @@ -1468,3 +1487,172 @@ static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_ return 0; } + +static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; + char buffer[S_BUFFER_LEN], response[1024], log_level[TLV_VALUE_SIZE], value[TLV_VALUE_SIZE]; + int len, status = TLV_VALUE_STATUS_NOT_OK, i; + size_t resp_len; + char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; + struct tlv_hdr *tlv = NULL; + +#ifdef _OPENWRT_ +#else + system("rfkill unblock wlan"); + sleep(1); +#endif + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + system(buffer); + sleep(3); + + tlv = find_wrapper_tlv_by_id(req, TLV_CONTROL_INTERFACE); + if (tlv) { + memset(buffer, 0, sizeof(buffer)); + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + set_wpas_ctrl_path(value); + sprintf(buffer, "ctrl_interface=%s\n", value); + + /* Add Device name and Device type */ + strcat(buffer, "device_name=WFA P2P Device\n"); + strcat(buffer, "device_type=1-0050F204-1\n"); + len = strlen(buffer); + + if (len) { + write_file(get_wpas_conf_file(), buffer, len); + } + } else { + indigo_logger(LOG_LEVEL_ERROR, "No remote UDP port in TP"); + } + + /* TLV: DEBUG_LEVEL */ + tlv = find_wrapper_tlv_by_id(req, TLV_DEBUG_LEVEL); + memset(log_level, 0, sizeof(log_level)); + if (tlv) { + memcpy(log_level, tlv->value, tlv->len); + } + + if (strlen(log_level)) { + set_wpas_debug_level(get_debug_level(atoi(log_level))); + } + + /* Start WPA supplicant */ + memset(buffer, 0 ,sizeof(buffer)); + sprintf(buffer, "%s -B -t -c %s %s -i %s -f %s", + get_wpas_full_exec_path(), + get_wpas_conf_file(), + get_wpas_debug_arguments(), + get_wireless_interface(), + WPAS_LOG_FILE); + len = system(buffer); + sleep(2); + + len = pipe_command(buffer, sizeof(buffer), "/bin/pidof", parameter); + if (len) { + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_WPA_S_START_UP_OK; + } else { + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_START_UP_NOT_OK; + } + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + return 0; +} + + +static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_START_DHCP_NOT_OK; + char buffer[S_BUFFER_LEN]; + char param_value[256], role[8]; + struct tlv_hdr *tlv = NULL; + FILE *fp; + char if_name[32]; + + memset(role, 0, sizeof(role)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(role, tlv->value, tlv->len); + if (atoi(role) == DUT_TYPE_P2PUT) { + get_p2p_group_if(if_name, sizeof(if_name)); + } else { + } + } + + /* TLV: TLV_STATIC_IP */ + memset(param_value, 0, sizeof(param_value)); + tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); + if (tlv) { + memcpy(param_value, tlv->value, tlv->len); + if (!strcmp("0.0.0.0", param_value)) { + snprintf(buffer, sizeof(buffer), "%s/24", DHCP_SERVER_IP); + } else { /* Need to update dhcp conf when using specific IP */ + snprintf(buffer, sizeof(buffer), "%s/24", param_value); + } + set_interface_ip(if_name, buffer); + /* Assign specific IF for DHCP Server */ + snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); + indigo_logger(LOG_LEVEL_DEBUG, buffer); + system(buffer); + snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); + system(buffer); + } else { + snprintf(buffer, sizeof(buffer), "dhclient -4 %s &", if_name); + system(buffer); + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + + return 0; +} + +static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_NOT_OK; + char buffer[S_BUFFER_LEN]; + char role[8]; + struct tlv_hdr *tlv = NULL; + char if_name[32]; + + memset(role, 0, sizeof(role)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(role, tlv->value, tlv->len); + if (atoi(role) == DUT_TYPE_P2PUT) { + get_p2p_group_if(if_name, sizeof(if_name)); + } else { + } + } else { + } + + /* TLV: TLV_STATIC_IP */ + tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); + if (tlv) { /* DHCP Server */ + snprintf(buffer, sizeof(buffer), "systemctl stop isc-dhcp-server.service"); + system(buffer); + } else { /* DHCP Client */ + snprintf(buffer, sizeof(buffer), "killall dhclient 1>/dev/null 2>/dev/null"); + system(buffer); + } + reset_interface_ip(if_name); + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + + return 0; +} diff --git a/utils.c b/utils.c index 467794f..0d2a1e1 100644 --- a/utils.c +++ b/utils.c @@ -482,7 +482,8 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet timeout.tv_sec = 1; timeout.tv_usec = 0; } - snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); + if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) + snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); const int len = strnlen(ifname, IFNAMSIZ); if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, ifname, len) < 0) { indigo_logger(LOG_LEVEL_ERROR, "failed to bind the interface %s", ifname); @@ -584,7 +585,8 @@ int send_icmp_data(char *target_ip, int packet_count, int packet_size, double ra timeout.tv_usec = 0; } - snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); + if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) + snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); const int len = strnlen(ifname, IFNAMSIZ); if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, ifname, len) < 0) { indigo_logger(LOG_LEVEL_ERROR, "failed to bind the interface %s", ifname); @@ -1069,6 +1071,11 @@ char* get_wpas_ctrl_path() { return wpas_full_ctrl_path; } +char* get_wpas_if_ctrl_path(char* if_name) { + memset(wpas_full_ctrl_path, 0, sizeof(wpas_full_ctrl_path)); + sprintf(wpas_full_ctrl_path, "%s/%s", wpas_ctrl_path, if_name); + return wpas_full_ctrl_path; +} int set_wpas_ctrl_path(char* path) { snprintf(wpas_ctrl_path, sizeof(wpas_ctrl_path), "%s", path); return 0; diff --git a/utils.h b/utils.h index 8f881fd..d82d19f 100644 --- a/utils.h +++ b/utils.h @@ -177,6 +177,7 @@ int set_wpas_exec_file(char* path); char* get_wpas_full_exec_path(); int set_wpas_full_exec_path(char* path); char* get_wpas_ctrl_path(); +char* get_wpas_if_ctrl_path(char* if_name); int set_wpas_ctrl_path(char* path); char* get_wpas_global_ctrl_path(); int set_wpas_global_ctrl_path(char* path); diff --git a/vendor_specific.h b/vendor_specific.h index d469763..451284f 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -83,6 +83,10 @@ #define HOSTAPD_SUPPORT_MBSSID_WAR #endif +/* Default DUT GO intent value */ +#define P2P_GO_INTENT 7 + +#define DHCP_SERVER_IP "192.168.65.1" void vendor_init(); void vendor_deinit(); void vendor_device_reset(); @@ -118,4 +122,7 @@ void configure_ap_enable_mbssid(); void configure_ap_radio_params(char *band, char *country, int channel, int chwidth); void start_ap_set_wlan_params(void *if_info); +int get_p2p_mac_addr(char *mac_addr, size_t size); +int get_p2p_group_if(char *if_name, size_t size); + #endif diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 88e6eed..36d0b71 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -261,3 +261,69 @@ void start_ap_set_wlan_params(void *if_info) { #endif printf("set_wlan_params: %s\n", buffer); } + +int get_p2p_mac_addr(char *mac_addr, size_t size) { + FILE *fp; + char buffer[S_BUFFER_LEN], *ptr, addr[32]; + int error = 1; + + fp = popen("iw dev", "r"); + if (fp) { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "addr"); + if (ptr != NULL) { + sscanf(ptr, "%*s %s", addr); + if (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "type"); + if (ptr != NULL) { + ptr += 5; + if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { + snprintf(mac_addr, size, "%s", addr); + error = 0; + break; + } else if (!strncmp(ptr, "P2P-device", 10)) { + snprintf(mac_addr, size, "%s", addr); + error = 0; + } + } else { + printf("Format changed??? Can't detect device type"); + } + } + } + } + pclose(fp); + } + + return error; +} + +int get_p2p_group_if(char *if_name, size_t size) { + FILE *fp; + char buffer[S_BUFFER_LEN], *ptr, name[32]; + int error = 1; + + fp = popen("iw dev", "r"); + if (fp) { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "Interface"); + if (ptr != NULL) { + sscanf(ptr, "%*s %s", name); + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "type"); + if (ptr != NULL) { + ptr += 5; + if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { + snprintf(if_name, size, "%s", name); + error = 0; + break; + } + } + } + break; + } + } + pclose(fp); + } + + return error; +} diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 9a3c0eb..e1f6330 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -442,4 +442,70 @@ const struct sta_driver_ops sta_driver_platform2_ops = { .set_phy_mode = set_phy_mode_platform2, }; + +int get_p2p_mac_addr(char *mac_addr, size_t size) { + FILE *fp; + char buffer[S_BUFFER_LEN], *ptr, addr[32]; + int error = 1; + + fp = popen("iw dev", "r"); + if (fp) { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "addr"); + if (ptr != NULL) { + sscanf(ptr, "%*s %s", addr); + if (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "type"); + if (ptr != NULL) { + ptr += 5; + if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { + snprintf(mac_addr, size, "%s", addr); + error = 0; + break; + } else if (!strncmp(ptr, "P2P-device", 10)) { + snprintf(mac_addr, size, "%s", addr); + error = 0; + } + } else { + printf("Format changed??? Can't detect device type"); + } + } + } + } + pclose(fp); + } + + return error; +} + +int get_p2p_group_if(char *if_name, size_t size) { + FILE *fp; + char buffer[S_BUFFER_LEN], *ptr, name[32]; + int error = 1; + + fp = popen("iw dev", "r"); + if (fp) { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "Interface"); + if (ptr != NULL) { + sscanf(ptr, "%*s %s", name); + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + ptr = strstr(buffer, "type"); + if (ptr != NULL) { + ptr += 5; + if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { + snprintf(if_name, size, "%s", name); + error = 0; + break; + } + } + } + break; + } + } + pclose(fp); + } + + return error; +} #endif /* _TEST_PLATFORM_ */ From ca3ea11c22054374dc3ae684689187a4bdb3f958 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Thu, 9 Dec 2021 16:45:19 +0800 Subject: [PATCH 06/90] Return MAC of wireless IF when there is no P2P device --- indigo_api_callback_dut.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index f9e208f..7dca345 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -939,12 +939,11 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe } else if (atoi(role) == DUT_TYPE_P2PUT) { /* Get P2P GO/Client or Device MAC */ if (get_p2p_mac_addr(mac_addr, sizeof(mac_addr))) { - status = TLV_VALUE_STATUS_NOT_OK; - message = "Unable to get mac address of the P2P device"; - } else { - status = TLV_VALUE_STATUS_OK; - message = TLV_VALUE_OK; + indigo_logger(LOG_LEVEL_INFO, "Can't find P2P Device MAC. Use wireless IF MAC"); + get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; goto done; } else { wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); From 2571859e8220928422787491b5a9219ae1735fa5 Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Tue, 14 Dec 2021 17:51:57 +0800 Subject: [PATCH 07/90] Add PMF in global setting for wpa_supplicant config --- hs2_profile.h | 2 +- indigo_api_callback.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/hs2_profile.h b/hs2_profile.h index ae7f99b..5688a97 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -52,7 +52,7 @@ const char * venue_name[] = { const char * network_auth_type[] = { "", "network_auth_type=00https://tandc-server.wi-fi.org/\n", - "network_auth_type=01", + "network_auth_type=01\n", }; const char * ipaddr_type_avail[] = { diff --git a/indigo_api_callback.h b/indigo_api_callback.h index b749bad..3331b2f 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -195,6 +195,7 @@ struct tlv_to_config_name wpas_global_maps[] = { { TLV_HESSID, "hessid", 0 }, { TLV_ACCESS_NETWORK_TYPE, "access_network_type", 0 }, { TLV_FREQ_LIST, "freq_list", 0 }, + { TLV_IEEE80211_W, "pmf", 0 }, }; struct tlv_to_config_name* find_wpas_global_config_name(int tlv_id) { From a23e8ec291275dc791589a207612e5e3b4668658 Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 15 Dec 2021 10:32:46 +0800 Subject: [PATCH 08/90] Update README.md --- README.md | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/README.md b/README.md index 5a14c72..210c331 100644 --- a/README.md +++ b/README.md @@ -29,28 +29,3 @@ Build & Run make clean ; make
sudo ./app -p <port> ------------------------------------------------------------------------- -OpenWRT Prerequisite ------------------------------------------------------------------------- -1. Add firewall rule to allow to run ControlAppC on WAN
-uci add firewall rule
-uci add_list firewall.@rule[10].target='ACCEPT'
-uci add_list firewall.@rule[10].src='wan'
-uci add_list firewall.@rule[10].proto='tcp udp'
-uci add_list firewall.@rule[10].dest_port='9004'
-uci add_list firewall.@rule[10].name='ControlAppC'
-uci commit
-2. Disable Wi-Fi for the clean start
-uci delete wireless.@wifi-iface[0]
-uci delete wireless.@wifi-iface[1]
-uci commit
- ------------------------------------------------------------------------- -OpenWRT Build ------------------------------------------------------------------------- -Change Makefile
-ROLE = openwrt
-make clean ; make
- -Use scp to copy app to OpenWRT
-./app -p <port> From 54dc72bba3ff6350b35bcb3115429d6f6cc7a154 Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Thu, 16 Dec 2021 16:43:49 +0800 Subject: [PATCH 09/90] Add PMF global configuration in start_up_sta_handler --- indigo_api_callback.h | 1 - indigo_api_callback_tp.c | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 3331b2f..b749bad 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -195,7 +195,6 @@ struct tlv_to_config_name wpas_global_maps[] = { { TLV_HESSID, "hessid", 0 }, { TLV_ACCESS_NETWORK_TYPE, "access_network_type", 0 }, { TLV_FREQ_LIST, "freq_list", 0 }, - { TLV_IEEE80211_W, "pmf", 0 }, }; struct tlv_to_config_name* find_wpas_global_config_name(int tlv_id) { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index cf9fc07..cbd9310 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1263,6 +1263,14 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe set_wpas_ctrl_path(value); sprintf(buffer, "ap_scan=1\n"); + tlv = find_wrapper_tlv_by_id(req, TLV_STA_IEEE80211_W); + if (tlv) { + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + sprintf(cfg_item, "pmf=%s\n", value); + strcat(buffer, cfg_item); + } + for (i = 0; i < req->tlv_num; i++) { cfg = find_wpas_global_config_name(req->tlv[i]->id); if (cfg) { From 7a5d1d1479f31dea14c38260fe695ebfefc07c20 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Thu, 23 Dec 2021 17:29:28 +0800 Subject: [PATCH 10/90] Enhance DHCP start/stop mechanism and add GET_WSC_PIN API --- QT_dhcpd.conf | 108 +++++++++++++++++++++++++++++++++++++ build_deb.sh | 6 ++- indigo_api.c | 1 + indigo_api.h | 3 ++ indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 109 +++++++++++++++++++++++++++++--------- indigo_api_callback_tp.c | 43 ++++++++------- vendor_specific.h | 4 ++ vendor_specific_dut.c | 52 ++++++++++++++++++ vendor_specific_tp.c | 52 ++++++++++++++++++ 10 files changed, 330 insertions(+), 49 deletions(-) create mode 100644 QT_dhcpd.conf mode change 100644 => 100755 build_deb.sh diff --git a/QT_dhcpd.conf b/QT_dhcpd.conf new file mode 100644 index 0000000..abfed54 --- /dev/null +++ b/QT_dhcpd.conf @@ -0,0 +1,108 @@ +# dhcpd.conf +# +# Sample configuration file for ISC dhcpd +# +# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as +# configuration file instead of this file. +# + +# option definitions common to all supported networks... +option domain-name "example.org"; +option domain-name-servers ns1.example.org, ns2.example.org; + +default-lease-time 600; +max-lease-time 7200; + +# The ddns-updates-style parameter controls whether or not the server will +# attempt to do a DNS update when a lease is confirmed. We default to the +# behavior of the version 2 packages ('none', since DHCP v2 didn't +# have support for DDNS.) +ddns-update-style none; + +# If this DHCP server is the official DHCP server for the local +# network, the authoritative directive should be uncommented. +#authoritative; + +# Use this to send dhcp log messages to a different log file (you also +# have to hack syslog.conf to complete the redirection). +#log-facility local7; + +# No service will be given on this subnet, but declaring it helps the +# DHCP server to understand the network topology. + +# This is a very basic subnet declaration. + +#subnet 10.254.239.0 netmask 255.255.255.224 { +# range 10.254.239.10 10.254.239.20; +# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; +#} + +# This declaration allows BOOTP clients to get dynamic addresses, +# which we don't really recommend. + +#subnet 10.254.239.32 netmask 255.255.255.224 { +# range dynamic-bootp 10.254.239.40 10.254.239.60; +# option broadcast-address 10.254.239.31; +# option routers rtr-239-32-1.example.org; +#} + +# A slightly different configuration for an internal subnet. +#subnet 10.5.5.0 netmask 255.255.255.224 { +# range 10.5.5.26 10.5.5.30; +# option domain-name-servers ns1.internal.example.org; +# option domain-name "internal.example.org"; +# option subnet-mask 255.255.255.224; +# option routers 10.5.5.1; +# option broadcast-address 10.5.5.31; +# default-lease-time 600; +# max-lease-time 7200; +#} + +# Hosts which require special configuration options can be listed in +# host statements. If no address is specified, the address will be +# allocated dynamically (if possible), but the host-specific information +# will still come from the host declaration. + +#host passacaglia { +# hardware ethernet 0:0:c0:5d:bd:95; +# filename "vmunix.passacaglia"; +# server-name "toccata.example.com"; +#} + +# Fixed IP addresses can also be specified for hosts. These addresses +# should not also be listed as being available for dynamic assignment. +# Hosts for which fixed IP addresses have been specified can boot using +# BOOTP or DHCP. Hosts for which no fixed address is specified can only +# be booted with DHCP, unless there is an address range on the subnet +# to which a BOOTP client is connected which has the dynamic-bootp flag +# set. +#host fantasia { +# hardware ethernet 08:00:07:26:c0:a5; +# fixed-address fantasia.example.com; +#} + +# You can declare a class of clients and then do address allocation +# based on that. The example below shows a case where all clients +# in a certain class get addresses on the 10.17.224/24 subnet, and all +# other clients get addresses on the 10.0.29/24 subnet. + +#class "foo" { +# match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; +#} + +#shared-network 224-29 { +# subnet 10.17.224.0 netmask 255.255.255.0 { +# option routers rtr-224.example.org; +# } +# subnet 10.0.29.0 netmask 255.255.255.0 { +# option routers rtr-29.example.org; +# } +# pool { +# allow members of "foo"; +# range 10.17.224.10 10.17.224.250; +# } +# pool { +# deny members of "foo"; +# range 10.0.29.10 10.0.29.230; +# } +#} diff --git a/build_deb.sh b/build_deb.sh old mode 100644 new mode 100755 index b86d95f..2755f3d --- a/build_deb.sh +++ b/build_deb.sh @@ -20,13 +20,14 @@ create_source_folder() { copy_filter_source() { cp -rf *.c *.h Makefile ${source_folder} cp -rf patch_nwmgr.sh ${source_folder} + cp -rf QT_dhcpd.conf ${source_folder} } create_control() { echo "Package: ${package_name}" >"$control_file" echo "Version: ${version}-${revision}" >>"$control_file" echo "Architecture: all" >>"$control_file" - echo "Depends: build-essential, arping" >>"$control_file" + echo "Depends: build-essential, arping, isc-dhcp-server" >>"$control_file" echo "Essential: no" >>"$control_file" echo "Conflicts: wfa-indigo-controlappc" >>"$control_file" echo "Priority: optional" >>"$control_file" @@ -50,6 +51,8 @@ create_postinst() { echo "cp app ../app_tp" >>"$postinst_file" echo "make clean >/dev/null" >>"$postinst_file" + echo "cp QT_dhcpd.conf ../QT_dhcpd.conf" >>"$postinst_file" + echo "echo \"Test application version\"" >>"$postinst_file" echo "../app_dut -v" >>"$postinst_file" echo "../app_tp -v" >>"$postinst_file" @@ -72,6 +75,7 @@ create_prerm() { echo "rm -rf /usr/local/bin/${package_name}/app_dut" >>"$prerm_file" echo "rm -rf /usr/local/bin/${package_name}/app_tp" >>"$prerm_file" echo "/bin/bash ${installed_source_folder}/patch_nwmgr.sh restore" >>"$prerm_file" + echo "rm -rf /usr/local/bin/${package_name}/QT_dhcpd.conf" >>"$prerm_file" echo "fi" >>"$prerm_file" chmod 755 "$prerm_file" diff --git a/indigo_api.c b/indigo_api.c index 0d3f452..46bf9e5 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -68,6 +68,7 @@ struct indigo_api indigo_api_list[] = { { API_STOP_LOOP_BACK_DATA, "STOP_LOOP_BACK_DATA", NULL, NULL }, { API_START_DHCP, "START_DHCP", NULL, NULL }, { API_STOP_DHCP, "STOP_DHCP", NULL, NULL }, + { API_GET_WSC_PIN, "GET_WSC_PIN", NULL, NULL }, }; /* Structure to declare the TLV list */ diff --git a/indigo_api.h b/indigo_api.h index 2d0b69b..a595c5e 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -81,6 +81,7 @@ struct indigo_api { #define API_STOP_LOOP_BACK_DATA 0x5009 #define API_START_DHCP 0x500a #define API_STOP_DHCP 0x500b +#define API_GET_WSC_PIN 0x500c /* TLV definition */ #define TLV_SSID 0x0001 @@ -252,6 +253,7 @@ struct indigo_api { #define TLV_ARP_RECV_NUM 0xa007 #define TLV_TEST_PLATFORM_APP_VERSION 0xa008 #define TLV_LOOP_BACK_SERVER_PORT 0xa009 +#define TLV_WSC_PIN_CODE 0xa00a /* TLV Value */ #define DUT_TYPE_STAUT 0x01 @@ -320,6 +322,7 @@ struct indigo_api { #define RESET_TYPE_TEARDOWN 0x02 #define WPA_CTRL_OK "OK" +#define WPA_CTRL_FAIL "FAIL" #define P2P_CONN_TYPE_JOIN 0x01 #define P2P_CONN_TYPE_AUTH 0x02 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index b749bad..f087ca0 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -230,6 +230,7 @@ static int get_ip_addr_handler(struct packet_wrapper *req, struct packet_wrapper static int reset_device_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* AP */ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 7dca345..cd486b3 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -42,6 +42,7 @@ void register_apis() { register_api(API_DEVICE_RESET, NULL, reset_device_handler); register_api(API_START_DHCP, NULL, start_dhcp_handler); register_api(API_STOP_DHCP, NULL, stop_dhcp_handler); + register_api(API_GET_WSC_PIN, NULL, get_wsc_pin_handler); /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); @@ -2020,6 +2021,8 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe /* Add Device name and Device type */ strcat(buffer, "device_name=WFA P2P Device\n"); strcat(buffer, "device_type=1-0050F204-1\n"); + /* Add config methods */ + strcat(buffer, "config_methods=keypad display push_button\n"); len = strlen(buffer); if (len) { @@ -2213,7 +2216,10 @@ static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapp memset(response, 0, sizeof(response)); resp_len = sizeof(response) - 1; wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); - /* Skip response check as response is not OK */ + if (strncmp(response, WPA_CTRL_FAIL, strlen(WPA_CTRL_FAIL)) == 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command(%s).", buffer); + goto done; + } status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; @@ -2237,13 +2243,14 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_P2P_CONNECT_NOT_OK; struct tlv_hdr *tlv = NULL; - char go_intent[32]; + char go_intent[32], he[16]; int intent_value = P2P_GO_INTENT; memset(buffer, 0, sizeof(buffer)); memset(mac, 0, sizeof(mac)); memset(method, 0, sizeof(method)); memset(type, 0, sizeof(type)); + memset(he, 0, sizeof(he)); tlv = find_wrapper_tlv_by_id(req, TLV_ADDRESS); if (tlv) { memcpy(mac, tlv->value, tlv->len); @@ -2270,6 +2277,10 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper } else { snprintf(go_intent, sizeof(go_intent), " go_intent=%d", intent_value); } + tlv = find_wrapper_tlv_by_id(req, TLV_IEEE80211_AX); + if (tlv) { + snprintf(he, sizeof(he), " he"); + } tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); if (tlv) { memset(pin_code, 0, sizeof(pin_code)); @@ -2280,7 +2291,7 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper } else { indigo_logger(LOG_LEVEL_ERROR, "Missed TLV PIN_METHOD???"); } - sprintf(buffer, "P2P_CONNECT %s %s %s%s%s", mac, pin_code, method, type, go_intent); + sprintf(buffer, "P2P_CONNECT %s %s %s%s%s%s", mac, pin_code, method, type, go_intent, he); } else { tlv = find_wrapper_tlv_by_id(req, TLV_WSC_METHOD); if (tlv) { @@ -2288,7 +2299,7 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper } else { indigo_logger(LOG_LEVEL_ERROR, "Missed TLV WSC_METHOD"); } - sprintf(buffer, "P2P_CONNECT %s %s%s%s", mac, method, type, go_intent); + sprintf(buffer, "P2P_CONNECT %s %s%s%s%s", mac, method, type, go_intent, he); } indigo_logger(LOG_LEVEL_DEBUG, "Command: %s", buffer); @@ -2326,9 +2337,8 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_START_DHCP_NOT_OK; char buffer[S_BUFFER_LEN]; - char param_value[256], role[8]; + char ip_addr[32], role[8]; struct tlv_hdr *tlv = NULL; - FILE *fp; char if_name[32]; memset(role, 0, sizeof(role)); @@ -2347,25 +2357,18 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper } /* TLV: TLV_STATIC_IP */ - memset(param_value, 0, sizeof(param_value)); + memset(ip_addr, 0, sizeof(ip_addr)); tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); - if (tlv) { - memcpy(param_value, tlv->value, tlv->len); - if (!strcmp("0.0.0.0", param_value)) { - snprintf(buffer, sizeof(buffer), "%s/24", DHCP_SERVER_IP); - } else { /* Need to update dhcp conf when using specific IP */ - snprintf(buffer, sizeof(buffer), "%s/24", param_value); + if (tlv) { /* DHCP Server */ + memcpy(ip_addr, tlv->value, tlv->len); + if (!strcmp("0.0.0.0", ip_addr)) { + snprintf(ip_addr, sizeof(ip_addr), DHCP_SERVER_IP); } + snprintf(buffer, sizeof(buffer), "%s/24", ip_addr); set_interface_ip(if_name, buffer); - /* Assign specific IF for DHCP Server */ - snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); - indigo_logger(LOG_LEVEL_DEBUG, buffer); - system(buffer); - snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); - system(buffer); - } else { - snprintf(buffer, sizeof(buffer), "dhclient -4 %s &", if_name); - system(buffer); + start_dhcp_server(if_name, ip_addr); + } else { /* DHCP Client */ + start_dhcp_client(if_name); } status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; @@ -2404,11 +2407,9 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * /* TLV: TLV_STATIC_IP */ tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); if (tlv) { /* DHCP Server */ - snprintf(buffer, sizeof(buffer), "systemctl stop isc-dhcp-server.service"); - system(buffer); + stop_dhcp_server(); } else { /* DHCP Client */ - snprintf(buffer, sizeof(buffer), "killall dhclient 1>/dev/null 2>/dev/null"); - system(buffer); + stop_dhcp_client(); } reset_interface_ip(if_name); status = TLV_VALUE_STATUS_OK; @@ -2421,3 +2422,59 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * return 0; } + + +static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_NOT_OK; + char buffer[64], response[S_BUFFER_LEN]; + struct tlv_hdr *tlv = NULL; + char value[16]; + int role = 0; + struct wpa_ctrl *w = NULL; + size_t resp_len; + + memset(value, 0, sizeof(value)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(value, tlv->value, tlv->len); + role = atoi(value); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); + goto done; + } + + if (role == DUT_TYPE_APUT) { + // TODO + } else if (role == DUT_TYPE_STAUT || role == DUT_TYPE_P2PUT) { + sprintf(buffer, "WPS_PIN get"); + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + } else { + indigo_logger(LOG_LEVEL_ERROR, "Invalid value in TLV_ROLE"); + } + + memset(response, 0, sizeof(response)); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + if (strncmp(response, WPA_CTRL_FAIL, strlen(WPA_CTRL_FAIL)) == 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command(%s).", buffer); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (status == TLV_VALUE_STATUS_OK) { + fill_wrapper_tlv_bytes(resp, TLV_WSC_PIN_CODE, strlen(response), response); + } + return 0; +} diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index cf9fc07..110141e 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1518,6 +1518,8 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe /* Add Device name and Device type */ strcat(buffer, "device_name=WFA P2P Device\n"); strcat(buffer, "device_type=1-0050F204-1\n"); + /* Add config methods */ + strcat(buffer, "config_methods=keypad display push_button\n"); len = strlen(buffer); if (len) { @@ -1570,9 +1572,8 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_START_DHCP_NOT_OK; char buffer[S_BUFFER_LEN]; - char param_value[256], role[8]; + char ip_addr[32], role[8]; struct tlv_hdr *tlv = NULL; - FILE *fp; char if_name[32]; memset(role, 0, sizeof(role)); @@ -1583,29 +1584,26 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper get_p2p_group_if(if_name, sizeof(if_name)); } else { } + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); + goto done; } /* TLV: TLV_STATIC_IP */ - memset(param_value, 0, sizeof(param_value)); + memset(ip_addr, 0, sizeof(ip_addr)); tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); - if (tlv) { - memcpy(param_value, tlv->value, tlv->len); - if (!strcmp("0.0.0.0", param_value)) { - snprintf(buffer, sizeof(buffer), "%s/24", DHCP_SERVER_IP); - } else { /* Need to update dhcp conf when using specific IP */ - snprintf(buffer, sizeof(buffer), "%s/24", param_value); + if (tlv) { /* DHCP Server */ + memcpy(ip_addr, tlv->value, tlv->len); + if (!strcmp("0.0.0.0", ip_addr)) { + snprintf(ip_addr, sizeof(ip_addr), DHCP_SERVER_IP); } + snprintf(buffer, sizeof(buffer), "%s/24", ip_addr); set_interface_ip(if_name, buffer); - /* Assign specific IF for DHCP Server */ - snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); - indigo_logger(LOG_LEVEL_DEBUG, buffer); - system(buffer); - snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); - system(buffer); - } else { - snprintf(buffer, sizeof(buffer), "dhclient -4 %s &", if_name); - system(buffer); + start_dhcp_server(if_name, ip_addr); + } else { /* DHCP Client */ + start_dhcp_client(if_name); } + status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; @@ -1634,18 +1632,19 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * } else { } } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); + goto done; } /* TLV: TLV_STATIC_IP */ tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); if (tlv) { /* DHCP Server */ - snprintf(buffer, sizeof(buffer), "systemctl stop isc-dhcp-server.service"); - system(buffer); + stop_dhcp_server(); } else { /* DHCP Client */ - snprintf(buffer, sizeof(buffer), "killall dhclient 1>/dev/null 2>/dev/null"); - system(buffer); + stop_dhcp_client(); } reset_interface_ip(if_name); + status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; diff --git a/vendor_specific.h b/vendor_specific.h index 451284f..1da4e0a 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -125,4 +125,8 @@ void start_ap_set_wlan_params(void *if_info); int get_p2p_mac_addr(char *mac_addr, size_t size); int get_p2p_group_if(char *if_name, size_t size); +void start_dhcp_server(char *if_name, char *ip_addr); +void stop_dhcp_server(); +void start_dhcp_client(char *if_name); +void stop_dhcp_client(); #endif diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 36d0b71..a8a056e 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -327,3 +327,55 @@ int get_p2p_group_if(char *if_name, size_t size) { return error; } + + +void start_dhcp_server(char *if_name, char *ip_addr) +{ + char buffer[S_BUFFER_LEN]; + char ip_sub[32], *ptr; + FILE *fp; + + /* + snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); + system(buffer); + snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); + system(buffer); + */ + // dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf p2p-wlp2s0-0 + // Avoid apparmor check because we manually start dhcpd + memset(ip_sub, 0, sizeof(ip_sub)); + ptr = strrchr(ip_addr, '.'); + memcpy(ip_sub, ip_addr, ptr - ip_addr); + system("cp QT_dhcpd.conf /etc/dhcp/QT_dhcpd.conf"); + fp = fopen("/etc/dhcp/QT_dhcpd.conf", "a"); + if (fp) { + snprintf(buffer, sizeof(buffer), "\nsubnet %s.0 netmask 255.255.255.0 {\n", ip_sub); + fputs(buffer, fp); + snprintf(buffer, sizeof(buffer), " range %s.50 %s.200;\n", ip_sub, ip_sub); + fputs(buffer, fp); + fputs("}\n", fp); + fclose(fp); + } + system("touch /var/lib/dhcp/dhcpd.leases_QT"); + snprintf(buffer, sizeof(buffer), "dhcpd -4 -cf /etc/dhcp/QT_dhcpd.conf -lf /var/lib/dhcp/dhcpd.leases_QT %s", if_name); + system(buffer); +} + +void stop_dhcp_server() +{ + //system("systemctl stop isc-dhcp-server.service"); + system("killall dhcpd 1>/dev/null 2>/dev/null"); +} + +void start_dhcp_client(char *if_name) +{ + char buffer[S_BUFFER_LEN]; + + snprintf(buffer, sizeof(buffer), "dhclient -4 %s &", if_name); + system(buffer); +} + +void stop_dhcp_client() +{ + system("killall dhclient 1>/dev/null 2>/dev/null"); +} diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index e1f6330..983a6cc 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -508,4 +508,56 @@ int get_p2p_group_if(char *if_name, size_t size) { return error; } + + +void start_dhcp_server(char *if_name, char *ip_addr) +{ + char buffer[S_BUFFER_LEN]; + char ip_sub[32], *ptr; + FILE *fp; + + /* + snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); + system(buffer); + snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); + system(buffer); + */ + // dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf p2p-wlp2s0-0 + // Avoid apparmor check because we manually start dhcpd + memset(ip_sub, 0, sizeof(ip_sub)); + ptr = strrchr(ip_addr, '.'); + memcpy(ip_sub, ip_addr, ptr - ip_addr); + system("cp QT_dhcpd.conf /etc/dhcp/QT_dhcpd.conf"); + fp = fopen("/etc/dhcp/QT_dhcpd.conf", "a"); + if (fp) { + snprintf(buffer, sizeof(buffer), "\nsubnet %s.0 netmask 255.255.255.0 {\n", ip_sub); + fputs(buffer, fp); + snprintf(buffer, sizeof(buffer), " range %s.50 %s.200;\n", ip_sub, ip_sub); + fputs(buffer, fp); + fputs("}\n", fp); + fclose(fp); + } + system("touch /var/lib/dhcp/dhcpd.leases_QT"); + snprintf(buffer, sizeof(buffer), "dhcpd -4 -cf /etc/dhcp/QT_dhcpd.conf -lf /var/lib/dhcp/dhcpd.leases_QT %s", if_name); + system(buffer); +} + +void stop_dhcp_server() +{ + //system("systemctl stop isc-dhcp-server.service"); + system("killall dhcpd 1>/dev/null 2>/dev/null"); +} + +void start_dhcp_client(char *if_name) +{ + char buffer[S_BUFFER_LEN]; + + snprintf(buffer, sizeof(buffer), "dhclient -4 %s &", if_name); + system(buffer); +} + +void stop_dhcp_client() +{ + system("killall dhclient 1>/dev/null 2>/dev/null"); +} #endif /* _TEST_PLATFORM_ */ From 5a10edfdf14525caed1c608fad6e3a4591530727 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 4 Jan 2022 10:18:46 +0800 Subject: [PATCH 11/90] ITS-2082 Add STA_SCAN API Support test script 10575_1 --- indigo_api.c | 1 + indigo_api.h | 4 ++ indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 78 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index 46bf9e5..d69bbc9 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -49,6 +49,7 @@ struct indigo_api indigo_api_list[] = { { API_STA_SET_PHY_MODE, "STA_SET_PHY_MODE", NULL, NULL }, { API_STA_SET_CHANNEL_WIDTH, "STA_SET_CHANNEL_WIDTH", NULL, NULL }, { API_STA_POWER_SAVE, "STA_POWER_SAVE", NULL, NULL }, + { API_STA_SCAN, "STA_SCAN", NULL, NULL }, { API_P2P_START_UP, "P2P_START_UP", NULL, NULL }, { API_P2P_FIND, "P2P_FIND", NULL, NULL }, { API_P2P_LISTEN, "P2P_LISTEN", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index a595c5e..3bdba72 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -68,6 +68,9 @@ struct indigo_api { #define API_P2P_ADD_GROUP 0x200f #define API_P2P_START_WPS 0x2010 #define API_P2P_CONNECT 0x2011 +#define API_STA_HS2_ASSOCIATE 0x2012 +#define API_STA_ADD_CREDENTIAL 0x2013 +#define API_STA_SCAN 0x2014 #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -307,6 +310,7 @@ struct indigo_api { #define TLV_VALUE_WPA_S_CTRL_NOT_OK "Failed to connect to WPA supplicant control interface" #define TLV_VALUE_WPA_S_BTM_QUERY_OK "Sent WNM_BSS_QUERY" #define TLV_VALUE_WPA_S_BTM_QUERY_NOT_OK "Failed to WNM_BSS_QUERY" +#define TLV_VALUE_WPA_S_SCAN_NOT_OK "Failed to trigger SCAN" #define TLV_VALUE_RESET_OK "Device reset successfully" #define TLV_VALUE_RESET_NOT_OK "Failed to run Device reset" #define TLV_VALUE_POWER_SAVE_OK "Set power save value successfully" diff --git a/indigo_api_callback.h b/indigo_api_callback.h index f087ca0..1becd73 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -249,6 +249,7 @@ static int send_sta_disconnect_handler(struct packet_wrapper *req, struct packet static int send_sta_reconnect_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int send_sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_phy_mode_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_channel_width_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index cd486b3..98e5aea 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -60,6 +60,7 @@ void register_apis() { register_api(API_STA_SET_PARAM, NULL, set_sta_parameter_handler); register_api(API_STA_SEND_BTM_QUERY, NULL, send_sta_btm_query_handler); register_api(API_STA_SEND_ANQP_QUERY, NULL, send_sta_anqp_query_handler); + register_api(API_STA_SCAN, NULL, send_sta_scan_handler); /* TODO: Add the handlers */ register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL); register_api(API_STA_POWER_SAVE, NULL, NULL); @@ -2234,6 +2235,83 @@ static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapp return 0; } +static int send_sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int len, status = TLV_VALUE_STATUS_NOT_OK, i; + char *message = TLV_VALUE_WPA_S_SCAN_NOT_OK; + char buffer[1024]; + char response[1024]; + struct tlv_hdr *tlv = NULL; + struct wpa_ctrl *w = NULL; + size_t resp_len; + struct tlv_to_config_name* cfg = NULL; + char value[TLV_VALUE_SIZE], cfg_item[2*S_BUFFER_LEN]; + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT); + tlv = find_wrapper_tlv_by_id(req, TLV_STA_IEEE80211_W); + if (tlv) { + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + sprintf(cfg_item, "pmf=%s\n", value); + strcat(buffer, cfg_item); + } + for (i = 0; i < req->tlv_num; i++) { + cfg = find_wpas_global_config_name(req->tlv[i]->id); + if (cfg) { + memset(value, 0, sizeof(value)); + memcpy(value, req->tlv[i]->value, req->tlv[i]->len); + sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); + strcat(buffer, cfg_item); + } + } + len = strlen(buffer); + if (len) { + write_file(get_wpas_conf_file(), buffer, len); + } + + memset(buffer, 0 ,sizeof(buffer)); + sprintf(buffer, "%s -B -t -c %s -i %s -f /var/log/supplicant.log", + get_wpas_full_exec_path(), + get_wpas_conf_file(), + get_wireless_interface()); + len = system(buffer); + sleep(2); + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + // SCAN + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "SCAN"); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + indigo_logger(LOG_LEVEL_DEBUG, "%s -> resp: %s\n", buffer, response); + sleep(10); + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; From 384f1ac19a413fc7b532de4106d7fe94a5bbb8a2 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 11 Jan 2022 16:31:46 +0800 Subject: [PATCH 12/90] ITS-2046 support test case 10507_1 --- indigo_api_callback_dut.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 98e5aea..d0d8ad3 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -1909,6 +1909,7 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet size_t resp_len; char *token = NULL; char *delimit = ";"; + char realm[S_BUFFER_LEN]; /* It may need to check whether to just scan */ memset(buffer, 0, sizeof(buffer)); @@ -1962,19 +1963,33 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet memcpy(anqp_info_id, tlv->value, tlv->len); } - token = strtok(anqp_info_id, delimit); - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, "ANQP_GET %s ", bssid); - while(token != NULL) { - for (i = 0; i < sizeof(anqp_maps)/sizeof(struct anqp_tlv_to_config_name); i++) { - if (strcmp(token, anqp_maps[i].element) == 0) { - strcat(buffer, anqp_maps[i].config); - } + indigo_logger(LOG_LEVEL_DEBUG, "anqp_info_id: %s\n", anqp_info_id); //remove me + + if (strcmp(anqp_info_id, "NAIHomeRealm") == 0) { + /* TLV: REALM */ + memset(realm, 0, sizeof(realm)); + tlv = find_wrapper_tlv_by_id(req, TLV_REALM); + if (tlv) { + memcpy(realm, tlv->value, tlv->len); + sprintf(buffer, "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s", bssid, realm); + } else { + goto done; } + } else { + token = strtok(anqp_info_id, delimit); + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "ANQP_GET %s ", bssid); + while(token != NULL) { + for (i = 0; i < sizeof(anqp_maps)/sizeof(struct anqp_tlv_to_config_name); i++) { + if (strcmp(token, anqp_maps[i].element) == 0) { + strcat(buffer, anqp_maps[i].config); + } + } - token = strtok(NULL, delimit); - if (token != NULL) { - strcat(buffer, ","); + token = strtok(NULL, delimit); + if (token != NULL) { + strcat(buffer, ","); + } } } From 4ed9093148fb84559777a8bc1118abfc8de70094 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 11 Jan 2022 17:40:01 +0800 Subject: [PATCH 13/90] ITS-2046 Remove debug codes --- indigo_api_callback_dut.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index d0d8ad3..c4059d7 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -1963,8 +1963,6 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet memcpy(anqp_info_id, tlv->value, tlv->len); } - indigo_logger(LOG_LEVEL_DEBUG, "anqp_info_id: %s\n", anqp_info_id); //remove me - if (strcmp(anqp_info_id, "NAIHomeRealm") == 0) { /* TLV: REALM */ memset(realm, 0, sizeof(realm)); From a165f5bd19789ba4732f92928d155f015d87a6d6 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Mon, 17 Jan 2022 14:41:01 +0800 Subject: [PATCH 14/90] ITS-1965: Add P2P GET_INTENT_VALUE API --- indigo_api.c | 1 + indigo_api.h | 2 ++ indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 20 ++++++++++++++++++++ 4 files changed, 24 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index d69bbc9..e533c91 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -56,6 +56,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_ADD_GROUP, "P2P_ADD_GROUP", NULL, NULL }, { API_P2P_START_WPS, "P2P_START_WPS", NULL, NULL }, { API_P2P_CONNECT, "P2P_CONNECT", NULL, NULL }, + { API_P2P_GET_INTENT_VALUE, "P2P_GET_INTENT_VALUE", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index 3bdba72..395bc22 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -71,6 +71,7 @@ struct indigo_api { #define API_STA_HS2_ASSOCIATE 0x2012 #define API_STA_ADD_CREDENTIAL 0x2013 #define API_STA_SCAN 0x2014 +#define API_P2P_GET_INTENT_VALUE 0x2015 #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -257,6 +258,7 @@ struct indigo_api { #define TLV_TEST_PLATFORM_APP_VERSION 0xa008 #define TLV_LOOP_BACK_SERVER_PORT 0xa009 #define TLV_WSC_PIN_CODE 0xa00a +#define TLV_P2P_INTENT_VALUE 0xa00b /* TLV Value */ #define DUT_TYPE_STAUT 0x01 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 1becd73..47f21ee 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -261,4 +261,5 @@ static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); #endif // __INDIGO_API_CALLBACK diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 98e5aea..1231897 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -70,6 +70,7 @@ void register_apis() { register_api(API_P2P_ADD_GROUP, NULL, add_group_p2p_handler); register_api(API_P2P_START_WPS, NULL, start_wps_p2p_handler); register_api(API_P2P_CONNECT, NULL, connect_p2p_handler); + register_api(API_P2P_GET_INTENT_VALUE, NULL, get_intent_value_p2p_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -2556,3 +2557,22 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper } return 0; } + + +static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_OK; + char *message = TLV_VALUE_OK; + char response[S_BUFFER_LEN]; + + memset(response, 0, sizeof(response)); + snprintf(response, sizeof(response), "%d", P2P_GO_INTENT); + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (status == TLV_VALUE_STATUS_OK) { + fill_wrapper_tlv_bytes(resp, TLV_P2P_INTENT_VALUE, strlen(response), response); + } + return 0; +} From 2b66b9b2596464d486f5dcfffaf26ca41c3a665d Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 19 Jan 2022 14:59:09 +0800 Subject: [PATCH 15/90] ITS-2047 add test case 10508_1 --- hs2_profile.h | 7 ++++--- indigo_api.c | 1 + indigo_api.h | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index 5688a97..6922371 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -80,9 +80,9 @@ const char * hs20_conn_capab[] = { const char * operating_class_indication[] = { "", - "", - "", - "", + "hs20_operating_class=51\n", + "hs20_operating_class=73\n", + "hs20_operating_class=5173\n", }; const char * osu_providers_list[] = { @@ -133,6 +133,7 @@ struct tlv_to_profile hs2_profile[] = { { TLV_VENUE_URL, venue_url, ARRAY_SIZE(venue_url) }, { TLV_BSSLOAD_ENABLE, venue_url, ARRAY_SIZE(venue_url) }, { TLV_OPERATOR_ICON_METADATA, operator_icon_metadata, ARRAY_SIZE(operator_icon_metadata) }, + { TLV_HS20_OPERATING_CLASS_INDICATION, operating_class_indication, ARRAY_SIZE(operating_class_indication) }, }; struct tlv_to_profile* find_tlv_hs2_profile(int tlv_id) { diff --git a/indigo_api.c b/indigo_api.c index e533c91..2053e54 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -232,6 +232,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_PIN_METHOD, "PIN_METHOD" }, { TLV_PIN_CODE, "PIN_CODE" }, { TLV_P2P_CONN_TYPE, "P2P_CONN_TYPE" }, + { TLV_HS20_OPERATING_CLASS_INDICATION, "HS20_OPERATING_CLASS_INDICATION"}, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 395bc22..8a18418 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -244,6 +244,7 @@ struct indigo_api { #define TLV_PIN_METHOD 0x00c8 #define TLV_PIN_CODE 0x00c9 #define TLV_P2P_CONN_TYPE 0x00ca +#define TLV_HS20_OPERATING_CLASS_INDICATION 0x00cb // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT From c8127beb206b445886e2261f3b67422d26dfefa8 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Thu, 20 Jan 2022 18:39:35 +0800 Subject: [PATCH 16/90] Add APIs: - start aput wps - get sta credntails Add the logic for WSC_OOB(# Use pre-dfined OOB setting. Might refine later) Add the logig check for new reset type "MIDDLE" which is used for WPS reconfiguration. --- indigo_api.c | 4 ++ indigo_api.h | 10 +++++ indigo_api_callback.h | 3 ++ indigo_api_callback_dut.c | 95 ++++++++++++++++++++++++++++++++++++++- indigo_api_callback_tp.c | 95 ++++++++++++++++++++++++++++++++++++++- vendor_specific.h | 40 +++++++++++++++++ vendor_specific_dut.c | 53 ++++++++++++++++++++++ 7 files changed, 298 insertions(+), 2 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 2053e54..815e3d9 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -36,6 +36,7 @@ struct indigo_api indigo_api_list[] = { { API_AP_SET_PARAM, "API_AP_SET_PARAM", NULL, NULL }, { API_AP_SEND_BTM_REQ, "API_AP_SEND_BTM_REQ", NULL, NULL }, { API_AP_SEND_ARP_MSGS, "API_AP_SEND_ARP_MSGS", NULL, NULL }, + { API_AP_START_WPS, "AP_START_WPS", NULL, NULL }, /* Station specific */ { API_STA_START_UP, "STA_START_UP", NULL, NULL }, { API_STA_ASSOCIATE, "STA_ASSOCIATE", NULL, NULL }, @@ -71,6 +72,7 @@ struct indigo_api indigo_api_list[] = { { API_START_DHCP, "START_DHCP", NULL, NULL }, { API_STOP_DHCP, "STOP_DHCP", NULL, NULL }, { API_GET_WSC_PIN, "GET_WSC_PIN", NULL, NULL }, + { API_GET_WSC_CRED, "GET_WSC_CRED", NULL, NULL }, }; /* Structure to declare the TLV list */ @@ -233,6 +235,8 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_PIN_CODE, "PIN_CODE" }, { TLV_P2P_CONN_TYPE, "P2P_CONN_TYPE" }, { TLV_HS20_OPERATING_CLASS_INDICATION, "HS20_OPERATING_CLASS_INDICATION"}, + { TLV_WSC_OOB, "WSC_OOB" }, + { TLV_UPDATE_CONFIG, "UPDATE_CONFIG" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 8a18418..4807a97 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -49,6 +49,7 @@ struct indigo_api { #define API_AP_SET_PARAM 0x1005 #define API_AP_SEND_BTM_REQ 0x1006 #define API_AP_SEND_ARP_MSGS 0x1007 +#define API_AP_START_WPS 0x1008 #define API_STA_ASSOCIATE 0x2000 #define API_STA_CONFIGURE 0x2001 @@ -86,6 +87,7 @@ struct indigo_api { #define API_START_DHCP 0x500a #define API_STOP_DHCP 0x500b #define API_GET_WSC_PIN 0x500c +#define API_GET_WSC_CRED 0x500d /* TLV definition */ #define TLV_SSID 0x0001 @@ -245,6 +247,8 @@ struct indigo_api { #define TLV_PIN_CODE 0x00c9 #define TLV_P2P_CONN_TYPE 0x00ca #define TLV_HS20_OPERATING_CLASS_INDICATION 0x00cb +#define TLV_WSC_OOB 0x00cc +#define TLV_UPDATE_CONFIG 0x00cd // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT @@ -260,6 +264,9 @@ struct indigo_api { #define TLV_LOOP_BACK_SERVER_PORT 0xa009 #define TLV_WSC_PIN_CODE 0xa00a #define TLV_P2P_INTENT_VALUE 0xa00b +#define TLV_WSC_SSID 0xa00c +#define TLV_WSC_WPA_KEY_MGMT 0xa00d +#define TLV_WSC_WPA_PASSPHRASS 0xa00e /* TLV Value */ #define DUT_TYPE_STAUT 0x01 @@ -325,8 +332,11 @@ struct indigo_api { #define TLV_VALUE_P2P_START_WPS_NOT_OK "Failed to start WPS on GO interface" #define TLV_VALUE_P2P_CONNECT_NOT_OK "Failed to trigger P2P connect" +#define TLV_VALUE_AP_START_WPS_NOT_OK "Failed to start WPS on AP interface" + #define RESET_TYPE_INIT 0x01 #define RESET_TYPE_TEARDOWN 0x02 +#define RESET_TYPE_MIDDLE 0x03 #define WPA_CTRL_OK "OK" #define WPA_CTRL_FAIL "FAIL" diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 47f21ee..9ddb56c 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -195,6 +195,7 @@ struct tlv_to_config_name wpas_global_maps[] = { { TLV_HESSID, "hessid", 0 }, { TLV_ACCESS_NETWORK_TYPE, "access_network_type", 0 }, { TLV_FREQ_LIST, "freq_list", 0 }, + { TLV_UPDATE_CONFIG, "update_config", 0 }, }; struct tlv_to_config_name* find_wpas_global_config_name(int tlv_id) { @@ -231,6 +232,7 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* AP */ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); @@ -240,6 +242,7 @@ static int set_ap_parameter_handler(struct packet_wrapper *req, struct packet_wr static int send_ap_btm_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int trigger_ap_channel_switch(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_ap_arp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* STA */ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int configure_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 0117bb5..d70b90f 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -51,6 +51,7 @@ void register_apis() { register_api(API_AP_SEND_DISCONNECT, NULL, send_ap_disconnect_handler); register_api(API_AP_SET_PARAM , NULL, set_ap_parameter_handler); register_api(API_AP_SEND_BTM_REQ, NULL, send_ap_btm_handler); + register_api(API_AP_START_WPS, NULL, start_wps_ap_handler); /* STA */ register_api(API_STA_ASSOCIATE, NULL, associate_sta_handler); register_api(API_STA_CONFIGURE, NULL, configure_sta_handler); @@ -356,6 +357,41 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ continue; } + /* wps settings */ + if (tlv->id == TLV_WSC_OOB) { + int j; + + memcpy(buffer, tlv->value, tlv->len); + wps_setting *s = get_vendor_wps_settings(atoi(buffer)); + if (atoi(buffer)) { + /* Use OOB */ + for (j = 0; j < SETTING_NUM; j++) { + memset(cfg_item, 0, sizeof(cfg_item)); + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + strcat(output, cfg_item); + } + } else { + /* NOT use OOB: Configure manually. */ + for (j = 0; j < SETTING_NUM; j++) { + memset(cfg_item, 0, sizeof(cfg_item)); + if (s[j].attr & WPS_COMMON) { + if (s[j].wkey == WPS_OOB_STATE) { + if (s[j].wkey == WPS_OOB_NOT_CONFIGURED) { + /* Change wps oob state to Configured. */ + sprintf(cfg_item, "%s=%s\n", s[j].wkey, WPS_OOB_CONFIGURED); + } else { + indigo_logger(LOG_LEVEL_ERROR, "DUT OOB state Mismatch: 0x%04x", s[j].wkey); + continue; + } + } else { + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + } + strcat(output, cfg_item); + } + } + } + } + cfg = find_tlv_config(tlv->id); if (!cfg) { indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id); @@ -2538,6 +2574,14 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper if (role == DUT_TYPE_APUT) { // TODO + sprintf(buffer, "WPS_AP_PIN get"); + w = wpa_ctrl_open(get_hapd_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to hostapd"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } } else if (role == DUT_TYPE_STAUT || role == DUT_TYPE_P2PUT) { sprintf(buffer, "WPS_PIN get"); w = wpa_ctrl_open(get_wpas_ctrl_path()); @@ -2571,7 +2615,6 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper return 0; } - static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_OK; char *message = TLV_VALUE_OK; @@ -2580,6 +2623,7 @@ static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packe memset(response, 0, sizeof(response)); snprintf(response, sizeof(response), "%d", P2P_GO_INTENT); + done: fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); @@ -2589,3 +2633,52 @@ static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packe } return 0; } + +static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + char pin_code[64], if_name[32]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_AP_START_WPS_NOT_OK; + struct tlv_hdr *tlv = NULL; + + memset(buffer, 0, sizeof(buffer)); + tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); + if (tlv) { + memset(pin_code, 0, sizeof(pin_code)); + memcpy(pin_code, tlv->value, tlv->len); + sprintf(buffer, "WPS_PIN any %s", pin_code); + } else { + sprintf(buffer, "WPS_PBC"); + } + + /* Open hostapd UDS socket */ + w = wpa_ctrl_open(get_hapd_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to hostapd"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(response, 0, sizeof(response)); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + if (strncmp(response, WPA_CTRL_FAIL, strlen(WPA_CTRL_FAIL)) == 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command(%s).", buffer); + goto done; + } + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 360c068..05e0f95 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -48,6 +48,7 @@ void register_apis() { register_api(API_ASSIGN_STATIC_IP, NULL, assign_static_ip_handler); register_api(API_START_DHCP, NULL, start_dhcp_handler); register_api(API_STOP_DHCP, NULL, stop_dhcp_handler); + register_api(API_GET_WSC_CRED, NULL, get_wsc_cred_handler); /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); @@ -946,10 +947,11 @@ static int send_ap_arp_handler(struct packet_wrapper *req, struct packet_wrapper static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len = 0, reset = 0; - char buffer[S_BUFFER_LEN], reset_type[16]; + char buffer[S_BUFFER_LEN*2], reset_type[16], buffer1[S_BUFFER_LEN], buffer2[S_BUFFER_LEN]; char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; char *message = NULL; struct tlv_hdr *tlv = NULL; + static int middle_reset_count = 0; /* TLV: RESET_TYPE */ tlv = find_wrapper_tlv_by_id(req, TLV_RESET_TYPE); @@ -988,6 +990,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r sta_hw_config.chwidth = CHWIDTH_AUTO; set_channel_width(); } + middle_reset_count = 0; } if (reset == RESET_TYPE_INIT) { @@ -1001,6 +1004,40 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r system(buffer); } + if (reset == RESET_TYPE_MIDDLE) { + middle_reset_count++; + /* Send intermediate supplicant conf and log to Tool */ + if (tool_addr != NULL) { + /* wpas conf file rename and send */ + memset(buffer, 0, sizeof(buffer)); + memset(buffer1, 0, sizeof(buffer1)); + snprintf(buffer1, sizeof(buffer1), "%s.m%d", get_wpas_conf_file(), middle_reset_count); + snprintf(buffer, sizeof(buffer), "mv %s %s", get_wpas_conf_file(), buffer1); + system(buffer); + http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, WPAS_UPLOAD_API, buffer1); + sleep(1); + /* wpas log file rename and send */ + memset(buffer, 0, sizeof(buffer)); + memset(buffer2, 0, sizeof(buffer2)); + snprintf(buffer2, sizeof(buffer2), "%s.m%d", WPAS_LOG_FILE, middle_reset_count); + snprintf(buffer, sizeof(buffer), "mv %s %s", WPAS_LOG_FILE, buffer2); + system(buffer); + http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, WPAS_UPLOAD_API, buffer2); + sleep(1); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Can't get tool IP address"); + } + len = unlink(buffer1); + if (len) { + indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove wpa_supplicant.conf"); + } + + /* clean the log */ + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "rm -rf %s >/dev/null 2>/dev/null", buffer2); + system(buffer); + } + len = reset_interface_ip(get_wireless_interface()); if (len) { indigo_logger(LOG_LEVEL_DEBUG, "Failed to free IP address"); @@ -1663,3 +1700,59 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * return 0; } + +static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_NOT_OK; + char *pos = NULL, *data = NULL; + int i, len, ret = -1, count = 0; + struct _cfg_cred { + char *key; + char *tok; + char val[S_BUFFER_LEN]; + unsigned short tid; + } cfg_creds[] = { + {"ssid", "ssid=", {0}, TLV_WSC_SSID}, + {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"key_mgmt", "key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} + }; + + data = read_file(get_wpas_conf_file()); + if (!data) + indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", get_wpas_conf_file()); + + count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); + for (i = 0; i < count; i++) { + pos = strstr(data, cfg_creds[i].tok); + if (pos) { + pos += strlen(cfg_creds[i].tok); + if (*pos == '"') { + /* Handle with the format ssid/key="xxxxxxxx" */ + pos++; + len = strchr(pos, '"') - pos; + } else { + /* Handle with the format key_mgmt=yyyyyyyy */ + len = strchr(pos, '\n') - pos; + } + memcpy(cfg_creds[i].val, pos, len); + indigo_logger(LOG_LEVEL_INFO, "Get %s: %s\n", cfg_creds[i].key, cfg_creds[i].val); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Cannot find the setting: %s\n", cfg_creds[i].key); + goto done; + } + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + free(data); + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (status == TLV_VALUE_STATUS_OK) { + for (i = 0; i < count; i++) { + fill_wrapper_tlv_bytes(resp, cfg_creds[i].tid, strlen(cfg_creds[i].val), cfg_creds[i].val); + } + } + return 0; +} diff --git a/vendor_specific.h b/vendor_specific.h index 1da4e0a..c854428 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -91,6 +91,46 @@ void vendor_init(); void vendor_deinit(); void vendor_device_reset(); +/** + * wps settings retrieved with vendor-specific operations. + */ + +#define WPS_OOB_SSID "ssid" +#define WPS_OOB_AUTH_TYPE "wpa_key_mgmt" +#define WPS_OOB_ENC_TYPE "wpa_pairwise" +#define WPS_OOB_PSK "wpa_passphrase" +#define WPS_OOB_WPA_VER "wpa" +#define WPS_OOB_AP_PIN "ap_pin" +#define WPS_OOB_STATE "wps_state" +#define WPS_CONFIG "config_methods" +#define WPS_DEV_NAME "device_name" +#define WPS_DEV_TYPE "device_type" +#define WPS_MANUFACTURER "manufacturer" +#define WPS_MODEL_NAME "model_name" +#define WPS_MODEL_NUMBER "model_number" +#define WPS_SERIAL_NUMBER "serial_number" + +#define WPS_OOB_NOT_CONFIGURED "1" +#define WPS_OOB_CONFIGURED "2" + +#define SUPPORTED_CONF_METHOD "keypad push_button phsical_push_button virtual_push_button display physical_display virtual_display" + +enum param_attr { + WPS_COMMON = 0x0001, + WPS_OOB_ONLY = 0x0010 +}; + +#define GROUP_NUM (2) +#define SETTING_NUM (14) + +typedef struct _wps_setting { + /* key-value for each setting pair */ + char *wkey; + char *value; + enum param_attr attr; +} wps_setting; + + #ifdef _TEST_PLATFORM_ /** diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index a8a056e..39f1b95 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -379,3 +379,56 @@ void stop_dhcp_client() { system("killall dhclient 1>/dev/null 2>/dev/null"); } + +wps_setting wps_settings[GROUP_NUM][SETTING_NUM] = { + { + /* + * WPS OOB required. (Not-Configured OOB state) + * */ + { WPS_OOB_SSID, "Openwrt_ssid", WPS_OOB_ONLY }, /* ap broadcasts ssid */ + { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ + { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ + { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ + { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + /* + * General + * */ + { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ + { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "Openwrt-AP", WPS_COMMON }, /* device name */ + { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ + { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "Openwrt-AP", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Openwrt-AP", WPS_COMMON }, /* model number */ + { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ + }, + { + /* + * WPS OOB required. (Configured OOB state) + * */ + { WPS_OOB_SSID, "Openwrt_ssid", WPS_OOB_ONLY }, /* ap broadcasts ssid */ + { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ + { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ + { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ + { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + /* + * General + * */ + { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ + { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_COMMON }, /* wps oob state */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "Openwrt-AP", WPS_COMMON }, /* device name */ + { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ + { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "Openwrt-AP", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Openwrt-AP", WPS_COMMON }, /* model number */ + { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ + }, +}; + +wps_setting* get_vendor_wps_settings(int oob_flag) +{ + return wps_settings[0]; +} + From 90a374063c655ba2168373460d554ea7a5944efc Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 21 Jan 2022 10:27:20 +0800 Subject: [PATCH 17/90] ITS-2045 Support test case 10506_1 --- hs2_profile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hs2_profile.h b/hs2_profile.h index 6922371..5b7d71a 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -87,7 +87,7 @@ const char * operating_class_indication[] = { const char * osu_providers_list[] = { "", - "", + "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\nosu_friendly_name=eng:SP Red Test Only\nosu_friendly_name=kor:SP 빨강 테스트 전용\nosu_method_list=1\nosu_service_desc=eng:Free service for test purpose\nosu_service_desc=kor:테스트 목적으로 무료 서비스\n", "", "", "", From 38ff4858324a15e1a2119e4a6913d267dfa06d2a Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 21 Jan 2022 11:36:03 +0800 Subject: [PATCH 18/90] Chnage the reset type from MILLDE to RECONFIGURE --- indigo_api.h | 2 +- indigo_api_callback_tp.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/indigo_api.h b/indigo_api.h index 4807a97..8689f2a 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -336,7 +336,7 @@ struct indigo_api { #define RESET_TYPE_INIT 0x01 #define RESET_TYPE_TEARDOWN 0x02 -#define RESET_TYPE_MIDDLE 0x03 +#define RESET_TYPE_RECONFIGURE 0x03 #define WPA_CTRL_OK "OK" #define WPA_CTRL_FAIL "FAIL" diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 05e0f95..fa92085 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -951,7 +951,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; char *message = NULL; struct tlv_hdr *tlv = NULL; - static int middle_reset_count = 0; + static int reconf_count = 0; /* TLV: RESET_TYPE */ tlv = find_wrapper_tlv_by_id(req, TLV_RESET_TYPE); @@ -990,7 +990,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r sta_hw_config.chwidth = CHWIDTH_AUTO; set_channel_width(); } - middle_reset_count = 0; + reconf_count = 0; } if (reset == RESET_TYPE_INIT) { @@ -1004,14 +1004,14 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r system(buffer); } - if (reset == RESET_TYPE_MIDDLE) { - middle_reset_count++; + if (reset == RESET_TYPE_RECONFIGURE) { + reconf_count++; /* Send intermediate supplicant conf and log to Tool */ if (tool_addr != NULL) { /* wpas conf file rename and send */ memset(buffer, 0, sizeof(buffer)); memset(buffer1, 0, sizeof(buffer1)); - snprintf(buffer1, sizeof(buffer1), "%s.m%d", get_wpas_conf_file(), middle_reset_count); + snprintf(buffer1, sizeof(buffer1), "%s.m%d", get_wpas_conf_file(), reconf_count); snprintf(buffer, sizeof(buffer), "mv %s %s", get_wpas_conf_file(), buffer1); system(buffer); http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, WPAS_UPLOAD_API, buffer1); @@ -1019,7 +1019,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r /* wpas log file rename and send */ memset(buffer, 0, sizeof(buffer)); memset(buffer2, 0, sizeof(buffer2)); - snprintf(buffer2, sizeof(buffer2), "%s.m%d", WPAS_LOG_FILE, middle_reset_count); + snprintf(buffer2, sizeof(buffer2), "%s.m%d", WPAS_LOG_FILE, reconf_count); snprintf(buffer, sizeof(buffer), "mv %s %s", WPAS_LOG_FILE, buffer2); system(buffer); http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, WPAS_UPLOAD_API, buffer2); @@ -1029,7 +1029,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r } len = unlink(buffer1); if (len) { - indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove wpa_supplicant.conf"); + indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove %s", buffer1); } /* clean the log */ From 14c4a643467fe603eefe3a27e7ae3060f3a6c2c8 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Sat, 22 Jan 2022 20:19:55 +0800 Subject: [PATCH 19/90] Add function prototype to avoid compile warning. --- vendor_specific.h | 1 + 1 file changed, 1 insertion(+) diff --git a/vendor_specific.h b/vendor_specific.h index c854428..df043fc 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -169,4 +169,5 @@ void start_dhcp_server(char *if_name, char *ip_addr); void stop_dhcp_server(); void start_dhcp_client(char *if_name); void stop_dhcp_client(); +wps_setting* get_vendor_wps_settings(int oob_flag); #endif From e1523786e75fe0fad26643b13794daad82283852 Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Mon, 24 Jan 2022 17:18:23 +0800 Subject: [PATCH 20/90] add hs20_deauth_req_timeout config for WNM Deauth Imminent testcase --- hs2_profile.h | 2 +- indigo_api.h | 2 +- indigo_api_callback_dut.c | 1 + indigo_api_callback_tp.c | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index 5b7d71a..567f174 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -131,7 +131,7 @@ struct tlv_to_profile hs2_profile[] = { { TLV_OSU_PROVIDERS_LIST, osu_providers_list, ARRAY_SIZE(osu_providers_list) }, { TLV_OSU_PROVIDERS_NAI_LIST, osu_providers_nai_list, ARRAY_SIZE(osu_providers_nai_list) }, { TLV_VENUE_URL, venue_url, ARRAY_SIZE(venue_url) }, - { TLV_BSSLOAD_ENABLE, venue_url, ARRAY_SIZE(venue_url) }, + { TLV_BSSLOAD_ENABLE, bss_load, ARRAY_SIZE(bss_load) }, { TLV_OPERATOR_ICON_METADATA, operator_icon_metadata, ARRAY_SIZE(operator_icon_metadata) }, { TLV_HS20_OPERATING_CLASS_INDICATION, operating_class_indication, ARRAY_SIZE(operating_class_indication) }, }; diff --git a/indigo_api.h b/indigo_api.h index 8689f2a..b1b3f19 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -207,7 +207,7 @@ struct indigo_api { #define TLV_SKIP_6G_BSS_SECURITY_CHECK 0x00a1 #define TLV_OWE_TRANSITION_BSS_IDENTIFIER 0x00a2 #define TLV_FREQ_LIST 0x00a3 -#define TLV_SHORT_SSID 0x00a4 +#define TLV_BSSID_FILTER_LIST 0x00a4 #define TLV_HE_BEACON_TX_SU_PPDU 0x00a5 #define TLV_HE_6G_ONLY 0x00a6 #define TLV_HE_UNSOL_PR_RESP_CADENCE 0x00a7 diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index d70b90f..32545f3 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -673,6 +673,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, "manage_p2p=1\n"); strcat(output, "allow_cross_connection=0\n"); strcat(output, "bss_load_update_period=100\n"); + strcat(output, "hs20_deauth_req_timeout=3\n"); } /* vendor specific config, not via hostapd */ diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index fa92085..13984c2 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -441,6 +441,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, "manage_p2p=1\n"); strcat(output, "allow_cross_connection=0\n"); strcat(output, "bss_load_update_period=100\n"); + strcat(output, "hs20_deauth_req_timeout=3\n"); } #ifdef _WTS_OPENWRT_ From 9c1806842d9db243e62f8c300cb50dd22f9982c6 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 25 Jan 2022 12:53:19 +0800 Subject: [PATCH 21/90] ITS-2077 Support Operator Icons --- hs2_profile.h | 15 ++++++++++++++- indigo_api_callback_dut.c | 6 ++++++ indigo_api_callback_tp.c | 6 ++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/hs2_profile.h b/hs2_profile.h index 5b7d71a..8ae91b1 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -117,7 +117,12 @@ const char * venue_url[] = { const char * operator_icon_metadata[] = { "", - "", + "operator_icon=icon_red_eng\n", +}; + +// ::::: +const char * hs20_icon[] = { + "hs20_icon=160:76:eng:image/png:icon_red_eng:/overlay/icon_red_eng.png\n", }; struct tlv_to_profile hs2_profile[] = { @@ -146,4 +151,12 @@ struct tlv_to_profile* find_tlv_hs2_profile(int tlv_id) { return NULL; } +void attach_hs20_icons(char * buffer) { + int i; + for (i = 0; i < ARRAY_SIZE(hs20_icon); i++) { + strcat(buffer, hs20_icon[i]); + } + return; +} + #endif // _HS2_PROFILE \ No newline at end of file diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index d70b90f..8faa4ed 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -277,6 +277,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int is_6g_only = 0, unsol_pr_resp_interval = 0; struct tlv_to_profile *profile = NULL; int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); + int hs20_icons_attached = 0; #if HOSTAPD_SUPPORT_MBSSID if (wlanp->mbssid_enable && !wlanp->transmitter) @@ -346,6 +347,11 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ char *hs2_config = 0; memcpy(buffer, tlv->value, tlv->len); + if (((tlv->id == TLV_OSU_PROVIDERS_LIST) || (tlv->id == TLV_OPERATOR_ICON_METADATA)) && (!hs20_icons_attached)) { + attach_hs20_icons(output); + hs20_icons_attached = 1; + } + if (atoi(buffer) > profile->size) { indigo_logger(LOG_LEVEL_ERROR, "profile index out of bound!: %d, array_size:%d", atoi(buffer), profile->size); } else { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index fa92085..b249b15 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -241,6 +241,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int has_owe = 0, enable_hs20 = 0; struct tlv_to_profile *profile = NULL; int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); + int hs20_icons_attached = 0; #if HOSTAPD_SUPPORT_MBSSID @@ -296,6 +297,11 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ char *hs2_config = 0; memcpy(buffer, tlv->value, tlv->len); + if (((tlv->id == TLV_OSU_PROVIDERS_LIST) || (tlv->id == TLV_OPERATOR_ICON_METADATA)) && (!hs20_icons_attached)) { + attach_hs20_icons(output); + hs20_icons_attached = 1; + } + if (atoi(buffer) > profile->size) { indigo_logger(LOG_LEVEL_ERROR, "profile index out of bound!: %d, array_size:%d", atoi(buffer), profile->size); } else { From 20de7d9eed301bc99a372c6afde5beef5473dc18 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Wed, 26 Jan 2022 12:38:43 +0800 Subject: [PATCH 22/90] 1. Refined WPS settings on both APUT and STAUT cases. 2. Added API for STAUT start 3. Added basic WPS APIs used for STAUT cases. --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 171 ++++++++++++++++++++++++++++++++++++-- indigo_api_callback_tp.c | 57 ++++++++++++- vendor_specific.h | 10 ++- vendor_specific_dut.c | 34 +++++--- vendor_specific_tp.c | 63 ++++++++++++++ 8 files changed, 317 insertions(+), 21 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 815e3d9..1dd1e3d 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -58,6 +58,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_START_WPS, "P2P_START_WPS", NULL, NULL }, { API_P2P_CONNECT, "P2P_CONNECT", NULL, NULL }, { API_P2P_GET_INTENT_VALUE, "P2P_GET_INTENT_VALUE", NULL, NULL }, + { API_STA_START_WPS, "STA_START_WPS", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index 8689f2a..14c1d2b 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -73,6 +73,7 @@ struct indigo_api { #define API_STA_ADD_CREDENTIAL 0x2013 #define API_STA_SCAN 0x2014 #define API_P2P_GET_INTENT_VALUE 0x2015 +#define API_STA_START_WPS 0x2016 #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 9ddb56c..8437ba3 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -257,6 +257,7 @@ static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_w static int set_sta_phy_mode_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_channel_width_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* P2P */ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index d70b90f..3dfd23b 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -56,12 +56,14 @@ void register_apis() { register_api(API_STA_ASSOCIATE, NULL, associate_sta_handler); register_api(API_STA_CONFIGURE, NULL, configure_sta_handler); register_api(API_STA_DISCONNECT, NULL, stop_sta_handler); + register_api(API_STA_START_UP, NULL, start_up_sta_handler); register_api(API_STA_SEND_DISCONNECT, NULL, send_sta_disconnect_handler); register_api(API_STA_REASSOCIATE, NULL, send_sta_reconnect_handler); register_api(API_STA_SET_PARAM, NULL, set_sta_parameter_handler); register_api(API_STA_SEND_BTM_QUERY, NULL, send_sta_btm_query_handler); register_api(API_STA_SEND_ANQP_QUERY, NULL, send_sta_anqp_query_handler); register_api(API_STA_SCAN, NULL, send_sta_scan_handler); + register_api(API_STA_START_WPS, NULL, start_wps_sta_handler); /* TODO: Add the handlers */ register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL); register_api(API_STA_POWER_SAVE, NULL, NULL); @@ -362,25 +364,26 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int j; memcpy(buffer, tlv->value, tlv->len); - wps_setting *s = get_vendor_wps_settings(atoi(buffer)); + wps_setting *s = get_vendor_wps_settings(WPS_AP); if (atoi(buffer)) { /* Use OOB */ - for (j = 0; j < SETTING_NUM; j++) { + for (j = 0; j < AP_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); strcat(output, cfg_item); } } else { /* NOT use OOB: Configure manually. */ - for (j = 0; j < SETTING_NUM; j++) { + for (j = 0; j < AP_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); if (s[j].attr & WPS_COMMON) { - if (s[j].wkey == WPS_OOB_STATE) { - if (s[j].wkey == WPS_OOB_NOT_CONFIGURED) { + if (strlen(s[j].wkey) == strlen(WPS_OOB_STATE) && + !(memcmp(s[j].wkey, WPS_OOB_STATE, strlen(WPS_OOB_STATE)))) { + if (atoi(s[j].value) == atoi(WPS_OOB_NOT_CONFIGURED)) { /* Change wps oob state to Configured. */ sprintf(cfg_item, "%s=%s\n", s[j].wkey, WPS_OOB_CONFIGURED); } else { - indigo_logger(LOG_LEVEL_ERROR, "DUT OOB state Mismatch: 0x%04x", s[j].wkey); + indigo_logger(LOG_LEVEL_ERROR, "DUT OOB state Mismatch: 0x%s", s[j].value); continue; } } else { @@ -2682,3 +2685,159 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe } return 0; } + +static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; + char buffer[BUFFER_LEN], response[1024], log_level[TLV_VALUE_SIZE], value[TLV_VALUE_SIZE]; + char ssid[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; + int len, status = TLV_VALUE_STATUS_NOT_OK, i, ssid_len = 0; + size_t resp_len; + char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; + struct tlv_hdr *tlv = NULL; + struct tlv_to_config_name* cfg = NULL; +#ifdef _OPENWRT_ +#else + system("rfkill unblock wlan"); + sleep(1); +#endif + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + system(buffer); + sleep(3); + + tlv = find_wrapper_tlv_by_id(req, TLV_SSID); + memset(ssid, 0, sizeof(ssid)); + if (tlv) { + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + ssid_len = sprintf(ssid, "network={\nssid=\"%s\"\nscan_ssid=1\nkey_mgmt=NONE\n}\n", value); + } + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT); + + for (i = 0; i < req->tlv_num; i++) { + cfg = find_wpas_global_config_name(req->tlv[i]->id); + if (cfg) { + memset(value, 0, sizeof(value)); + memcpy(value, req->tlv[i]->value, req->tlv[i]->len); + sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); + strcat(buffer, cfg_item); + } + } + + /* wps settings */ + tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); + if (tlv) { + int j; + + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + + /* To get STA wps vendor info */ + wps_setting *s = get_vendor_wps_settings(WPS_STA); + if (atoi(value)) { + for (j = 0; j < STA_SETTING_NUM; j++) { + memset(cfg_item, 0, sizeof(cfg_item)); + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + strcat(buffer, cfg_item); + } + } + } + + if (ssid_len) { + strcat(buffer, ssid); + } + len = strlen(buffer); + + if (len) { + write_file(get_wpas_conf_file(), buffer, len); + } + + /* TLV: DEBUG_LEVEL */ + tlv = find_wrapper_tlv_by_id(req, TLV_DEBUG_LEVEL); + memset(log_level, 0, sizeof(log_level)); + if (tlv) { + memcpy(log_level, tlv->value, tlv->len); + } + + if (strlen(log_level)) { + set_wpas_debug_level(get_debug_level(atoi(log_level))); + } + + /* Start WPA supplicant */ + memset(buffer, 0 ,sizeof(buffer)); + sprintf(buffer, "%s -B -t -c %s %s -i %s -f %s", + get_wpas_full_exec_path(), + get_wpas_conf_file(), + get_wpas_debug_arguments(), + get_wireless_interface(), + WPAS_LOG_FILE); + len = system(buffer); + sleep(2); + + len = pipe_command(buffer, sizeof(buffer), "/bin/pidof", parameter); + if (len) { + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_WPA_S_START_UP_OK; + } else { + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_START_UP_NOT_OK; + } + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + return 0; +} + +static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + char pin_code[64], if_name[32]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_AP_START_WPS_NOT_OK; + struct tlv_hdr *tlv = NULL; + + memset(buffer, 0, sizeof(buffer)); + tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); + if (tlv) { + memset(pin_code, 0, sizeof(pin_code)); + memcpy(pin_code, tlv->value, tlv->len); + sprintf(buffer, "WPS_PIN any %s", pin_code); + } else { + sprintf(buffer, "WPS_PBC"); + } + + /* Open hostapd UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(response, 0, sizeof(response)); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + if (strncmp(response, WPA_CTRL_FAIL, strlen(WPA_CTRL_FAIL)) == 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command(%s).", buffer); + goto done; + } + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index fa92085..6d09589 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -307,6 +307,42 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ continue; } + /* wps settings */ + if (tlv->id == TLV_WSC_OOB) { + int j; + + memcpy(buffer, tlv->value, tlv->len); + wps_setting *s = get_vendor_wps_settings(WPS_AP); + if (atoi(buffer)) { + /* Use OOB */ + for (j = 0; j < AP_SETTING_NUM; j++) { + memset(cfg_item, 0, sizeof(cfg_item)); + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + strcat(output, cfg_item); + } + } else { + /* NOT use OOB: Configure manually. */ + for (j = 0; j < AP_SETTING_NUM; j++) { + memset(cfg_item, 0, sizeof(cfg_item)); + if (s[j].attr & WPS_COMMON) { + if (strlen(s[j].wkey) == strlen(WPS_OOB_STATE) && + !(memcmp(s[j].wkey, WPS_OOB_STATE, strlen(WPS_OOB_STATE)))) { + if (atoi(s[j].value) == atoi(WPS_OOB_NOT_CONFIGURED)) { + /* Change wps oob state to Configured. */ + sprintf(cfg_item, "%s=%s\n", s[j].wkey, WPS_OOB_CONFIGURED); + } else { + indigo_logger(LOG_LEVEL_ERROR, "DUT OOB state Mismatch: 0x%s", s[j].value); + continue; + } + } else { + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + } + strcat(output, cfg_item); + } + } + } + } + cfg = find_tlv_config(tlv->id); if (!cfg) { indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id); @@ -1266,7 +1302,7 @@ static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapp static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; - char buffer[S_BUFFER_LEN], response[1024], log_level[TLV_VALUE_SIZE], value[TLV_VALUE_SIZE]; + char buffer[BUFFER_LEN], response[1024], log_level[TLV_VALUE_SIZE], value[TLV_VALUE_SIZE]; char ssid[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; int len, status = TLV_VALUE_STATUS_NOT_OK, i, ssid_len; size_t resp_len; @@ -1318,6 +1354,25 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe } } + /* wps settings */ + tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); + if (tlv) { + int j; + + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + + /* To get STA wps vendor info */ + wps_setting *s = get_vendor_wps_settings(WPS_STA); + if (atoi(value)) { + for (j = 0; j < STA_SETTING_NUM; j++) { + memset(cfg_item, 0, sizeof(cfg_item)); + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + strcat(buffer, cfg_item); + } + } + } + if (ssid_len) { strcat(buffer, ssid); } diff --git a/vendor_specific.h b/vendor_specific.h index df043fc..ba1077f 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -120,8 +120,14 @@ enum param_attr { WPS_OOB_ONLY = 0x0010 }; +enum wps_device_role { + WPS_AP, + WPS_STA +}; + #define GROUP_NUM (2) -#define SETTING_NUM (14) +#define AP_SETTING_NUM (14) +#define STA_SETTING_NUM (5) typedef struct _wps_setting { /* key-value for each setting pair */ @@ -169,5 +175,5 @@ void start_dhcp_server(char *if_name, char *ip_addr); void stop_dhcp_server(); void start_dhcp_client(char *if_name); void stop_dhcp_client(); -wps_setting* get_vendor_wps_settings(int oob_flag); +wps_setting* get_vendor_wps_settings(enum wps_device_role); #endif diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 39f1b95..e53be63 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -380,12 +380,12 @@ void stop_dhcp_client() system("killall dhclient 1>/dev/null 2>/dev/null"); } -wps_setting wps_settings[GROUP_NUM][SETTING_NUM] = { +wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { /* * WPS OOB required. (Not-Configured OOB state) * */ - { WPS_OOB_SSID, "Openwrt_ssid", WPS_OOB_ONLY }, /* ap broadcasts ssid */ + { WPS_OOB_SSID, "Openwrt-WPS-dut", WPS_OOB_ONLY }, /* ap broadcasts ssid */ { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ @@ -396,18 +396,18 @@ wps_setting wps_settings[GROUP_NUM][SETTING_NUM] = { { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ - { WPS_DEV_NAME, "Openwrt-AP", WPS_COMMON }, /* device name */ + { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ - { WPS_MODEL_NAME, "Openwrt-AP", WPS_COMMON }, /* model name */ - { WPS_MODEL_NUMBER, "Openwrt-AP", WPS_COMMON }, /* model number */ + { WPS_MODEL_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Openwrt Wireless AP-001", WPS_COMMON }, /* model number */ { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ }, { /* * WPS OOB required. (Configured OOB state) * */ - { WPS_OOB_SSID, "Openwrt_ssid", WPS_OOB_ONLY }, /* ap broadcasts ssid */ + { WPS_OOB_SSID, "Openwrt-WPS-dut", WPS_OOB_ONLY }, /* ap broadcasts ssid */ { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ @@ -418,17 +418,27 @@ wps_setting wps_settings[GROUP_NUM][SETTING_NUM] = { { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_COMMON }, /* wps oob state */ { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ - { WPS_DEV_NAME, "Openwrt-AP", WPS_COMMON }, /* device name */ + { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ - { WPS_MODEL_NAME, "Openwrt-AP", WPS_COMMON }, /* model name */ - { WPS_MODEL_NUMBER, "Openwrt-AP", WPS_COMMON }, /* model number */ + { WPS_MODEL_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Openwrt Wireless AP-001", WPS_COMMON }, /* model number */ { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ }, }; -wps_setting* get_vendor_wps_settings(int oob_flag) +wps_setting wps_settings_sta[STA_SETTING_NUM] = { + { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "Intel Wireless STA", WPS_COMMON }, /* device name */ + { WPS_MANUFACTURER, "Intel.com", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "Intel Wireless STA", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Intel Wireless STA-001", WPS_COMMON }, /* model number */ +}; + +wps_setting* get_vendor_wps_settings(enum wps_device_role role) { - return wps_settings[0]; + if (role == WPS_AP) + return wps_settings_ap[0]; + else + return wps_settings_sta; } - diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 983a6cc..d36dea4 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -560,4 +560,67 @@ void stop_dhcp_client() { system("killall dhclient 1>/dev/null 2>/dev/null"); } + +wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { + { + /* + * WPS OOB required. (Not-Configured OOB state) + * */ + { WPS_OOB_SSID, "Openwrt-WPS-tp", WPS_OOB_ONLY }, /* ap broadcasts ssid */ + { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ + { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ + { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ + { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + /* + * General + * */ + { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ + { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ + { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ + { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Openwrt Wireless AP-001", WPS_COMMON }, /* model number */ + { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ + }, + { + /* + * WPS OOB required. (Configured OOB state) + * */ + { WPS_OOB_SSID, "Openwrt-WPS-tp", WPS_OOB_ONLY }, /* ap broadcasts ssid */ + { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ + { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ + { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ + { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + /* + * General + * */ + { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ + { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_COMMON }, /* wps oob state */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ + { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ + { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Openwrt Wireless AP-001", WPS_COMMON }, /* model number */ + { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ + }, +}; + +wps_setting wps_settings_sta[STA_SETTING_NUM] = { + { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "Intel Wireless STA", WPS_COMMON }, /* device name */ + { WPS_MANUFACTURER, "Intel.com", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "Intel Wireless STA", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "Intel Wireless STA-001", WPS_COMMON }, /* model number */ +}; + +wps_setting* get_vendor_wps_settings(enum wps_device_role role) +{ + if (role == WPS_AP) + return wps_settings_ap[0]; + else + return wps_settings_sta; +} #endif /* _TEST_PLATFORM_ */ From 41c24b4d010c65538b683fa876182c333c7bff2e Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Thu, 27 Jan 2022 13:40:40 +0800 Subject: [PATCH 23/90] Remove sta_start_up handler and merge the function into sta_start_wps --- indigo_api_callback_dut.c | 87 ++++++--------------------------------- 1 file changed, 12 insertions(+), 75 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 64fb781..20ac63f 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -56,7 +56,6 @@ void register_apis() { register_api(API_STA_ASSOCIATE, NULL, associate_sta_handler); register_api(API_STA_CONFIGURE, NULL, configure_sta_handler); register_api(API_STA_DISCONNECT, NULL, stop_sta_handler); - register_api(API_STA_START_UP, NULL, start_up_sta_handler); register_api(API_STA_SEND_DISCONNECT, NULL, send_sta_disconnect_handler); register_api(API_STA_REASSOCIATE, NULL, send_sta_reconnect_handler); register_api(API_STA_SET_PARAM, NULL, set_sta_parameter_handler); @@ -2693,37 +2692,21 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe return 0; } -static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; - char buffer[BUFFER_LEN], response[1024], log_level[TLV_VALUE_SIZE], value[TLV_VALUE_SIZE]; - char ssid[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; - int len, status = TLV_VALUE_STATUS_NOT_OK, i, ssid_len = 0; +static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + char pin_code[64], if_name[32]; size_t resp_len; - char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; + int i, len, status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_AP_START_WPS_NOT_OK; struct tlv_hdr *tlv = NULL; struct tlv_to_config_name* cfg = NULL; -#ifdef _OPENWRT_ -#else - system("rfkill unblock wlan"); - sleep(1); -#endif - - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); - system(buffer); - sleep(3); - - tlv = find_wrapper_tlv_by_id(req, TLV_SSID); - memset(ssid, 0, sizeof(ssid)); - if (tlv) { - memset(value, 0, sizeof(value)); - memcpy(value, tlv->value, tlv->len); - ssid_len = sprintf(ssid, "network={\nssid=\"%s\"\nscan_ssid=1\nkey_mgmt=NONE\n}\n", value); - } + char value[TLV_VALUE_SIZE], cfg_item[2*S_BUFFER_LEN]; memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT); + /* global config excepts wps */ for (i = 0; i < req->tlv_num; i++) { cfg = find_wpas_global_config_name(req->tlv[i]->id); if (cfg) { @@ -2737,78 +2720,32 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe /* wps settings */ tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); if (tlv) { - int j; - memset(value, 0, sizeof(value)); memcpy(value, tlv->value, tlv->len); - /* To get STA wps vendor info */ wps_setting *s = get_vendor_wps_settings(WPS_STA); if (atoi(value)) { - for (j = 0; j < STA_SETTING_NUM; j++) { + for (i = 0; i < STA_SETTING_NUM; i++) { memset(cfg_item, 0, sizeof(cfg_item)); - sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); strcat(buffer, cfg_item); } } } - if (ssid_len) { - strcat(buffer, ssid); - } len = strlen(buffer); - if (len) { write_file(get_wpas_conf_file(), buffer, len); } - /* TLV: DEBUG_LEVEL */ - tlv = find_wrapper_tlv_by_id(req, TLV_DEBUG_LEVEL); - memset(log_level, 0, sizeof(log_level)); - if (tlv) { - memcpy(log_level, tlv->value, tlv->len); - } - - if (strlen(log_level)) { - set_wpas_debug_level(get_debug_level(atoi(log_level))); - } - - /* Start WPA supplicant */ memset(buffer, 0 ,sizeof(buffer)); - sprintf(buffer, "%s -B -t -c %s %s -i %s -f %s", + sprintf(buffer, "%s -B -t -c %s -i %s -f /var/log/supplicant.log", get_wpas_full_exec_path(), get_wpas_conf_file(), - get_wpas_debug_arguments(), - get_wireless_interface(), - WPAS_LOG_FILE); + get_wireless_interface()); len = system(buffer); sleep(2); - len = pipe_command(buffer, sizeof(buffer), "/bin/pidof", parameter); - if (len) { - status = TLV_VALUE_STATUS_OK; - message = TLV_VALUE_WPA_S_START_UP_OK; - } else { - status = TLV_VALUE_STATUS_NOT_OK; - message = TLV_VALUE_WPA_S_START_UP_NOT_OK; - } - -done: - fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); - fill_wrapper_tlv_byte(resp, TLV_STATUS, status); - fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); - return 0; -} - -static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - struct wpa_ctrl *w = NULL; - char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; - char pin_code[64], if_name[32]; - size_t resp_len; - int status = TLV_VALUE_STATUS_NOT_OK; - char *message = TLV_VALUE_AP_START_WPS_NOT_OK; - struct tlv_hdr *tlv = NULL; - memset(buffer, 0, sizeof(buffer)); tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); if (tlv) { From 0fa26f336b8a84af209378078a54b744c94536b7 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 28 Jan 2022 10:46:37 +0800 Subject: [PATCH 24/90] Add configuration for UUID and RF-BAND --- indigo_api_callback_dut.c | 22 ++++++++++++++++++++++ indigo_api_callback_tp.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 20ac63f..cd18fff 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -270,6 +270,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int has_sae = 0, has_wpa = 0, has_pmf = 0, has_owe = 0, has_transition = 0, has_sae_groups = 0; int channel = 0, chwidth = 1, enable_ax = 0, chwidthset = 0, enable_muedca = 0, vht_chwidthset = 0; int i, enable_ac = 0, enable_11h = 0, enable_hs20 = 0; + int enable_wps = 0, is_g_mode = 0, is_a_mode = 0, use_mbss = 0; char buffer[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; char band[64], value[16]; char country[16]; @@ -308,6 +309,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } if (tlv->id == TLV_BSS_IDENTIFIER) { + use_mbss = 1; if (is_band_enabled(BAND_6GHZ) && !wlanp->mbssid_enable) { strcat(output, "rnr=1\n"); } @@ -368,6 +370,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (tlv->id == TLV_WSC_OOB) { int j; + enable_wps = 1; memcpy(buffer, tlv->value, tlv->len); wps_setting *s = get_vendor_wps_settings(WPS_AP); if (atoi(buffer)) { @@ -429,6 +432,11 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (tlv->id == TLV_HW_MODE) { memset(band, 0, sizeof(band)); memcpy(band, tlv->value, tlv->len); + if (!strncmp(band, "a", 1)) { + is_a_mode = 1; + } else if (!(strncmp(band, "g", 1))) { + is_g_mode = 1; + } } if (tlv->id == TLV_CHANNEL) { @@ -542,6 +550,20 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } } + /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WSC_OOB */ + if (enable_wps) { + if (use_mbss) { + /* dual concurrent case */ + strcat(output, "wps_rf_bands=ag\n"); + } else { + if (is_a_mode) { + strcat(output, "wps_rf_bands=a\n"); + } else if (is_g_mode) { + strcat(output, "wps_rf_bands=g\n"); + } + } + } + if (has_pmf == 0) { if (has_transition) { strcat(output, "ieee80211w=1\n"); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 1806765..72a0e65 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -242,6 +242,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ struct tlv_to_profile *profile = NULL; int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); int hs20_icons_attached = 0; + int enable_wps = 0, is_g_mode = 0, is_a_mode = 0, use_mbss = 0; #if HOSTAPD_SUPPORT_MBSSID @@ -281,6 +282,18 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ continue; } + if (tlv->id == TLV_BSS_IDENTIFIER) { + use_mbss = 1; + } + + if (tlv->id == TLV_HW_MODE && tlv->value) { + if (!strncmp(tlv->value, "a", 1)) { + is_a_mode = 1; + } else if (!(strncmp(tlv->value, "g", 1))) { + is_g_mode = 1; + } + } + if (tlv->id == TLV_HESSID && strstr(tlv->value, "self")) { char mac_addr[64]; @@ -317,6 +330,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (tlv->id == TLV_WSC_OOB) { int j; + enable_wps = 1; memcpy(buffer, tlv->value, tlv->len); wps_setting *s = get_vendor_wps_settings(WPS_AP); if (atoi(buffer)) { @@ -469,6 +483,21 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (tlv->id == TLV_HE_MU_EDCA) add_mu_edca_params(output); } + + /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WSC_OOB */ + if (enable_wps) { + if (use_mbss) { + /* dual concurrent case */ + strcat(output, "wps_rf_bands=ag\n"); + } else { + if (is_a_mode) { + strcat(output, "wps_rf_bands=a\n"); + } else if (is_g_mode) { + strcat(output, "wps_rf_bands=g\n"); + } + } + } + if (ctrl_iface == 0) { indigo_logger(LOG_LEVEL_ERROR, "No Remote UDP ctrl interface TLV for TP"); return 0; From 798bad4601b57ae28493f65768ba95e5af7b80e8 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 28 Jan 2022 14:38:32 +0800 Subject: [PATCH 25/90] Remove dummy variables and add more descriptions. --- indigo_api_callback_dut.c | 13 ++++--------- indigo_api_callback_tp.c | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index cd18fff..7468c67 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -270,7 +270,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int has_sae = 0, has_wpa = 0, has_pmf = 0, has_owe = 0, has_transition = 0, has_sae_groups = 0; int channel = 0, chwidth = 1, enable_ax = 0, chwidthset = 0, enable_muedca = 0, vht_chwidthset = 0; int i, enable_ac = 0, enable_11h = 0, enable_hs20 = 0; - int enable_wps = 0, is_g_mode = 0, is_a_mode = 0, use_mbss = 0; + int enable_wps = 0, use_mbss = 0; char buffer[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; char band[64], value[16]; char country[16]; @@ -432,11 +432,6 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (tlv->id == TLV_HW_MODE) { memset(band, 0, sizeof(band)); memcpy(band, tlv->value, tlv->len); - if (!strncmp(band, "a", 1)) { - is_a_mode = 1; - } else if (!(strncmp(band, "g", 1))) { - is_g_mode = 1; - } } if (tlv->id == TLV_CHANNEL) { @@ -553,12 +548,12 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WSC_OOB */ if (enable_wps) { if (use_mbss) { - /* dual concurrent case */ + /* The wps test for mbss should always be dual concurrent. */ strcat(output, "wps_rf_bands=ag\n"); } else { - if (is_a_mode) { + if (!strncmp(band, "a", 1)) { strcat(output, "wps_rf_bands=a\n"); - } else if (is_g_mode) { + } else if (!strncmp(band, "g", 1)) { strcat(output, "wps_rf_bands=g\n"); } } diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 72a0e65..12b76d6 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -487,7 +487,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WSC_OOB */ if (enable_wps) { if (use_mbss) { - /* dual concurrent case */ + /* The wps test for mbss should always be dual concurrent. */ strcat(output, "wps_rf_bands=ag\n"); } else { if (is_a_mode) { From 9aa3b1bb22bafb5b73faa09ef8b92e9c12f09c14 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Tue, 8 Feb 2022 16:39:00 +0800 Subject: [PATCH 26/90] Refined get_wsc_cred API which supported by tool and dut side. --- indigo_api_callback_dut.c | 105 ++++++++++++++++++++++++++++++++++++++ indigo_api_callback_tp.c | 104 +++++++++++++++++++++++++++---------- utils.c | 12 +++++ utils.h | 1 + 4 files changed, 194 insertions(+), 28 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 7468c67..5e022fc 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -43,6 +43,7 @@ void register_apis() { register_api(API_START_DHCP, NULL, start_dhcp_handler); register_api(API_STOP_DHCP, NULL, stop_dhcp_handler); register_api(API_GET_WSC_PIN, NULL, get_wsc_pin_handler); + register_api(API_GET_WSC_CRED, NULL, get_wsc_cred_handler); /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); @@ -2802,3 +2803,107 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp } return 0; } + +struct _cfg_cred { + char *key; + char *tok; + char val[S_BUFFER_LEN]; + unsigned short tid; +}; + +static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_NOT_OK; + char *pos = NULL, *data = NULL, value[16]; + int i, len, ret = -1, count = 0, role = 0; + struct tlv_hdr *tlv = NULL; + struct _cfg_cred *p_cfg = NULL; + + memset(value, 0, sizeof(value)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(value, tlv->value, tlv->len); + role = atoi(value); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); + goto done; + } + + if (role == DUT_TYPE_APUT) { + // APUT + struct _cfg_cred cfg_creds[] = { + {"ssid", "ssid=", {0}, TLV_WSC_SSID}, + {"wpa_passphrase", "wpa_passphrase=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"wpa_key_mgmt", "wpa_key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} + }; + count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); + p_cfg = cfg_creds; + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_IDENTIFIER); + struct interface_info *wlan = NULL; + if (tlv) { + /* mbss: TBD */ + } else { + /* single wlan */ + wlan = get_first_configured_wireless_interface_info(); + } + if (!wlan) + goto done; + data = read_file(wlan->hapd_conf_file); + if (!data) { + indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", wlan->hapd_conf_file); + goto done; + } + } else if (role == DUT_TYPE_STAUT) { + // STAUT + struct _cfg_cred cfg_creds[] = { + {"ssid", "ssid=", {0}, TLV_WSC_SSID}, + {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"key_mgmt", "key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} + }; + count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); + p_cfg = cfg_creds; + data = read_file(get_wpas_conf_file()); + if (!data) { + indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", get_wpas_conf_file()); + goto done; + } + } else { + indigo_logger(LOG_LEVEL_ERROR, "Invalid value in TLV_ROLE"); + goto done; + } + + for (i = 0; i < count; i++) { + pos = strstr(data, p_cfg[i].tok); + if (pos) { + pos += strlen(p_cfg[i].tok); + if (*pos == '"') { + /* Handle with the format aaaaa="xxxxxxxx" */ + pos++; + len = strchr(pos, '"') - pos; + } else { + /* Handle with the format bbbbb=yyyyyyyy */ + len = strchr(pos, '\n') - pos; + } + memcpy(p_cfg[i].val, pos, len); + indigo_logger(LOG_LEVEL_INFO, "Get %s: %s\n", p_cfg[i].key, p_cfg[i].val); + } else { + indigo_logger(LOG_LEVEL_INFO, "Cannot find the setting: %s\n", p_cfg[i].key); + //goto done; + } + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + if (data) + free(data); + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (status == TLV_VALUE_STATUS_OK) { + for (i = 0; i < count; i++) { + fill_wrapper_tlv_bytes(resp, p_cfg[i].tid, strlen(p_cfg[i].val), p_cfg[i].val); + } + } + return 0; +} diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 12b76d6..584c1ef 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1792,57 +1792,105 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * return 0; } +struct _cfg_cred { + char *key; + char *tok; + char val[S_BUFFER_LEN]; + unsigned short tid; +}; + static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_NOT_OK; - char *pos = NULL, *data = NULL; - int i, len, ret = -1, count = 0; - struct _cfg_cred { - char *key; - char *tok; - char val[S_BUFFER_LEN]; - unsigned short tid; - } cfg_creds[] = { - {"ssid", "ssid=", {0}, TLV_WSC_SSID}, - {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASS}, - {"key_mgmt", "key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} - }; - - data = read_file(get_wpas_conf_file()); - if (!data) - indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", get_wpas_conf_file()); - - count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); + char *pos = NULL, *data = NULL, value[16]; + int i, len, ret = -1, count = 0, role = 0; + struct tlv_hdr *tlv = NULL; + struct _cfg_cred *p_cfg = NULL; + + memset(value, 0, sizeof(value)); + tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); + if (tlv) { + memcpy(value, tlv->value, tlv->len); + role = atoi(value); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); + goto done; + } + + if (role == DUT_TYPE_APUT) { + // Test Platform: STA + struct _cfg_cred cfg_creds[] = { + {"ssid", "ssid=", {0}, TLV_WSC_SSID}, + {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"key_mgmt", "key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} + }; + count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); + p_cfg = cfg_creds; + data = read_file(get_wpas_conf_file()); + if (!data) { + indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", get_wpas_conf_file()); + goto done; + } + } else if (role == DUT_TYPE_STAUT) { + // Test Platform: AP + struct _cfg_cred cfg_creds[] = { + {"ssid", "ssid=", {0}, TLV_WSC_SSID}, + {"wpa_passphrase", "wpa_passphrase=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"wpa_key_mgmt", "wpa_key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} + }; + count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); + p_cfg = cfg_creds; + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_IDENTIFIER); + struct interface_info *wlan = NULL; + if (tlv) { + /* mbss: TBD */ + } else { + /* single wlan */ + wlan = get_first_configured_wireless_interface_info(); + } + if (!wlan) + goto done; + data = read_file(wlan->hapd_conf_file); + if (!data) { + indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", wlan->hapd_conf_file); + goto done; + } + } else { + indigo_logger(LOG_LEVEL_ERROR, "Invalid value in TLV_ROLE"); + goto done; + } + for (i = 0; i < count; i++) { - pos = strstr(data, cfg_creds[i].tok); + pos = strstr(data, p_cfg[i].tok); if (pos) { - pos += strlen(cfg_creds[i].tok); + pos += strlen(p_cfg[i].tok); if (*pos == '"') { - /* Handle with the format ssid/key="xxxxxxxx" */ + /* Handle with the format aaaaa="xxxxxxxx" */ pos++; len = strchr(pos, '"') - pos; } else { - /* Handle with the format key_mgmt=yyyyyyyy */ + /* Handle with the format bbbbb=yyyyyyyy */ len = strchr(pos, '\n') - pos; } - memcpy(cfg_creds[i].val, pos, len); - indigo_logger(LOG_LEVEL_INFO, "Get %s: %s\n", cfg_creds[i].key, cfg_creds[i].val); + memcpy(p_cfg[i].val, pos, len); + indigo_logger(LOG_LEVEL_INFO, "Get %s: %s\n", p_cfg[i].key, p_cfg[i].val); } else { - indigo_logger(LOG_LEVEL_ERROR, "Cannot find the setting: %s\n", cfg_creds[i].key); - goto done; + indigo_logger(LOG_LEVEL_INFO, "Cannot find the setting: %s\n", p_cfg[i].key); + //goto done; } } status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; done: - free(data); + if (data) + free(data); fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); if (status == TLV_VALUE_STATUS_OK) { for (i = 0; i < count; i++) { - fill_wrapper_tlv_bytes(resp, cfg_creds[i].tid, strlen(cfg_creds[i].val), cfg_creds[i].val); + fill_wrapper_tlv_bytes(resp, p_cfg[i].tid, strlen(p_cfg[i].val), p_cfg[i].val); } } return 0; diff --git a/utils.c b/utils.c index 0d2a1e1..0b80754 100644 --- a/utils.c +++ b/utils.c @@ -942,6 +942,18 @@ struct interface_info* get_wireless_interface_info(int band, int identifier) { return NULL; } +struct interface_info* get_first_configured_wireless_interface_info() { + int i; + + for (i = 0; i < interface_count; i++) { + if (interfaces[i].identifier != UNUSED_IDENTIFIER) { + return &interfaces[i]; + } + } + + return NULL; +} + int get_debug_level(int value) { if (value == 0) { return DEBUG_LEVEL_DISABLE; diff --git a/utils.h b/utils.h index d82d19f..bf1ec87 100644 --- a/utils.h +++ b/utils.h @@ -198,6 +198,7 @@ char* get_all_hapd_conf_files(int *swap_hostapd); void parse_bss_identifier(int bss_identifier, struct bss_identifier_info* bss); struct interface_info* assign_wireless_interface_info(struct bss_identifier_info *bss); struct interface_info* get_wireless_interface_info(int band, int identifier); +struct interface_info* get_first_configured_wireless_interface_info(); int add_all_wireless_interface_to_bridge(char *br); void set_default_wireless_interface_info(int channel); int show_wireless_interface_info(); From 0b41d45551ac24599016383d8157c063be78c839 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Wed, 9 Feb 2022 13:48:24 +0800 Subject: [PATCH 27/90] Don't stop wpa_supplicant in DUT before TP stops wpa_supplicant --- indigo_api_callback_dut.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 0117bb5..905d386 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -133,11 +133,9 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe /* reset interfaces info */ clear_interfaces_resource(); } else if (atoi(role) == DUT_TYPE_P2PUT) { - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); - system(buffer); - sleep(1); - //reset_interface_ip(get_wireless_interface()); + /* If TP is P2P client, GO can't stop before client removes group monitor if */ + // sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + // reset_interface_ip(get_wireless_interface()); if (strlen(log_level)) { set_wpas_debug_level(get_debug_level(atoi(log_level))); } From 99a78825b78aa9076b7d58245b55d2051b0f9f83 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Wed, 9 Feb 2022 15:21:50 +0800 Subject: [PATCH 28/90] Add wpa_ctrl_close() in get_wsc_pin_handler --- indigo_api_callback_dut.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 905d386..bc34773 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -2566,6 +2566,9 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper if (status == TLV_VALUE_STATUS_OK) { fill_wrapper_tlv_bytes(resp, TLV_WSC_PIN_CODE, strlen(response), response); } + if (w) { + wpa_ctrl_close(w); + } return 0; } From 18f70a0c59a09d0f9a9afb7542594a15ff4cd4db Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 11 Feb 2022 10:52:43 +0800 Subject: [PATCH 29/90] ITT-1176 ITS-2061 Support PPS MO --- indigo_api.c | 2 + indigo_api.h | 4 + indigo_api_callback.h | 2 + indigo_api_callback_dut.c | 182 ++++++++++++++++++++++++++++++++++++++ vendor_specific.h | 2 + 5 files changed, 192 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index 1dd1e3d..8e917cb 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -51,6 +51,8 @@ struct indigo_api indigo_api_list[] = { { API_STA_SET_CHANNEL_WIDTH, "STA_SET_CHANNEL_WIDTH", NULL, NULL }, { API_STA_POWER_SAVE, "STA_POWER_SAVE", NULL, NULL }, { API_STA_SCAN, "STA_SCAN", NULL, NULL }, + { API_STA_HS2_ASSOCIATE, "API_STA_HS2_ASSOCIATE", NULL, NULL }, + { API_STA_INSTALL_PPSMO, "API_STA_INSTALL_PPSMO", NULL, NULL }, { API_P2P_START_UP, "P2P_START_UP", NULL, NULL }, { API_P2P_FIND, "P2P_FIND", NULL, NULL }, { API_P2P_LISTEN, "P2P_LISTEN", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index 665f6fc..9eb9110 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -74,6 +74,7 @@ struct indigo_api { #define API_STA_SCAN 0x2014 #define API_P2P_GET_INTENT_VALUE 0x2015 #define API_STA_START_WPS 0x2016 +#define API_STA_INSTALL_PPSMO 0x2017 #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -333,6 +334,9 @@ struct indigo_api { #define TLV_VALUE_P2P_START_WPS_NOT_OK "Failed to start WPS on GO interface" #define TLV_VALUE_P2P_CONNECT_NOT_OK "Failed to trigger P2P connect" +#define TLV_VALUE_HS2_INSTALL_PPSMO_OK "PPSMO file is installed" +#define TLV_VALUE_HS2_INSTALL_PPSMO_NOT_OK "Failed to install PPSMO file" + #define TLV_VALUE_AP_START_WPS_NOT_OK "Failed to start WPS on AP interface" #define RESET_TYPE_INIT 0x01 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 8437ba3..7e026a1 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -254,6 +254,8 @@ static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int set_sta_hs2_associate_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_phy_mode_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_channel_width_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 6e02f6f..fa9b0eb 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "indigo_api.h" #include "vendor_specific.h" @@ -28,6 +30,7 @@ static char pac_file_path[S_BUFFER_LEN] = {0}; struct interface_info* band_transmitter[16]; +extern struct sockaddr_in *tool_addr; void register_apis() { @@ -64,6 +67,8 @@ void register_apis() { register_api(API_STA_SEND_ANQP_QUERY, NULL, send_sta_anqp_query_handler); register_api(API_STA_SCAN, NULL, send_sta_scan_handler); register_api(API_STA_START_WPS, NULL, start_wps_sta_handler); + register_api(API_STA_HS2_ASSOCIATE, NULL, set_sta_hs2_associate_handler); + register_api(API_STA_INSTALL_PPSMO, NULL, set_sta_install_ppsmo_handler); /* TODO: Add the handlers */ register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL); register_api(API_STA_POWER_SAVE, NULL, NULL); @@ -77,6 +82,12 @@ void register_apis() { } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + char ipAddress[INET_ADDRSTRLEN]; + if (tool_addr) { + inet_ntop(AF_INET, &(tool_addr->sin_addr), ipAddress, INET_ADDRSTRLEN); + indigo_logger(LOG_LEVEL_DEBUG, "Tool Control IP address on DUT network path: %s", ipAddress); + } + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, TLV_VALUE_STATUS_OK); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(TLV_VALUE_OK), TLV_VALUE_OK); @@ -2387,6 +2398,177 @@ static int send_sta_scan_handler(struct packet_wrapper *req, struct packet_wrapp return 0; } +static int set_sta_hs2_associate_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + size_t resp_len; + char *message = TLV_VALUE_WPA_S_ASSOC_NOT_OK; + char buffer[BUFFER_LEN]; + char response[BUFFER_LEN]; + char bssid[256]; + struct tlv_hdr *tlv = NULL; + struct wpa_ctrl *w = NULL; + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(bssid, 0, sizeof(bssid)); + tlv = find_wrapper_tlv_by_id(req, TLV_BSSID); + if (tlv) { + memset(bssid, 0, sizeof(bssid)); + memcpy(bssid, tlv->value, tlv->len); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "INTERWORKING_CONNECT %s", bssid); + } else { + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "INTERWORKING_SELECT auto"); + } + + /* Send command to wpa_supplicant UDS socket */ + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command %s.\n Response: %s", buffer, response); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + +static int run_hs20_osu_client(const char *params) +{ + char buf[BUFFER_LEN], cmd[S_BUFFER_LEN]; + int res; + + res = snprintf(cmd, sizeof(cmd), + "%s -w \"%s\" -r hs20-osu-client.res -dddKt -f /var/log/hs20-osu-client.log", + HS20_OSU_CLIENT, + WPAS_CTRL_PATH_DEFAULT "/"); + if (res < 0 || res >= (int) sizeof(cmd)) + return -1; + + res = snprintf(buf, sizeof(buf), "%s %s", cmd, params); + if (res < 0 || res >= (int) sizeof(buf)) + return -1; + + indigo_logger(LOG_LEVEL_DEBUG, "Run: %s", buf); + + if (system(buf) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to run: %s", buf); + return -1; + } + + return 0; +} + +static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_HS2_INSTALL_PPSMO_NOT_OK; + int len, i; + char buffer[L_BUFFER_LEN], ppsmo_file[S_BUFFER_LEN]; + struct tlv_hdr *tlv; + char *fqdn = NULL; + char fqdn_buf[S_BUFFER_LEN]; + + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT); + + len = strlen(buffer); + if (len) { + write_file(get_wpas_conf_file(), buffer, len); + } + + snprintf(buffer, sizeof(buffer), "%s -B -t -c %s -i %s -f /var/log/supplicant.log", + get_wpas_full_exec_path(), + get_wpas_conf_file(), + get_wireless_interface()); + if (system(buffer)) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to run wpa_supplicant."); + goto done; + } + sleep(2); + + tlv = find_wrapper_tlv_by_id(req, TLV_PPSMO_FILE); + if (tlv) { + memset(ppsmo_file, 0, sizeof(ppsmo_file)); + memcpy(ppsmo_file, tlv->value, tlv->len); + } else { + goto done; + } + + unlink("pps-tnds.xml"); + snprintf(buffer, sizeof(buffer), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", ppsmo_file); + indigo_logger(LOG_LEVEL_DEBUG, "RUN: %s\n", buffer); + if (system(buffer) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to download PPS MO from %s\n", ppsmo_file); + goto done; + } + + snprintf(buffer, sizeof(buffer), "from_tnds pps-tnds.xml pps.xml"); + if (run_hs20_osu_client(buffer) < 0) + goto done; + sleep(2); + + memset(fqdn_buf, 0, sizeof(fqdn_buf)); + if (run_hs20_osu_client("get_fqdn pps.xml") == 0) { + FILE *f = fopen("pps-fqdn", "r"); + if (f) { + if (fgets(fqdn_buf, sizeof(fqdn_buf), f)) { + fqdn_buf[sizeof(fqdn_buf) - 1] = '\0'; + fqdn = fqdn_buf; + if (fqdn) + indigo_logger(LOG_LEVEL_DEBUG, "FQDN: %s", fqdn); + else { + indigo_logger(LOG_LEVEL_ERROR, "Get FQDN ERROR" ); + goto done; + } + } + fclose(f); + } + } + + mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + snprintf(buffer, sizeof(buffer), "SP/%s", fqdn); + mkdir(buffer, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + + snprintf(buffer, sizeof(buffer), "dl_aaa_ca pps.xml SP/%s/aaa-ca.pem", fqdn); + if (run_hs20_osu_client(buffer) < 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to download AAA CA cert"); + goto done; + } + + snprintf(buffer, sizeof(buffer), "set_pps pps.xml"); + if (run_hs20_osu_client(buffer) < 0) { + indigo_logger(LOG_LEVEL_ERROR, + "errorCode,Failed to configure credential from PPSMO"); + goto done; + } + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_HS2_INSTALL_PPSMO_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + + return 0; +} + static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; diff --git a/vendor_specific.h b/vendor_specific.h index ba1077f..7fa3767 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -66,6 +66,8 @@ #define WPAS_GLOBAL_CTRL_PATH_DEFAULT "/var/run/wpa_supplicant/global" // not use wpas global before #define WPAS_LOG_FILE "/var/log/supplicant.log" +#define HS20_OSU_CLIENT "/usr/local/bin/WFA-Hostapd-Supplicant/hs20-osu-client" + #define WIRELESS_INTERFACE_DEFAULT "wlan0" #define SERVICE_PORT_DEFAULT 9004 From 12963541fa2ede0264b914f298b2fee3573ccb22 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Mon, 14 Feb 2022 12:26:24 +0800 Subject: [PATCH 30/90] Refine sta_start_wps() to support dynamic PIN by STAUT. --- indigo_api_callback_dut.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 5e022fc..ed4c8c9 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -2769,7 +2769,10 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp if (tlv) { memset(pin_code, 0, sizeof(pin_code)); memcpy(pin_code, tlv->value, tlv->len); - sprintf(buffer, "WPS_PIN any %s", pin_code); + if (strlen(pin_code) == 1 && atoi(pin_code) == 0) + sprintf(buffer, "WPS_PIN any"); + else + sprintf(buffer, "WPS_PIN any %s", pin_code); } else { sprintf(buffer, "WPS_PBC"); } @@ -2798,6 +2801,9 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (status == TLV_VALUE_STATUS_OK) { + fill_wrapper_tlv_bytes(resp, TLV_WSC_PIN_CODE, strlen(response), response); + } if (w) { wpa_ctrl_close(w); } From 2d0693e09c5dcbc19bd29de836c69b44eee677ab Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Tue, 15 Feb 2022 13:06:05 +0800 Subject: [PATCH 31/90] Add TLV:EAP_FRAG_SIZE which can be used by wpas and hapd. Currently it is only used in tp-ap. --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback.h | 5 ++++- indigo_api_callback_tp.c | 8 +++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 8e917cb..2b703e1 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -240,6 +240,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_HS20_OPERATING_CLASS_INDICATION, "HS20_OPERATING_CLASS_INDICATION"}, { TLV_WSC_OOB, "WSC_OOB" }, { TLV_UPDATE_CONFIG, "UPDATE_CONFIG" }, + { TLV_EAP_FRAG_SIZE, "EAP_FRAG_SIZE" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 9eb9110..935650e 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -251,6 +251,7 @@ struct indigo_api { #define TLV_HS20_OPERATING_CLASS_INDICATION 0x00cb #define TLV_WSC_OOB 0x00cc #define TLV_UPDATE_CONFIG 0x00cd +#define TLV_EAP_FRAG_SIZE 0x00ce // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 7e026a1..ce0a085 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -129,7 +129,10 @@ struct tlv_to_config_name maps[] = { { TLV_BSSID, "bssid", 0 }, { TLV_REALM, "realm", 0 }, { TLV_IMSI, "imsi", 0 }, - { TLV_MILENAGE, "milenage", 0 }, + { TLV_MILENAGE, "milenage", 0 }, + + /* hapd + wpas */ + { TLV_EAP_FRAG_SIZE, "fragment_size", 0 }, }; struct tlv_to_config_name semicolon_list[] = { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 584c1ef..299f944 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -362,13 +362,19 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } } } - cfg = find_tlv_config(tlv->id); if (!cfg) { indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id); continue; } + /* wps eap fragment size */ + if (tlv->id == TLV_EAP_FRAG_SIZE) { + memcpy(buffer, tlv->value, tlv->len); + sprintf(cfg_item, "%s=%s\n", cfg->config_name, buffer); + strcat(output, cfg_item); + } + #ifdef _WTS_OPENWRT_ if (tlv->id == TLV_HW_MODE) { memset(band, 0, sizeof(band)); From c0cf88b69291bba7d083597fece61296f917f644 Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 16 Feb 2022 13:04:16 +0800 Subject: [PATCH 32/90] ITS-2067 support test case 10528_1 --- hs2_profile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hs2_profile.h b/hs2_profile.h index 675099e..b5033c2 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -64,7 +64,7 @@ const char * hs20_wan_metrics[] = { "", "hs20_wan_metrics=01:2560:384:0:0:0\n", "", - "", + "hs20_wan_metrics=01:2048:1024:20:20:10\n", "", "", }; From 77611547ec30760467be6c8ffc685d6adb77c0a5 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Wed, 16 Feb 2022 13:31:00 +0800 Subject: [PATCH 33/90] ap_configure() to handle wps ie fragmentation when receiving TLV_PERFORM_WPS_IE_FRAG. --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback_tp.c | 17 ++++++++++++++++- vendor_specific.h | 2 +- vendor_specific_tp.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 2b703e1..ef1b403 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -241,6 +241,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_WSC_OOB, "WSC_OOB" }, { TLV_UPDATE_CONFIG, "UPDATE_CONFIG" }, { TLV_EAP_FRAG_SIZE, "EAP_FRAG_SIZE" }, + { TLV_PERFORM_WPS_IE_FRAG, "PERFORM_WPS_IE_FRAG" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 935650e..ccfb3fa 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -252,6 +252,7 @@ struct indigo_api { #define TLV_WSC_OOB 0x00cc #define TLV_UPDATE_CONFIG 0x00cd #define TLV_EAP_FRAG_SIZE 0x00ce +#define TLV_PERFORM_WPS_IE_FRAG 0x00cf // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 299f944..c4d6c1b 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -37,6 +37,7 @@ int rrm = 0, he_mu_edca = 0; #endif extern struct sockaddr_in *tool_addr; +extern wps_setting* get_vendor_wps_settings_for_ie_frag_test(enum wps_device_role role); void register_apis() { /* Basic */ @@ -243,6 +244,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); int hs20_icons_attached = 0; int enable_wps = 0, is_g_mode = 0, is_a_mode = 0, use_mbss = 0; + int perform_wps_ie_frag = 0; #if HOSTAPD_SUPPORT_MBSSID @@ -326,13 +328,26 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ continue; } + /* wps settings */ + if (tlv->id == TLV_PERFORM_WPS_IE_FRAG) { + perform_wps_ie_frag = 1; + } + /* wps settings */ if (tlv->id == TLV_WSC_OOB) { int j; + wps_setting *s = NULL; enable_wps = 1; memcpy(buffer, tlv->value, tlv->len); - wps_setting *s = get_vendor_wps_settings(WPS_AP); + if (perform_wps_ie_frag == 1) + s = get_vendor_wps_settings_for_ie_frag_test(WPS_AP); + else + s = get_vendor_wps_settings(WPS_AP); + if (!s) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to get vendor wps settings."); + continue; + } if (atoi(buffer)) { /* Use OOB */ for (j = 0; j < AP_SETTING_NUM; j++) { diff --git a/vendor_specific.h b/vendor_specific.h index 7fa3767..7bf5138 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -127,7 +127,7 @@ enum wps_device_role { WPS_STA }; -#define GROUP_NUM (2) +#define GROUP_NUM (3) #define AP_SETTING_NUM (14) #define STA_SETTING_NUM (5) diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index d36dea4..a9a3b76 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -584,6 +584,28 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { WPS_MODEL_NUMBER, "Openwrt Wireless AP-001", WPS_COMMON }, /* model number */ { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ }, + { + /* + * WPS OOB required. (Not-Configured OOB state) - Test purpose for WPS IE fragmentation. + * */ + { WPS_OOB_SSID, "Openwrt-WPS-tp", WPS_OOB_ONLY }, /* ap broadcasts ssid */ + { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ + { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ + { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ + { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + /* + * General + * */ + { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ + { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* device name */ + { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ + { WPS_MANUFACTURER, "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* model number */ + { WPS_SERIAL_NUMBER, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* serial number */ + }, { /* * WPS OOB required. (Configured OOB state) @@ -623,4 +645,16 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) else return wps_settings_sta; } + +wps_setting* get_vendor_wps_settings_for_ie_frag_test(enum wps_device_role role) +{ + /* + * Test purpose to enlarge wps ie payload and perform wps ie fragmentation automatically. (AP only) + * */ + + if (role == WPS_AP) + return wps_settings_ap[1]; + else + return NULL; +} #endif /* _TEST_PLATFORM_ */ From e3d09cd9d222ea50011e42913511f4e3c06b2e99 Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 16 Feb 2022 15:23:42 +0800 Subject: [PATCH 34/90] ITS-2067 update hs20_wan_metrics --- hs2_profile.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index b5033c2..d4068c2 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -62,9 +62,9 @@ const char * ipaddr_type_avail[] = { const char * hs20_wan_metrics[] = { "", - "hs20_wan_metrics=01:2560:384:0:0:0\n", + "hs20_wan_metrics=01:2500:384:0:0:10\n", "", - "hs20_wan_metrics=01:2048:1024:20:20:10\n", + "hs20_wan_metrics=01:2000:1000:20:20:10\n", "", "", }; From 869dcdbccc2f39bfad5180e3c5a35fab09562d00 Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 16 Feb 2022 15:57:16 +0800 Subject: [PATCH 35/90] ITS-2075 support test case 10536_1 --- indigo_api_callback_tp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 299f944..d9c67a5 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -243,7 +243,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); int hs20_icons_attached = 0; int enable_wps = 0, is_g_mode = 0, is_a_mode = 0, use_mbss = 0; - + int bss_load_tlv = 0; #if HOSTAPD_SUPPORT_MBSSID if (wlanp->mbssid_enable && !wlanp->transmitter) @@ -315,6 +315,10 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ hs20_icons_attached = 1; } + if (tlv->id == TLV_BSSLOAD_ENABLE) { + bss_load_tlv = 1; + } + if (atoi(buffer) > profile->size) { indigo_logger(LOG_LEVEL_ERROR, "profile index out of bound!: %d, array_size:%d", atoi(buffer), profile->size); } else { @@ -517,8 +521,10 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, "hs20_release=3\n"); strcat(output, "manage_p2p=1\n"); strcat(output, "allow_cross_connection=0\n"); - strcat(output, "bss_load_update_period=100\n"); strcat(output, "hs20_deauth_req_timeout=3\n"); + if (bss_load_tlv == 0) { + strcat(output, "bss_load_update_period=100\n"); + } } #ifdef _WTS_OPENWRT_ From e16f3f652b2664df30ede257a7341a5a3a6525ba Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Thu, 17 Feb 2022 11:07:46 +0800 Subject: [PATCH 36/90] Separated the wps control steps into configure and start phrases. --- indigo_api_callback_dut.c | 179 +++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 99 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 0faa3dc..5d6c535 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -1633,7 +1633,7 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra int transition_mode_enabled = 0; int owe_configured = 0; int sae_only = 0; - + struct tlv_hdr *tlv = NULL; struct tlv_to_config_name* cfg = NULL; sprintf(buffer, "ctrl_interface=%s\nap_scan=1\npmf=1\n", WPAS_CTRL_PATH_DEFAULT); @@ -1647,80 +1647,98 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra strcat(buffer, cfg_item); } } - strcat(buffer, "network={\n"); + + /* wps settings */ + tlv = find_wrapper_tlv_by_id(wrapper, TLV_WSC_OOB); + if (tlv) { + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + /* To get STA wps vendor info */ + wps_setting *s = get_vendor_wps_settings(WPS_STA); + if (atoi(value)) { + for (i = 0; i < STA_SETTING_NUM; i++) { + memset(cfg_item, 0, sizeof(cfg_item)); + sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); + strcat(buffer, cfg_item); + } + } + } else { + /* Configure network profile only for Non-WPS case */ + + strcat(buffer, "network={\n"); #ifdef _RESERVED_ - /* The function is reserved for the defeault wpas config */ - append_wpas_network_default_config(wrapper); + /* The function is reserved for the defeault wpas config */ + append_wpas_network_default_config(wrapper); #endif /* _RESERVED_ */ - for (i = 0; i < wrapper->tlv_num; i++) { - cfg = find_tlv_config(wrapper->tlv[i]->id); - if (cfg && find_wpas_global_config_name(wrapper->tlv[i]->id) == NULL) { - memset(value, 0, sizeof(value)); - memcpy(value, wrapper->tlv[i]->value, wrapper->tlv[i]->len); + for (i = 0; i < wrapper->tlv_num; i++) { + cfg = find_tlv_config(wrapper->tlv[i]->id); + if (cfg && find_wpas_global_config_name(wrapper->tlv[i]->id) == NULL) { + memset(value, 0, sizeof(value)); + memcpy(value, wrapper->tlv[i]->value, wrapper->tlv[i]->len); + + if ((wrapper->tlv[i]->id == TLV_IEEE80211_W) || (wrapper->tlv[i]->id == TLV_STA_IEEE80211_W)) { + ieee80211w_configured = 1; + } else if (wrapper->tlv[i]->id == TLV_KEY_MGMT) { + if (strstr(value, "WPA-PSK") && strstr(value, "SAE")) { + transition_mode_enabled = 1; + } + if (!strstr(value, "WPA-PSK") && strstr(value, "SAE")) { + sae_only = 1; + } - if ((wrapper->tlv[i]->id == TLV_IEEE80211_W) || (wrapper->tlv[i]->id == TLV_STA_IEEE80211_W)) { - ieee80211w_configured = 1; - } else if (wrapper->tlv[i]->id == TLV_KEY_MGMT) { - if (strstr(value, "WPA-PSK") && strstr(value, "SAE")) { - transition_mode_enabled = 1; - } - if (!strstr(value, "WPA-PSK") && strstr(value, "SAE")) { - sae_only = 1; + if (strstr(value, "OWE")) { + owe_configured = 1; + } + } else if ((wrapper->tlv[i]->id == TLV_CA_CERT) && strcmp("DEFAULT", value) == 0) { + sprintf(value, "/etc/ssl/certs/ca-certificates.crt"); + } else if ((wrapper->tlv[i]->id == TLV_PAC_FILE)) { + memset(pac_file_path, 0, sizeof(pac_file_path)); + snprintf(pac_file_path, sizeof(pac_file_path), "%s", value); + } else if (wrapper->tlv[i]->id == TLV_SERVER_CERT) { + memset(buf, 0, sizeof(buf)); + get_server_cert_hash(value, buf); + memcpy(value, buf, sizeof(buf)); } - if (strstr(value, "OWE")) { - owe_configured = 1; + if (cfg->quoted) { + sprintf(cfg_item, "%s=\"%s\"\n", cfg->config_name, value); + strcat(buffer, cfg_item); + } else { + sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); + strcat(buffer, cfg_item); } - } else if ((wrapper->tlv[i]->id == TLV_CA_CERT) && strcmp("DEFAULT", value) == 0) { - sprintf(value, "/etc/ssl/certs/ca-certificates.crt"); - } else if ((wrapper->tlv[i]->id == TLV_PAC_FILE)) { - memset(pac_file_path, 0, sizeof(pac_file_path)); - snprintf(pac_file_path, sizeof(pac_file_path), "%s", value); - } else if (wrapper->tlv[i]->id == TLV_SERVER_CERT) { - memset(buf, 0, sizeof(buf)); - get_server_cert_hash(value, buf); - memcpy(value, buf, sizeof(buf)); } + } - if (cfg->quoted) { - sprintf(cfg_item, "%s=\"%s\"\n", cfg->config_name, value); - strcat(buffer, cfg_item); - } else { - sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); - strcat(buffer, cfg_item); + if (ieee80211w_configured == 0) { + if (transition_mode_enabled) { + strcat(buffer, "ieee80211w=1\n"); + } else if (sae_only) { + strcat(buffer, "ieee80211w=2\n"); + } else if (owe_configured) { + strcat(buffer, "ieee80211w=2\n"); } - } - } - - if (ieee80211w_configured == 0) { - if (transition_mode_enabled) { - strcat(buffer, "ieee80211w=1\n"); - } else if (sae_only) { - strcat(buffer, "ieee80211w=2\n"); - } else if (owe_configured) { - strcat(buffer, "ieee80211w=2\n"); } - } - - /* TODO: merge another file */ - /* python source code: - if merge_config_file: - appended_supplicant_conf_str = "" - existing_conf = StaCommandHelper.get_existing_supplicant_conf() - wpa_supplicant_dict = StaCommandHelper.__convert_config_str_to_dict(config = wps_config) - for each_key in existing_conf: - if each_key not in wpa_supplicant_dict: - wpa_supplicant_dict[each_key] = existing_conf[each_key] - for each_supplicant_conf in wpa_supplicant_dict: - appended_supplicant_conf_str += each_supplicant_conf + "=" + wpa_supplicant_dict[each_supplicant_conf] + "\n" - wps_config = appended_supplicant_conf_str.rstrip() - */ + /* TODO: merge another file */ + /* python source code: + if merge_config_file: + appended_supplicant_conf_str = "" + existing_conf = StaCommandHelper.get_existing_supplicant_conf() + wpa_supplicant_dict = StaCommandHelper.__convert_config_str_to_dict(config = wps_config) + for each_key in existing_conf: + if each_key not in wpa_supplicant_dict: + wpa_supplicant_dict[each_key] = existing_conf[each_key] - strcat(buffer, "}\n"); + for each_supplicant_conf in wpa_supplicant_dict: + appended_supplicant_conf_str += each_supplicant_conf + "=" + wpa_supplicant_dict[each_supplicant_conf] + "\n" + wps_config = appended_supplicant_conf_str.rstrip() + */ + strcat(buffer, "}\n"); + } return strlen(buffer); } @@ -2898,53 +2916,16 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; char pin_code[64], if_name[32]; size_t resp_len; - int i, len, status = TLV_VALUE_STATUS_NOT_OK; + int i, status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_AP_START_WPS_NOT_OK; struct tlv_hdr *tlv = NULL; - struct tlv_to_config_name* cfg = NULL; - char value[TLV_VALUE_SIZE], cfg_item[2*S_BUFFER_LEN]; - - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT); - - /* global config excepts wps */ - for (i = 0; i < req->tlv_num; i++) { - cfg = find_wpas_global_config_name(req->tlv[i]->id); - if (cfg) { - memset(value, 0, sizeof(value)); - memcpy(value, req->tlv[i]->value, req->tlv[i]->len); - sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); - strcat(buffer, cfg_item); - } - } - - /* wps settings */ - tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); - if (tlv) { - memset(value, 0, sizeof(value)); - memcpy(value, tlv->value, tlv->len); - /* To get STA wps vendor info */ - wps_setting *s = get_vendor_wps_settings(WPS_STA); - if (atoi(value)) { - for (i = 0; i < STA_SETTING_NUM; i++) { - memset(cfg_item, 0, sizeof(cfg_item)); - sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); - strcat(buffer, cfg_item); - } - } - } - - len = strlen(buffer); - if (len) { - write_file(get_wpas_conf_file(), buffer, len); - } memset(buffer, 0 ,sizeof(buffer)); sprintf(buffer, "%s -B -t -c %s -i %s -f /var/log/supplicant.log", get_wpas_full_exec_path(), get_wpas_conf_file(), get_wireless_interface()); - len = system(buffer); + system(buffer); sleep(2); memset(buffer, 0, sizeof(buffer)); From 97ea6ee3ab71bbe11b00f540510f2a71380f80a7 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Thu, 17 Feb 2022 13:35:31 +0800 Subject: [PATCH 37/90] Refine the code to reduce the scope of change. --- indigo_api_callback_dut.c | 124 +++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 5d6c535..d1db926 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -1662,83 +1662,85 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra strcat(buffer, cfg_item); } } - } else { - /* Configure network profile only for Non-WPS case */ + /* WPS: no network profile configuration and return. */ + goto done; + } - strcat(buffer, "network={\n"); + strcat(buffer, "network={\n"); #ifdef _RESERVED_ - /* The function is reserved for the defeault wpas config */ - append_wpas_network_default_config(wrapper); + /* The function is reserved for the defeault wpas config */ + append_wpas_network_default_config(wrapper); #endif /* _RESERVED_ */ - for (i = 0; i < wrapper->tlv_num; i++) { - cfg = find_tlv_config(wrapper->tlv[i]->id); - if (cfg && find_wpas_global_config_name(wrapper->tlv[i]->id) == NULL) { - memset(value, 0, sizeof(value)); - memcpy(value, wrapper->tlv[i]->value, wrapper->tlv[i]->len); - - if ((wrapper->tlv[i]->id == TLV_IEEE80211_W) || (wrapper->tlv[i]->id == TLV_STA_IEEE80211_W)) { - ieee80211w_configured = 1; - } else if (wrapper->tlv[i]->id == TLV_KEY_MGMT) { - if (strstr(value, "WPA-PSK") && strstr(value, "SAE")) { - transition_mode_enabled = 1; - } - if (!strstr(value, "WPA-PSK") && strstr(value, "SAE")) { - sae_only = 1; - } + for (i = 0; i < wrapper->tlv_num; i++) { + cfg = find_tlv_config(wrapper->tlv[i]->id); + if (cfg && find_wpas_global_config_name(wrapper->tlv[i]->id) == NULL) { + memset(value, 0, sizeof(value)); + memcpy(value, wrapper->tlv[i]->value, wrapper->tlv[i]->len); - if (strstr(value, "OWE")) { - owe_configured = 1; - } - } else if ((wrapper->tlv[i]->id == TLV_CA_CERT) && strcmp("DEFAULT", value) == 0) { - sprintf(value, "/etc/ssl/certs/ca-certificates.crt"); - } else if ((wrapper->tlv[i]->id == TLV_PAC_FILE)) { - memset(pac_file_path, 0, sizeof(pac_file_path)); - snprintf(pac_file_path, sizeof(pac_file_path), "%s", value); - } else if (wrapper->tlv[i]->id == TLV_SERVER_CERT) { - memset(buf, 0, sizeof(buf)); - get_server_cert_hash(value, buf); - memcpy(value, buf, sizeof(buf)); + if ((wrapper->tlv[i]->id == TLV_IEEE80211_W) || (wrapper->tlv[i]->id == TLV_STA_IEEE80211_W)) { + ieee80211w_configured = 1; + } else if (wrapper->tlv[i]->id == TLV_KEY_MGMT) { + if (strstr(value, "WPA-PSK") && strstr(value, "SAE")) { + transition_mode_enabled = 1; + } + if (!strstr(value, "WPA-PSK") && strstr(value, "SAE")) { + sae_only = 1; } - if (cfg->quoted) { - sprintf(cfg_item, "%s=\"%s\"\n", cfg->config_name, value); - strcat(buffer, cfg_item); - } else { - sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); - strcat(buffer, cfg_item); + if (strstr(value, "OWE")) { + owe_configured = 1; } + } else if ((wrapper->tlv[i]->id == TLV_CA_CERT) && strcmp("DEFAULT", value) == 0) { + sprintf(value, "/etc/ssl/certs/ca-certificates.crt"); + } else if ((wrapper->tlv[i]->id == TLV_PAC_FILE)) { + memset(pac_file_path, 0, sizeof(pac_file_path)); + snprintf(pac_file_path, sizeof(pac_file_path), "%s", value); + } else if (wrapper->tlv[i]->id == TLV_SERVER_CERT) { + memset(buf, 0, sizeof(buf)); + get_server_cert_hash(value, buf); + memcpy(value, buf, sizeof(buf)); } - } - if (ieee80211w_configured == 0) { - if (transition_mode_enabled) { - strcat(buffer, "ieee80211w=1\n"); - } else if (sae_only) { - strcat(buffer, "ieee80211w=2\n"); - } else if (owe_configured) { - strcat(buffer, "ieee80211w=2\n"); + if (cfg->quoted) { + sprintf(cfg_item, "%s=\"%s\"\n", cfg->config_name, value); + strcat(buffer, cfg_item); + } else { + sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); + strcat(buffer, cfg_item); } } + } + + if (ieee80211w_configured == 0) { + if (transition_mode_enabled) { + strcat(buffer, "ieee80211w=1\n"); + } else if (sae_only) { + strcat(buffer, "ieee80211w=2\n"); + } else if (owe_configured) { + strcat(buffer, "ieee80211w=2\n"); + } + } - /* TODO: merge another file */ - /* python source code: - if merge_config_file: - appended_supplicant_conf_str = "" - existing_conf = StaCommandHelper.get_existing_supplicant_conf() - wpa_supplicant_dict = StaCommandHelper.__convert_config_str_to_dict(config = wps_config) - for each_key in existing_conf: - if each_key not in wpa_supplicant_dict: - wpa_supplicant_dict[each_key] = existing_conf[each_key] + /* TODO: merge another file */ + /* python source code: + if merge_config_file: + appended_supplicant_conf_str = "" + existing_conf = StaCommandHelper.get_existing_supplicant_conf() + wpa_supplicant_dict = StaCommandHelper.__convert_config_str_to_dict(config = wps_config) + for each_key in existing_conf: + if each_key not in wpa_supplicant_dict: + wpa_supplicant_dict[each_key] = existing_conf[each_key] - for each_supplicant_conf in wpa_supplicant_dict: - appended_supplicant_conf_str += each_supplicant_conf + "=" + wpa_supplicant_dict[each_supplicant_conf] + "\n" - wps_config = appended_supplicant_conf_str.rstrip() - */ + for each_supplicant_conf in wpa_supplicant_dict: + appended_supplicant_conf_str += each_supplicant_conf + "=" + wpa_supplicant_dict[each_supplicant_conf] + "\n" + wps_config = appended_supplicant_conf_str.rstrip() + */ - strcat(buffer, "}\n"); - } + strcat(buffer, "}\n"); + +done: return strlen(buffer); } From acf20a0f6c64ee827734fe72f13a16ae9a137bff Mon Sep 17 00:00:00 2001 From: Kenny Date: Thu, 17 Feb 2022 16:11:18 +0800 Subject: [PATCH 38/90] ITS-2065 Support test case 10526_1 --- hs2_profile.h | 2 +- indigo_api_callback_tp.c | 8 +++++--- utils.c | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index d4068c2..9264903 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -65,7 +65,7 @@ const char * hs20_wan_metrics[] = { "hs20_wan_metrics=01:2500:384:0:0:10\n", "", "hs20_wan_metrics=01:2000:1000:20:20:10\n", - "", + "hs20_wan_metrics=01:8000:1000:20:20:10\n", "", }; diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index d9c67a5..2467865 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -772,6 +772,7 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr struct tlv_hdr *tlv = NULL; char *ifname = NULL; char *message = TLV_VALUE_ASSIGN_STATIC_IP_OK; + char message_buf[S_BUFFER_LEN]; memset(buffer, 0, sizeof(buffer)); tlv = find_wrapper_tlv_by_id(req, TLV_STATIC_IP); @@ -794,9 +795,12 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr control_interface(ifname, "up"); /* Set IP address with network mask */ strcat(buffer, "/24"); - len = set_interface_ip(get_wireless_interface(), buffer); + len = set_interface_ip(ifname, buffer); if (len) { message = TLV_VALUE_ASSIGN_STATIC_IP_NOT_OK; + } else { + snprintf(message_buf, sizeof(message_buf), "Static IP successfully assigned to interface %s", ifname); + message = message_buf; } response: @@ -821,8 +825,6 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe char *message = TLV_VALUE_NOT_OK; char role[16]; - printf("req->tlv_num %d\n", req->tlv_num); //remove me - memset(&bss_info, 0, sizeof(bss_info)); tlv = find_wrapper_tlv_by_id(req, TLV_BSS_IDENTIFIER); if (tlv) { diff --git a/utils.c b/utils.c index 0b80754..af0202d 100644 --- a/utils.c +++ b/utils.c @@ -482,7 +482,9 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet timeout.tv_sec = 1; timeout.tv_usec = 0; } - if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) + if (is_bridge_created()) { + snprintf(ifname, sizeof(ifname), "%s", get_wlans_bridge()); + } else if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); const int len = strnlen(ifname, IFNAMSIZ); if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, ifname, len) < 0) { From 89509b054e59afa54fc8f21b5c6f11674f6e7220 Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 18 Feb 2022 10:58:29 +0800 Subject: [PATCH 39/90] Make set_sta_parameter work --- indigo_api.c | 1 + indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 40 +++++++++++++++++++-------------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index ef1b403..7d60def 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -229,6 +229,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_REALM, "REALM" }, { TLV_IMSI, "IMSI" }, { TLV_MILENAGE, "MILENAGE" }, + { TLV_BSSID_FILTER_LIST, "BSSID_FILTER_LIST" }, { TLV_PPSMO_FILE, "PPSMO_FILE" }, { TLV_OSU_SERVER_URI, "OSU_SERVER_URI" }, { TLV_OSU_METHOD, "OSU_METHOD" }, diff --git a/indigo_api_callback.h b/indigo_api_callback.h index ce0a085..2a5be34 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -130,6 +130,7 @@ struct tlv_to_config_name maps[] = { { TLV_REALM, "realm", 0 }, { TLV_IMSI, "imsi", 0 }, { TLV_MILENAGE, "milenage", 0 }, + { TLV_BSSID_FILTER_LIST, "bssid_filter", 0 }, /* hapd + wpas */ { TLV_EAP_FRAG_SIZE, "fragment_size", 0 }, diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index d1db926..2521487 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -1876,7 +1876,7 @@ static int send_sta_reconnect_handler(struct packet_wrapper *req, struct packet_ } static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - int status = TLV_VALUE_STATUS_NOT_OK; + int status = TLV_VALUE_STATUS_NOT_OK, i; size_t resp_len; char *message = NULL; char buffer[BUFFER_LEN]; @@ -1895,29 +1895,27 @@ static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_w goto done; } - /* Example: Use TLV_STA_IEEE80211_W. Change to corresponding TLV from Tool */ - memset(param_value, 0, sizeof(param_value)); - tlv = find_wrapper_tlv_by_id(req, TLV_STA_IEEE80211_W); - if (tlv && find_tlv_config_name(tlv->id) != NULL) { + for (i = 0; i < req->tlv_num; i++) { + memset(param_name, 0, sizeof(param_name)); + memset(param_value, 0, sizeof(param_value)); + tlv = req->tlv[i]; strcpy(param_name, find_tlv_config_name(tlv->id)); memcpy(param_value, tlv->value, tlv->len); - } else { - status = TLV_VALUE_STATUS_NOT_OK; - message = TLV_VALUE_INSUFFICIENT_TLV; - indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: STA_IEEE80211_W"); - goto done; - } - /* Assemble wpa_supplicant command */ - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "SET %s %s", param_name, param_value); - /* Send command to wpa_supplicant UDS socket */ - resp_len = sizeof(response) - 1; - wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); - /* Check response */ - if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { - indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); - goto done; + + /* Assemble wpa_supplicant command */ + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "SET %s %s", param_name, param_value); + /* Send command to wpa_supplicant UDS socket */ + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + message = TLV_VALUE_WPA_SET_PARAMETER_NO_OK; + goto done; + } } + status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; done: From d9cf45f86b4feebe8c5e4b02a9f46339bba78c79 Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Fri, 18 Feb 2022 13:56:45 +0800 Subject: [PATCH 40/90] Fixed typo for network auth type config --- hs2_profile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hs2_profile.h b/hs2_profile.h index 9264903..01d137b 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -51,7 +51,7 @@ const char * venue_name[] = { const char * network_auth_type[] = { "", - "network_auth_type=00https://tandc-server.wi-fi.org/\n", + "network_auth_type=00https://tandc-server.wi-fi.org\n", "network_auth_type=01\n", }; From 4c6b0b3506e8923722cd634cde728dfd3ec24ebb Mon Sep 17 00:00:00 2001 From: Kenny Date: Mon, 21 Feb 2022 17:12:57 +0800 Subject: [PATCH 41/90] Support test case 10529_1, 10530_1, and 10531_1 --- hs2_profile.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index 01d137b..d1d0fd4 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -63,10 +63,10 @@ const char * ipaddr_type_avail[] = { const char * hs20_wan_metrics[] = { "", "hs20_wan_metrics=01:2500:384:0:0:10\n", - "", + "hs20_wan_metrics=01:1500:384:20:20:10\n", "hs20_wan_metrics=01:2000:1000:20:20:10\n", "hs20_wan_metrics=01:8000:1000:20:20:10\n", - "", + "hs20_wan_metrics=01:9000:5000:20:20:10\n", }; const char * hs20_conn_capab[] = { From da4c49a4ed8e678a9963e7fe8510743cafc65771 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 22 Feb 2022 16:09:48 +0800 Subject: [PATCH 42/90] ITS-2108 Fix icmp issue on multiple AP wlans --- utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index af0202d..a2242e9 100644 --- a/utils.c +++ b/utils.c @@ -587,13 +587,16 @@ int send_icmp_data(char *target_ip, int packet_count, int packet_size, double ra timeout.tv_usec = 0; } - if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) + if (is_bridge_created()) { + snprintf(ifname, sizeof(ifname), "%s", get_wlans_bridge()); + } else if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); const int len = strnlen(ifname, IFNAMSIZ); if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, ifname, len) < 0) { indigo_logger(LOG_LEVEL_ERROR, "failed to bind the interface %s", ifname); return -1; } + indigo_logger(LOG_LEVEL_DEBUG, "Bind the interface %s", ifname); setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (const char *)&timeout, sizeof(timeout)); setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)); From 4fe90d3358ed4d816d1fc46532cf07671552b413 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 22 Feb 2022 16:11:34 +0800 Subject: [PATCH 43/90] ITS-2071 Support CONNECTION CAPABILITY test case --- hs2_profile.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index d1d0fd4..a1d39c8 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -73,8 +73,8 @@ const char * hs20_conn_capab[] = { "", "hs20_conn_capab=6:20:1\nhs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\nhs20_conn_capab=50:0:1\n", "", - "", - "", + "hs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\n", + "hs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\nhs20_conn_capab=6:5060:1\nhs20_conn_capab=17:5060:1\n", "", }; From d17d09b198f27e17aaf88ebdfaa1cc78713ef4e8 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 22 Feb 2022 17:22:23 +0800 Subject: [PATCH 44/90] ITS-2074 Support BSS LOAD --- hs2_profile.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index a1d39c8..4ffaec3 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -104,9 +104,9 @@ const char * osu_providers_nai_list[] = { const char * bss_load[] = { "", - "", - "", - "", + "bss_load_test=1:50:65535\n", + "bss_load_test=1:200:65535\n", + "bss_load_test=1:75:65535\n", }; const char * venue_url[] = { From 27c610c2d64f273e3cd5cd094ff13077aac6d2dd Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Wed, 23 Feb 2022 11:08:15 +0800 Subject: [PATCH 45/90] Support HS20R3 ANQP element configurations --- hs2_profile.h | 45 +++++++++++++++++++++++++++++++++++---- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback_dut.c | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index 4ffaec3..ccfeeed 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -26,6 +26,37 @@ struct tlv_to_profile { int size; }; +#define ADVICE_OF_CHARGE_1 \ +"bc01000000d200454e475553443c3f786d6c2076657273696f6e3d22312e30222065" \ +"6e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f77" \ +"77772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f" \ +"74302f76312e302f616f637069223e3c4465736372697074696f6e3e57692d46692061636365" \ +"737320666f72203120686f75722c207768696c6520796f752077616974206174207468652067" \ +"6174652c2024302e39393c2f4465736372697074696f6e3e3c2f506c616e3ee3004652414341" \ +"443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f" \ +"3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f72672f737065" \ +"63696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f637069223e3c" \ +"4465736372697074696f6e3e416363c3a8732057692d46692070656e64616e74203120686575" \ +"72652c2070656e64616e742071756520766f757320617474656e64657a20c3a0206c6120706f" \ +"7274652c20302c393920243c2f4465736372697074696f6e3e3c2f506c616e3ea101010000c7" \ +"00454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d2255" \ +"54462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f" \ +"72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f" \ +"637069223e3c4465736372697074696f6e3e446f776e6c6f616420766964656f7320666f7220" \ +"796f757220666c696768742c2024322e393920666f7220313047423c2f446573637269707469" \ +"6f6e3e3c2f506c616e3ed3004652414341443c3f786d6c2076657273696f6e3d22312e302220" \ +"656e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f" \ +"7777772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f743264" \ +"6f74302f76312e302f616f637069223e3c4465736372697074696f6e3e54c3a96cc3a9636861" \ +"7267657a2064657320766964c3a96f7320706f757220766f74726520766f6c2c20322c393920" \ +"2420706f757220313020476f3c2f4465736372697074696f6e3e3c2f506c616e3ee40003002b" \ +"736572766963652d70726f76696465722e636f6d3b66656465726174696f6e2e6578616d706c" \ +"652e636f6db400454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64" \ +"696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77" \ +"692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76" \ +"312e302f616f637069223e3c4465736372697074696f6e3e46726565207769746820796f7572" \ +"20737562736372697074696f6e213c2f4465736372697074696f6e3e3c2f506c616e3e" + const char * nai_realm[] = { "", "nai_realm=0,mail.example.com,21[2:4][5:7]\nnai_realm=0,cisco.com,21[2:4][5:7]\nnai_realm=0,wi-fi.org,13[5:6],21[2:4][5:7]\nnai_realm=0,example.com,13[5:6]\n", @@ -96,7 +127,7 @@ const char * osu_providers_list[] = { const char * osu_providers_nai_list[] = { "", - "", + "osu_nai2=anonymous@hotspot.net\n", "", "", "", @@ -111,18 +142,23 @@ const char * bss_load[] = { const char * venue_url[] = { "", - "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\nvenue_url=2:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n", + "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\nvenue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n", "", }; const char * operator_icon_metadata[] = { "", - "operator_icon=icon_red_eng\n", + "operator_icon=icon_red_eng.png\n", +}; + +const char * advice_of_charge[] = { + "", + "anqp_elem=278:" ADVICE_OF_CHARGE_1 "\n", }; // ::::: const char * hs20_icon[] = { - "hs20_icon=160:76:eng:image/png:icon_red_eng:/overlay/icon_red_eng.png\n", + "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/overlay/icon_red_eng.png\n", }; struct tlv_to_profile hs2_profile[] = { @@ -139,6 +175,7 @@ struct tlv_to_profile hs2_profile[] = { { TLV_BSSLOAD_ENABLE, bss_load, ARRAY_SIZE(bss_load) }, { TLV_OPERATOR_ICON_METADATA, operator_icon_metadata, ARRAY_SIZE(operator_icon_metadata) }, { TLV_HS20_OPERATING_CLASS_INDICATION, operating_class_indication, ARRAY_SIZE(operating_class_indication) }, + { TLV_ADVICE_OF_CHARGE, advice_of_charge, ARRAY_SIZE(advice_of_charge) }, }; struct tlv_to_profile* find_tlv_hs2_profile(int tlv_id) { diff --git a/indigo_api.c b/indigo_api.c index 7d60def..26fa497 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -243,6 +243,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_UPDATE_CONFIG, "UPDATE_CONFIG" }, { TLV_EAP_FRAG_SIZE, "EAP_FRAG_SIZE" }, { TLV_PERFORM_WPS_IE_FRAG, "PERFORM_WPS_IE_FRAG" }, + { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index ccfb3fa..44ee267 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -253,6 +253,7 @@ struct indigo_api { #define TLV_UPDATE_CONFIG 0x00cd #define TLV_EAP_FRAG_SIZE 0x00ce #define TLV_PERFORM_WPS_IE_FRAG 0x00cf +#define TLV_ADVICE_OF_CHARGE 0x00d0 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 2521487..3577b85 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -281,7 +281,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int channel = 0, chwidth = 1, enable_ax = 0, chwidthset = 0, enable_muedca = 0, vht_chwidthset = 0; int i, enable_ac = 0, enable_11h = 0, enable_hs20 = 0; int enable_wps = 0, use_mbss = 0; - char buffer[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN]; + char buffer[S_BUFFER_LEN], cfg_item[2*BUFFER_LEN]; char band[64], value[16]; char country[16]; struct tlv_to_config_name* cfg = NULL; From 46c9fbca1931d47c328a5fe8714d6f2df3489a49 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Wed, 23 Feb 2022 13:48:26 +0800 Subject: [PATCH 46/90] Support DUT P2P_INVITE API --- indigo_api.c | 1 + indigo_api.h | 2 ++ indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 55 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index 7d60def..7edc12c 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -61,6 +61,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_CONNECT, "P2P_CONNECT", NULL, NULL }, { API_P2P_GET_INTENT_VALUE, "P2P_GET_INTENT_VALUE", NULL, NULL }, { API_STA_START_WPS, "STA_START_WPS", NULL, NULL }, + { API_P2P_INVITE, "P2P_INVITE", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index ccfb3fa..2c16f9f 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -75,6 +75,7 @@ struct indigo_api { #define API_P2P_GET_INTENT_VALUE 0x2015 #define API_STA_START_WPS 0x2016 #define API_STA_INSTALL_PPSMO 0x2017 +#define API_P2P_INVITE 0x2018 #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -335,6 +336,7 @@ struct indigo_api { #define TLV_VALUE_P2P_ADD_GROUP_NOT_OK "Failed to add P2P group" #define TLV_VALUE_P2P_START_WPS_NOT_OK "Failed to start WPS on GO interface" #define TLV_VALUE_P2P_CONNECT_NOT_OK "Failed to trigger P2P connect" +#define TLV_VALUE_P2P_INVITE_NOT_OK "Failed to invite P2P device" #define TLV_VALUE_HS2_INSTALL_PPSMO_OK "PPSMO file is installed" #define TLV_VALUE_HS2_INSTALL_PPSMO_NOT_OK "Failed to install PPSMO file" diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 2a5be34..08ca071 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -272,4 +272,5 @@ static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapp static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); #endif // __INDIGO_API_CALLBACK diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 2521487..282b64f 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -79,6 +79,7 @@ void register_apis() { register_api(API_P2P_START_WPS, NULL, start_wps_p2p_handler); register_api(API_P2P_CONNECT, NULL, connect_p2p_handler); register_api(API_P2P_GET_INTENT_VALUE, NULL, get_intent_value_p2p_handler); + register_api(API_P2P_INVITE, NULL, invite_p2p_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -3077,3 +3078,57 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe } return 0; } + +static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + char addr[32], if_name[16]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_INVITE_NOT_OK; + struct tlv_hdr *tlv = NULL; + + memset(addr, 0, sizeof(addr)); + /* TLV_ADDRESS (required) */ + tlv = find_wrapper_tlv_by_id(req, TLV_ADDRESS); + if (tlv) { + memcpy(addr, tlv->value, tlv->len); + } else { + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_INSUFFICIENT_TLV; + indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ADDRESS"); + goto done; + } + get_p2p_group_if(if_name, sizeof(if_name)); + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "P2P_INVITE group=%s peer=%s", if_name, addr); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} From d20199676f7837f465848ac49c610f0a6f299dc5 Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 23 Feb 2022 13:53:37 +0800 Subject: [PATCH 47/90] ITT-1179 Fix false alarm on Test Tool --- indigo_api_callback_tp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 5ed16b6..2bcfe35 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -81,6 +81,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re char buffer[S_BUFFER_LEN], reset_type[16]; char *parameter[] = {"pidof", get_hapd_exec_file(), NULL}; char *message = NULL; + int status = TLV_VALUE_STATUS_NOT_OK; struct tlv_hdr *tlv = NULL; /* TLV: RESET_TYPE */ @@ -109,6 +110,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re message = TLV_VALUE_HOSTAPD_STOP_NOT_OK; } else { message = TLV_VALUE_HOSTAPD_STOP_OK; + status = TLV_VALUE_STATUS_OK; } /* Test case teardown case */ @@ -156,7 +158,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re } fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); - fill_wrapper_tlv_byte(resp, TLV_STATUS, len == 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); return 0; From f02324e06132aefee55b5b64afffa1de1bb9f48f Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 23 Feb 2022 17:20:17 +0800 Subject: [PATCH 48/90] ITS-2064 Add test case 10525_1 --- indigo_api_callback_tp.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 2bcfe35..8572f6f 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -130,10 +130,10 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re stop_loopback_data(NULL); - /* reset interfaces info */ - clear_interfaces_resource(); - if (reset == RESET_TYPE_INIT) { + /* reset interfaces info */ + clear_interfaces_resource(); + len = unlink(get_hapd_conf_file()); if (len) { indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove hostapd.conf"); @@ -717,6 +717,10 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r int len; struct tlv_hdr *tlv; int swap_hostapd = 0; + struct bss_identifier_info bss_info; + char bss_identifier_str[16]; + int bss_identifier = 0; + struct interface_info* wlan = NULL; sprintf(g_ctrl_iface, "%s", get_hapd_global_ctrl_path()); @@ -727,6 +731,21 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r memcpy(log_level, tlv->value, tlv->len); } + memset(&bss_info, 0, sizeof(bss_info)); + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_IDENTIFIER); + if (tlv) { + memset(bss_identifier_str, 0, sizeof(bss_identifier_str)); + memcpy(bss_identifier_str, tlv->value, tlv->len); + bss_identifier = atoi(bss_identifier_str); + parse_bss_identifier(bss_identifier, &bss_info); + + indigo_logger(LOG_LEVEL_DEBUG, "TLV_BSS_IDENTIFIER 0x%x identifier %d band %d\n", + bss_identifier, + bss_info.identifier, + bss_info.band); + wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); + } + if (strlen(log_level)) { set_hostapd_debug_level(get_debug_level(atoi(log_level))); } @@ -769,7 +788,8 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r g_ctrl_iface, get_hostapd_debug_arguments(), HAPD_LOG_FILE, - get_all_hapd_conf_files(&swap_hostapd)); + wlan ? wlan->hapd_conf_file :get_all_hapd_conf_files(&swap_hostapd)); + indigo_logger(LOG_LEVEL_DEBUG, "%s", buffer); len = system(buffer); sleep(1); From aab80776c277d6eda5ee08ae538fecd9a9ed0283 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Thu, 24 Feb 2022 10:56:30 +0800 Subject: [PATCH 49/90] Check the result of getting P2P Group IF --- indigo_api_callback_dut.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 282b64f..96102df 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -3099,7 +3099,10 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ADDRESS"); goto done; } - get_p2p_group_if(if_name, sizeof(if_name)); + if (get_p2p_group_if(if_name, sizeof(if_name)) != 0) { + message = "Failed to get P2P Group Interface"; + goto done; + } /* Open wpa_supplicant UDS socket */ w = wpa_ctrl_open(get_wpas_ctrl_path()); From 96f7b478f4edc01ca1b1d217012176b023c56a50 Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 25 Feb 2022 11:03:58 +0800 Subject: [PATCH 50/90] ITS-2062 Add test case 10523_1 --- main.c | 2 +- vendor_specific.h | 4 ++-- vendor_specific_tp.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index c34fc48..4ef5ff1 100755 --- a/main.c +++ b/main.c @@ -191,7 +191,7 @@ static void print_welcome() { /* Parse the commandline parameters */ static int parse_parameters(int argc, char *argv[]) { int c, ifs_configured = 0, bridge_configured = 0; - char buf[128]; + char buf[256]; #ifdef _VERSION_ while ((c = getopt(argc, argv, "a:b:s:i:hp:dcv")) != -1) { diff --git a/vendor_specific.h b/vendor_specific.h index 7bf5138..ca2b9d8 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -43,8 +43,8 @@ #define WPAS_CONF_FILE_DEFAULT "/tmp/wpa_supplicant.conf" // 2(2.4G): first interface ath1, second interface ath11 // 5(5G): first interface ath0, second interface ath01 -#define DEFAULT_APP_INTERFACES_PARAMS "2:ath1,2:ath11,5:ath0,5:ath01" -#define DEFAULT_APP_6E_INTERFACES_PARAMS "6:ath0,6:ath01,5:ath1,5:ath11,2:ath2,2:ath21" +#define DEFAULT_APP_INTERFACES_PARAMS "2:ath1,2:ath11,2:ath12,2:ath13,5:ath0,5:ath01,5:ath02,5:ath03" +#define DEFAULT_APP_6E_INTERFACES_PARAMS "6:ath0,6:ath01,6:ath02,6:ath03,5:ath1,5:ath11,5:ath12,5:ath13,2:ath2,2:ath21,2:ath22,2:ath23" #else #define HAPD_CONF_FILE_DEFAULT "/etc/hostapd/hostapd.conf" diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index a9a3b76..6aae23b 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -114,7 +114,6 @@ void interfaces_init() { char buffer[BUFFER_LEN]; char mac_addr[S_BUFFER_LEN]; int third_radio = 0; - third_radio = detect_third_radio(); memset(buffer, 0, sizeof(buffer)); @@ -122,15 +121,27 @@ void interfaces_init() { system(buffer); sprintf(buffer, "iw phy phy1 interface add ath11 type managed >/dev/null 2>/dev/null"); system(buffer); + sprintf(buffer, "iw phy phy1 interface add ath12 type managed >/dev/null 2>/dev/null"); + system(buffer); + sprintf(buffer, "iw phy phy1 interface add ath13 type managed >/dev/null 2>/dev/null"); + system(buffer); sprintf(buffer, "iw phy phy0 interface add ath0 type managed >/dev/null 2>/dev/null"); system(buffer); sprintf(buffer, "iw phy phy0 interface add ath01 type managed >/dev/null 2>/dev/null"); system(buffer); + sprintf(buffer, "iw phy phy0 interface add ath02 type managed >/dev/null 2>/dev/null"); + system(buffer); + sprintf(buffer, "iw phy phy0 interface add ath03 type managed >/dev/null 2>/dev/null"); + system(buffer); if (third_radio == 1) { sprintf(buffer, "iw phy phy2 interface add ath2 type managed >/dev/null 2>/dev/null"); system(buffer); sprintf(buffer, "iw phy phy2 interface add ath21 type managed >/dev/null 2>/dev/null"); system(buffer); + sprintf(buffer, "iw phy phy2 interface add ath22 type managed >/dev/null 2>/dev/null"); + system(buffer); + sprintf(buffer, "iw phy phy2 interface add ath23 type managed >/dev/null 2>/dev/null"); + system(buffer); } memset(mac_addr, 0, sizeof(mac_addr)); @@ -143,6 +154,14 @@ void interfaces_init() { mac_addr[16] = (char)'1'; set_mac_address("ath11", mac_addr); + control_interface("ath12", "down"); + mac_addr[16] = (char)'2'; + set_mac_address("ath12", mac_addr); + + control_interface("ath13", "down"); + mac_addr[16] = (char)'3'; + set_mac_address("ath13", mac_addr); + memset(mac_addr, 0, sizeof(mac_addr)); get_mac_address(mac_addr, sizeof(mac_addr), "ath0"); control_interface("ath0", "down"); @@ -153,6 +172,14 @@ void interfaces_init() { mac_addr[16] = (char)'1'; set_mac_address("ath01", mac_addr); + control_interface("ath02", "down"); + mac_addr[16] = (char)'2'; + set_mac_address("ath02", mac_addr); + + control_interface("ath03", "down"); + mac_addr[16] = (char)'3'; + set_mac_address("ath03", mac_addr); + if (third_radio == 1) { memset(mac_addr, 0, sizeof(mac_addr)); get_mac_address(mac_addr, sizeof(mac_addr), "ath2"); @@ -163,6 +190,14 @@ void interfaces_init() { control_interface("ath21", "down"); mac_addr[16] = (char)'9'; set_mac_address("ath21", mac_addr); + + control_interface("ath22", "down"); + mac_addr[16] = (char)'A'; + set_mac_address("ath22", mac_addr); + + control_interface("ath23", "down"); + mac_addr[16] = (char)'B'; + set_mac_address("ath23", mac_addr); } sleep(1); #endif From b071f2843560f38fbb07512f3627949d533368f8 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 25 Feb 2022 13:35:58 +0800 Subject: [PATCH 51/90] Dynamic config_methods support for DUT. --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback_dut.c | 49 ++++++++++++++++++++++++++++++++++++++- vendor_specific.h | 7 +++++- vendor_specific_dut.c | 23 +++++++++++++++--- vendor_specific_tp.c | 8 +++---- 6 files changed, 80 insertions(+), 9 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 5956691..3847448 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -245,6 +245,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_EAP_FRAG_SIZE, "EAP_FRAG_SIZE" }, { TLV_PERFORM_WPS_IE_FRAG, "PERFORM_WPS_IE_FRAG" }, { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, + { TLV_WSC_CONFIG_METHOD, "WSC_CONFIG_METHOD"}, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 9ad4d7e..366c206 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -255,6 +255,7 @@ struct indigo_api { #define TLV_EAP_FRAG_SIZE 0x00ce #define TLV_PERFORM_WPS_IE_FRAG 0x00cf #define TLV_ADVICE_OF_CHARGE 0x00d0 +#define TLV_WSC_CONFIG_METHOD 0x00d1 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 37259f8..65dc107 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -31,7 +31,7 @@ static char pac_file_path[S_BUFFER_LEN] = {0}; struct interface_info* band_transmitter[16]; extern struct sockaddr_in *tool_addr; - +extern conf_method_map CM_map[13]; void register_apis() { /* Basic */ @@ -387,6 +387,8 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (atoi(buffer)) { /* Use OOB */ for (j = 0; j < AP_SETTING_NUM; j++) { + if (0 == strlen(s[j].value)) + continue; memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); strcat(output, cfg_item); @@ -394,6 +396,8 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } else { /* NOT use OOB: Configure manually. */ for (j = 0; j < AP_SETTING_NUM; j++) { + if (0 == strlen(s[j].value)) + continue; memset(cfg_item, 0, sizeof(cfg_item)); if (s[j].attr & WPS_COMMON) { if (strlen(s[j].wkey) == strlen(WPS_OOB_STATE) && @@ -414,6 +418,26 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } } + /* wsc config methods */ + if (tlv->id == TLV_WSC_CONFIG_METHOD) { + int k, len = 0, conf_methods; + int count = sizeof(CM_map)/sizeof(CM_map[0]); + + memcpy(buffer, tlv->value, tlv->len); + conf_methods = atoi(buffer); + memset(buffer, 0, sizeof(buffer)); + indigo_logger(LOG_LEVEL_DEBUG, "APUT config methods: 0x%04X", conf_methods); + for (k = 0; k < count; k++) { + if (conf_methods & CM_map[k].attr_bit) + len += snprintf(buffer + len, sizeof(buffer) - len, "%s ", CM_map[k].name); + } + indigo_logger(LOG_LEVEL_DEBUG, "APUT config methods: %s, len=%d", buffer, len); + if (len) { + sprintf(cfg_item, "config_methods=%s\n", buffer); + strcat(output, cfg_item); + } + } + cfg = find_tlv_config(tlv->id); if (!cfg) { indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id); @@ -1636,6 +1660,7 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra int sae_only = 0; struct tlv_hdr *tlv = NULL; struct tlv_to_config_name* cfg = NULL; + int len = 0, conf_methods = 0, count = 0; sprintf(buffer, "ctrl_interface=%s\nap_scan=1\npmf=1\n", WPAS_CTRL_PATH_DEFAULT); @@ -1649,6 +1674,26 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra } } + /* wsc config methods */ + tlv = find_wrapper_tlv_by_id(wrapper, TLV_WSC_CONFIG_METHOD); + if (tlv) { + count = sizeof(CM_map)/sizeof(CM_map[0]); + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + conf_methods = atoi(value); + memset(buf, 0, sizeof(buf)); + indigo_logger(LOG_LEVEL_DEBUG, "STAUT config methods: 0x%04X", conf_methods); + for (i = 0; i < count; i++) { + if (conf_methods & CM_map[i].attr_bit) + len += snprintf(buf + len, sizeof(buf) - len, "%s ", CM_map[i].name); + } + indigo_logger(LOG_LEVEL_DEBUG, "STAUT config methods: %s, len=%d", buf, len); + if (len) { + sprintf(cfg_item, "config_methods=%s\n", buf); + strcat(buffer, cfg_item); + } + } + /* wps settings */ tlv = find_wrapper_tlv_by_id(wrapper, TLV_WSC_OOB); if (tlv) { @@ -1658,6 +1703,8 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra wps_setting *s = get_vendor_wps_settings(WPS_STA); if (atoi(value)) { for (i = 0; i < STA_SETTING_NUM; i++) { + if (0 == strlen(s[i].value)) + continue; memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); strcat(buffer, cfg_item); diff --git a/vendor_specific.h b/vendor_specific.h index 7bf5138..674dfe8 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -115,7 +115,8 @@ void vendor_device_reset(); #define WPS_OOB_NOT_CONFIGURED "1" #define WPS_OOB_CONFIGURED "2" -#define SUPPORTED_CONF_METHOD "keypad push_button phsical_push_button virtual_push_button display physical_display virtual_display" +#define SUPPORTED_CONF_METHOD_AP "label keypad push_button virtual_push_button display virtual_display" +#define SUPPORTED_CONF_METHOD_STA "keypad push_button virtual_push_button display virtual_display" enum param_attr { WPS_COMMON = 0x0001, @@ -138,6 +139,10 @@ typedef struct _wps_setting { enum param_attr attr; } wps_setting; +typedef struct _conf_method_map { + unsigned int attr_bit; + char *name; +} conf_method_map; #ifdef _TEST_PLATFORM_ diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index e53be63..b785e38 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -380,6 +380,23 @@ void stop_dhcp_client() system("killall dhclient 1>/dev/null 2>/dev/null"); } +conf_method_map CM_map[13] = { + {0x0001, "usba"}, + {0x0002, "ethernet"}, + {0x0004, "label"}, + {0x0008, "display"}, + {0x0010, "ext_nfc_token"}, + {0x0020, "int_nfc_token"}, + {0x0040, "nfc_interface"}, + {0x0080, "pushbutton"}, + {0x0100, "keypad"}, + {0x0200, "virtual_pushbutton"}, + {0x0400, "physical_pushbutton"}, + {0x2000, "virtual_display"}, + {0x4000, "physical_display"}, + +}; + wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { /* @@ -395,7 +412,7 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ - { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_CONFIG, "", WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ @@ -417,7 +434,7 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_COMMON }, /* wps oob state */ - { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_CONFIG, "", WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ @@ -428,7 +445,7 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { }; wps_setting wps_settings_sta[STA_SETTING_NUM] = { - { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_CONFIG, "", WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Intel Wireless STA", WPS_COMMON }, /* device name */ { WPS_MANUFACTURER, "Intel.com", WPS_COMMON }, /* manufacturer */ { WPS_MODEL_NAME, "Intel Wireless STA", WPS_COMMON }, /* model name */ diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index a9a3b76..c41c6a6 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -576,7 +576,7 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ - { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ @@ -598,7 +598,7 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ - { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", WPS_COMMON }, /* manufacturer */ @@ -620,7 +620,7 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_COMMON }, /* wps oob state */ - { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ @@ -631,7 +631,7 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { }; wps_setting wps_settings_sta[STA_SETTING_NUM] = { - { WPS_CONFIG, SUPPORTED_CONF_METHOD, WPS_COMMON }, /* config methods */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_STA, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Intel Wireless STA", WPS_COMMON }, /* device name */ { WPS_MANUFACTURER, "Intel.com", WPS_COMMON }, /* manufacturer */ { WPS_MODEL_NAME, "Intel Wireless STA", WPS_COMMON }, /* model name */ From cfe67c4c68664ee0997a0c9bd734982cad001f86 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 1 Mar 2022 19:59:14 +0800 Subject: [PATCH 52/90] Fix Segmentation fault --- utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.c b/utils.c index a2242e9..8a3a94d 100644 --- a/utils.c +++ b/utils.c @@ -51,7 +51,7 @@ int syslog_level = LOG_LEVEL_INFO; /* multiple VAPs */ int interface_count = 0; int configured_interface_count = 0; -struct interface_info interfaces[8]; +struct interface_info interfaces[16]; int band_mbssid_cnt[16]; struct interface_info* default_interface; static struct loopback_info loopback = {}; From 7b37b465262c4c9187dee1d59832fadf25c6f851 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Wed, 2 Mar 2022 15:55:44 +0800 Subject: [PATCH 53/90] Support P2P_STOP_GROUP and Persistent group --- indigo_api.c | 2 + indigo_api.h | 2 + indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 111 +++++++++++++++++++++++++++++++++++--- vendor_specific.h | 1 + vendor_specific_dut.c | 5 ++ 6 files changed, 115 insertions(+), 7 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 3847448..3a77a78 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -62,6 +62,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_GET_INTENT_VALUE, "P2P_GET_INTENT_VALUE", NULL, NULL }, { API_STA_START_WPS, "STA_START_WPS", NULL, NULL }, { API_P2P_INVITE, "P2P_INVITE", NULL, NULL }, + { API_P2P_STOP_GROUP, "P2P_STOP_GROUP", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, @@ -246,6 +247,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_PERFORM_WPS_IE_FRAG, "PERFORM_WPS_IE_FRAG" }, { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, { TLV_WSC_CONFIG_METHOD, "WSC_CONFIG_METHOD"}, + { TLV_PERSISTENT, "PERSISTENT_GROUP" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 366c206..d71c8e5 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -76,6 +76,7 @@ struct indigo_api { #define API_STA_START_WPS 0x2016 #define API_STA_INSTALL_PPSMO 0x2017 #define API_P2P_INVITE 0x2018 +#define API_P2P_STOP_GROUP 0x2019 #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -256,6 +257,7 @@ struct indigo_api { #define TLV_PERFORM_WPS_IE_FRAG 0x00cf #define TLV_ADVICE_OF_CHARGE 0x00d0 #define TLV_WSC_CONFIG_METHOD 0x00d1 +#define TLV_PERSISTENT 0x00d2 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 08ca071..3bc1ffc 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -269,6 +269,7 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int stop_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 65dc107..e8ada22 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -80,6 +80,7 @@ void register_apis() { register_api(API_P2P_CONNECT, NULL, connect_p2p_handler); register_api(API_P2P_GET_INTENT_VALUE, NULL, get_intent_value_p2p_handler); register_api(API_P2P_INVITE, NULL, invite_p2p_handler); + register_api(API_P2P_STOP_GROUP, NULL, stop_group_p2p_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -2333,6 +2334,86 @@ static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapp return 0; } +static int stop_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + int persist = 0; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_ADD_GROUP_NOT_OK; + struct tlv_hdr *tlv = NULL; + char if_name[32], p2p_dev_if[32]; + + tlv = find_wrapper_tlv_by_id(req, TLV_PERSISTENT); + if (tlv) { + persist = 1; + } + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + if (get_p2p_group_if(if_name, sizeof(if_name)) != 0) { + message = "Failed to get P2P Group Interface"; + goto done; + } + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "P2P_GROUP_REMOVE %s", if_name); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + if (w) { + wpa_ctrl_close(w); + w = NULL; + } + + if (persist == 1) { + get_p2p_dev_if(p2p_dev_if, sizeof(p2p_dev_if)); + indigo_logger(LOG_LEVEL_DEBUG, "P2P Dev IF: %s", p2p_dev_if); + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_if_ctrl_path(p2p_dev_if)); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + /* Clear the persistent group */ + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "REMOVE_NETWORK 0"); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} + static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; @@ -2644,7 +2725,7 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_P2P_CONNECT_NOT_OK; struct tlv_hdr *tlv = NULL; - char go_intent[32], he[16]; + char go_intent[32], he[16], persist[32]; int intent_value = P2P_GO_INTENT; memset(buffer, 0, sizeof(buffer)); @@ -2652,6 +2733,7 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper memset(method, 0, sizeof(method)); memset(type, 0, sizeof(type)); memset(he, 0, sizeof(he)); + memset(persist, 0, sizeof(persist)); tlv = find_wrapper_tlv_by_id(req, TLV_ADDRESS); if (tlv) { memcpy(mac, tlv->value, tlv->len); @@ -2682,6 +2764,10 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper if (tlv) { snprintf(he, sizeof(he), " he"); } + tlv = find_wrapper_tlv_by_id(req, TLV_PERSISTENT); + if (tlv) { + snprintf(persist, sizeof(persist), " persistent"); + } tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); if (tlv) { memset(pin_code, 0, sizeof(pin_code)); @@ -2692,7 +2778,7 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper } else { indigo_logger(LOG_LEVEL_ERROR, "Missed TLV PIN_METHOD???"); } - sprintf(buffer, "P2P_CONNECT %s %s %s%s%s%s", mac, pin_code, method, type, go_intent, he); + sprintf(buffer, "P2P_CONNECT %s %s %s%s%s%s%s", mac, pin_code, method, type, go_intent, he, persist); } else { tlv = find_wrapper_tlv_by_id(req, TLV_WSC_METHOD); if (tlv) { @@ -2700,7 +2786,7 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper } else { indigo_logger(LOG_LEVEL_ERROR, "Missed TLV WSC_METHOD"); } - sprintf(buffer, "P2P_CONNECT %s %s%s%s%s", mac, method, type, go_intent, he); + sprintf(buffer, "P2P_CONNECT %s %s%s%s%s%s", mac, method, type, go_intent, he, persist); } indigo_logger(LOG_LEVEL_DEBUG, "Command: %s", buffer); @@ -3129,7 +3215,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; - char addr[32], if_name[16]; + char addr[32], if_name[16], persist[32], p2p_dev_if[32]; size_t resp_len; int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_P2P_INVITE_NOT_OK; @@ -3146,13 +3232,20 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ADDRESS"); goto done; } - if (get_p2p_group_if(if_name, sizeof(if_name)) != 0) { + + memset(persist, 0, sizeof(persist)); + tlv = find_wrapper_tlv_by_id(req, TLV_PERSISTENT); + if (tlv) { + snprintf(persist, sizeof(persist), "persistent=0"); + } else if (get_p2p_group_if(if_name, sizeof(if_name)) != 0) { message = "Failed to get P2P Group Interface"; goto done; } + get_p2p_dev_if(p2p_dev_if, sizeof(p2p_dev_if)); + indigo_logger(LOG_LEVEL_DEBUG, "P2P Dev IF: %s", p2p_dev_if); /* Open wpa_supplicant UDS socket */ - w = wpa_ctrl_open(get_wpas_ctrl_path()); + w = wpa_ctrl_open(get_wpas_if_ctrl_path(p2p_dev_if)); if (!w) { indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); status = TLV_VALUE_STATUS_NOT_OK; @@ -3162,7 +3255,11 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper memset(buffer, 0, sizeof(buffer)); memset(response, 0, sizeof(response)); - sprintf(buffer, "P2P_INVITE group=%s peer=%s", if_name, addr); + if (persist[0] != 0) + sprintf(buffer, "P2P_INVITE %s peer=%s", persist, addr); + else + sprintf(buffer, "P2P_INVITE group=%s peer=%s", if_name, addr); + indigo_logger(LOG_LEVEL_DEBUG, "Command: %s", buffer); resp_len = sizeof(response) - 1; wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); /* Check response */ diff --git a/vendor_specific.h b/vendor_specific.h index 21e0b3c..6df9a05 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -177,6 +177,7 @@ void start_ap_set_wlan_params(void *if_info); int get_p2p_mac_addr(char *mac_addr, size_t size); int get_p2p_group_if(char *if_name, size_t size); +int get_p2p_dev_if(char *if_name, size_t size); void start_dhcp_server(char *if_name, char *ip_addr); void stop_dhcp_server(); diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index b785e38..d06b769 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -328,6 +328,11 @@ int get_p2p_group_if(char *if_name, size_t size) { return error; } +int get_p2p_dev_if(char *if_name, size_t size) { + snprintf(if_name, size, "p2p-dev-%s", get_wireless_interface()); + + return 0; +} void start_dhcp_server(char *if_name, char *ip_addr) { From 8467a05478b7cd0f00988fd556cf941507d6b94d Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Wed, 2 Mar 2022 17:34:35 +0800 Subject: [PATCH 54/90] Reset IP only when P2P If is existing --- indigo_api_callback_dut.c | 5 +++-- indigo_api_callback_tp.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index e8ada22..b39e059 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -2881,7 +2881,8 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * if (tlv) { memcpy(role, tlv->value, tlv->len); if (atoi(role) == DUT_TYPE_P2PUT) { - get_p2p_group_if(if_name, sizeof(if_name)); + if (!get_p2p_group_if(if_name, sizeof(if_name))) + reset_interface_ip(if_name); } else { indigo_logger(LOG_LEVEL_ERROR, "DHCP only supports in P2PUT"); goto done; @@ -2898,7 +2899,7 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * } else { /* DHCP Client */ stop_dhcp_client(); } - reset_interface_ip(if_name); + status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 8572f6f..f89f533 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1816,7 +1816,8 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * if (tlv) { memcpy(role, tlv->value, tlv->len); if (atoi(role) == DUT_TYPE_P2PUT) { - get_p2p_group_if(if_name, sizeof(if_name)); + if (get_p2p_group_if(if_name, sizeof(if_name))) + reset_interface_ip(if_name); } else { } } else { @@ -1831,7 +1832,6 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * } else { /* DHCP Client */ stop_dhcp_client(); } - reset_interface_ip(if_name); status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; From ea496ad79027df1351b2b566e1299925ddd1afa4 Mon Sep 17 00:00:00 2001 From: Kenny Date: Thu, 3 Mar 2022 16:56:39 +0800 Subject: [PATCH 55/90] ITS-2055 ITS-2056 ITS-2057 Add test cases --- indigo_api.c | 5 ++ indigo_api.h | 6 ++ indigo_api_callback.h | 12 ++-- indigo_api_callback_dut.c | 113 +++++++++++++++++++++++++++++++++++++- 4 files changed, 130 insertions(+), 6 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 3a77a78..fa30b05 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -59,6 +59,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_ADD_GROUP, "P2P_ADD_GROUP", NULL, NULL }, { API_P2P_START_WPS, "P2P_START_WPS", NULL, NULL }, { API_P2P_CONNECT, "P2P_CONNECT", NULL, NULL }, + { API_STA_ADD_CREDENTIAL, "API_STA_ADD_CREDENTIAL", NULL, NULL }, { API_P2P_GET_INTENT_VALUE, "P2P_GET_INTENT_VALUE", NULL, NULL }, { API_STA_START_WPS, "STA_START_WPS", NULL, NULL }, { API_P2P_INVITE, "P2P_INVITE", NULL, NULL }, @@ -116,6 +117,10 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_RESET_TYPE, "RESET_TYPE" }, { APP_TYPE, "APP_TYPE" }, { TLV_IE_OVERRIDE, "IE_OVERRIDE" }, + { TLV_HOME_FQDN, "HOME_FQDN"}, + { TLV_USERNAME, "USERNAME"}, + { TLV_PREFER, "PREFER"}, + { TLV_CREDENTIAL_TYPE, "CREDENTIAL_TYPE"}, { TLV_ADDRESS, "ADDRESS" }, { TLV_DISABLE_PMKSA_CACHING, "DISABLE_PMKSA_CACHING" }, { TLV_SAE_ANTI_CLOGGING_THRESHOLD, "SAE_ANTI_CLOGGING_THRESHOLD" }, diff --git a/indigo_api.h b/indigo_api.h index d71c8e5..1eb7ef4 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -129,6 +129,10 @@ struct indigo_api { #define APP_TYPE 0x0021 #define TLV_OP_CLASS 0x0022 #define TLV_IE_OVERRIDE 0x0023 +#define TLV_HOME_FQDN 0x0024 +#define TLV_USERNAME 0x0025 +#define TLV_PREFER 0x0026 +#define TLV_CREDENTIAL_TYPE 0x0027 #define TLV_ADDRESS 0x0028 #define TLV_DISABLE_PMKSA_CACHING 0x0033 #define TLV_SAE_ANTI_CLOGGING_THRESHOLD 0x0034 @@ -318,6 +322,8 @@ struct indigo_api { #define TLV_VALUE_WPA_S_START_UP_OK "wpa_supplicant is initialized successfully" #define TLV_VALUE_WPA_S_START_UP_NOT_OK "The wpa_supplicant was unable to initialize." +#define TLV_VALUE_WPA_S_ADD_CRED_OK "Add credential to the STA successfully" +#define TLV_VALUE_WPA_S_ADD_CRED_NOT_OK "Failed to add credential to the STA." #define TLV_VALUE_WPA_S_STOP_NOT_OK "Failed to stop wpa supplicant service." #define TLV_VALUE_WPA_S_STOP_OK "QuickTrack tool STA was successfully disconnected" #define TLV_VALUE_WPA_S_ASSOC_OK "STA is up: WPA supplicant associated" diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 3bc1ffc..42203ae 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -127,10 +127,13 @@ struct tlv_to_config_name maps[] = { { TLV_PAC_FILE, "pac_file", 1 }, { TLV_STA_OWE_GROUP, "owe_group", 0 }, { TLV_BSSID, "bssid", 0 }, - { TLV_REALM, "realm", 0 }, - { TLV_IMSI, "imsi", 0 }, - { TLV_MILENAGE, "milenage", 0 }, + { TLV_REALM, "realm", 1 }, + { TLV_IMSI, "imsi", 1 }, + { TLV_MILENAGE, "milenage", 1 }, { TLV_BSSID_FILTER_LIST, "bssid_filter", 0 }, + { TLV_USERNAME, "username", 1 }, + { TLV_HOME_FQDN, "domain", 1 }, + { TLV_PREFER, "priority", 0 }, /* hapd + wpas */ { TLV_EAP_FRAG_SIZE, "fragment_size", 0 }, @@ -256,9 +259,10 @@ static int send_sta_disconnect_handler(struct packet_wrapper *req, struct packet static int send_sta_reconnect_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int send_sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_hs2_associate_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int sta_add_credential_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_phy_mode_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_channel_width_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index b39e059..c4e4ab3 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -32,6 +32,8 @@ static char pac_file_path[S_BUFFER_LEN] = {0}; struct interface_info* band_transmitter[16]; extern struct sockaddr_in *tool_addr; extern conf_method_map CM_map[13]; +int sta_configured = 0; +int sta_started = 0; void register_apis() { /* Basic */ @@ -65,9 +67,10 @@ void register_apis() { register_api(API_STA_SET_PARAM, NULL, set_sta_parameter_handler); register_api(API_STA_SEND_BTM_QUERY, NULL, send_sta_btm_query_handler); register_api(API_STA_SEND_ANQP_QUERY, NULL, send_sta_anqp_query_handler); - register_api(API_STA_SCAN, NULL, send_sta_scan_handler); + register_api(API_STA_SCAN, NULL, sta_scan_handler); register_api(API_STA_START_WPS, NULL, start_wps_sta_handler); register_api(API_STA_HS2_ASSOCIATE, NULL, set_sta_hs2_associate_handler); + register_api(API_STA_ADD_CREDENTIAL, NULL, sta_add_credential_handler); register_api(API_STA_INSTALL_PPSMO, NULL, set_sta_install_ppsmo_handler); /* TODO: Add the handlers */ register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL); @@ -135,6 +138,8 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe if (strlen(log_level)) { set_wpas_debug_level(get_debug_level(atoi(log_level))); } + sta_configured = 0; + sta_started = 0; } else if (atoi(role) == DUT_TYPE_APUT) { /* stop the hostapd and release IP address */ memset(buffer, 0, sizeof(buffer)); @@ -1589,6 +1594,8 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); system(buffer); sleep(2); + sta_configured = 0; + sta_started = 0; /* Test case teardown case */ if (reset == RESET_TYPE_TEARDOWN) { @@ -1802,6 +1809,7 @@ static int configure_sta_handler(struct packet_wrapper *req, struct packet_wrapp memset(buffer, 0, sizeof(buffer)); len = generate_wpas_config(buffer, sizeof(buffer), req); if (len) { + sta_configured = 1; write_file(get_wpas_conf_file(), buffer, len); } @@ -2468,7 +2476,7 @@ static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapp return 0; } -static int send_sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len, status = TLV_VALUE_STATUS_NOT_OK, i; char *message = TLV_VALUE_WPA_S_SCAN_NOT_OK; char buffer[1024]; @@ -2596,6 +2604,107 @@ static int set_sta_hs2_associate_handler(struct packet_wrapper *req, struct pack return 0; } +static int sta_add_credential_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + char *message = TLV_VALUE_WPA_S_ADD_CRED_NOT_OK; + char buffer[BUFFER_LEN]; + int len, status = TLV_VALUE_STATUS_NOT_OK, i, cred_id, wpa_ret; + size_t resp_len; + char response[BUFFER_LEN]; + char param_value[256]; + struct tlv_hdr *tlv = NULL; + struct wpa_ctrl *w = NULL; + struct tlv_to_config_name* cfg = NULL; + + if (sta_configured == 0) { + sta_configured = 1; +#ifdef _OPENWRT_ +#else + system("rfkill unblock wlan"); + sleep(1); +#endif + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + system(buffer); + sleep(3); + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT); + len = strlen(buffer); + if (len) { + write_file(get_wpas_conf_file(), buffer, len); + } + } + if (sta_started == 0) { + sta_started = 1; + /* Start WPA supplicant */ + memset(buffer, 0 ,sizeof(buffer)); + sprintf(buffer, "%s -B -t -c %s %s -i %s -f /var/log/supplicant.log", + get_wpas_full_exec_path(), + get_wpas_conf_file(), + get_wpas_debug_arguments(), + get_wireless_interface()); + len = system(buffer); + sleep(2); + } + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + /* Assemble wpa_supplicant command */ + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "ADD_CRED"); + resp_len = sizeof(response) - 1; + wpa_ret = wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + if (wpa_ret < 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command ADD_CRED. Response: %s", response); + goto done; + } + cred_id = atoi(response); + + for (i = 0; i < req->tlv_num; i++) { + memset(param_value, 0, sizeof(param_value)); + tlv = req->tlv[i]; + cfg = find_tlv_config(tlv->id); + if (!cfg) { + continue; + } + memcpy(param_value, tlv->value, tlv->len); + + /* Assemble wpa_supplicant command */ + memset(buffer, 0, sizeof(buffer)); + + if (cfg->quoted) { + snprintf(buffer, sizeof(buffer), "SET_CRED %d %s \"%s\"", cred_id, cfg->config_name, param_value); + } else { + snprintf(buffer, sizeof(buffer), "SET_CRED %d %s %s", cred_id, cfg->config_name, param_value); + } + indigo_logger(LOG_LEVEL_DEBUG, "Execute the command: %s", buffer); + /* Send command to wpa_supplicant UDS socket */ + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + message = TLV_VALUE_WPA_SET_PARAMETER_NO_OK; + goto done; + } + } + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_WPA_S_ADD_CRED_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + return 0; +} + static int run_hs20_osu_client(const char *params) { char buf[BUFFER_LEN], cmd[S_BUFFER_LEN]; From 62bae101c55a091af7b962256fe166c8578e021f Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Fri, 4 Mar 2022 10:51:23 +0800 Subject: [PATCH 56/90] Add additional UDP setting in connection capability based on test plan --- hs2_profile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hs2_profile.h b/hs2_profile.h index ccfeeed..f10c8f1 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -102,7 +102,7 @@ const char * hs20_wan_metrics[] = { const char * hs20_conn_capab[] = { "", - "hs20_conn_capab=6:20:1\nhs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\nhs20_conn_capab=50:0:1\n", + "hs20_conn_capab=6:20:1\nhs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\nhs20_conn_capab=17:500:1\nhs20_conn_capab=50:0:1\n", "", "hs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\n", "hs20_conn_capab=6:80:1\nhs20_conn_capab=6:443:1\nhs20_conn_capab=6:5060:1\nhs20_conn_capab=17:5060:1\n", From 0becb96893cd9747b7883448c312945eb932b385 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 4 Mar 2022 15:10:02 +0800 Subject: [PATCH 57/90] Add wsc invalid pin validation check when ap_start_wps --- indigo_api_callback_dut.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index b39e059..aea9f68 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -3011,6 +3011,29 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe if (tlv) { memset(pin_code, 0, sizeof(pin_code)); memcpy(pin_code, tlv->value, tlv->len); + + /* Please implement the wsc pin validation function to + * identify the invalid PIN code and DONOT start wps. + * */ + #define WPS_PIN_VALIDATION_FILE "/tmp/pin_checksum.sh" + int len = 0, is_valid = 0; + char pipebuf[S_BUFFER_LEN]; + FILE *fp = NULL; + char *parameter[] = {"sh", WPS_PIN_VALIDATION_FILE, pin_code, NULL}; + memset(pipebuf, 0, sizeof(pipebuf)); + fp = fopen(WPS_PIN_VALIDATION_FILE, "r"); + if (fp) { + len = pipe_command(pipebuf, sizeof(pipebuf), "/bin/sh", parameter); + if (len && atoi(pipebuf)) { + indigo_logger(LOG_LEVEL_INFO, "Valid PIN Code: %s", pin_code); + } else { + indigo_logger(LOG_LEVEL_INFO, "Invalid PIN Code: %s", pin_code); + goto done; + } + } + /* + * End of wsc pin validation function + * */ sprintf(buffer, "WPS_PIN any %s", pin_code); } else { sprintf(buffer, "WPS_PBC"); From bf853775fceef321e70e86b62472dc773556c3d2 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 4 Mar 2022 16:16:26 +0800 Subject: [PATCH 58/90] Use access() to check file existence. --- indigo_api_callback_dut.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index aea9f68..7a70e46 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -3018,11 +3018,9 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe #define WPS_PIN_VALIDATION_FILE "/tmp/pin_checksum.sh" int len = 0, is_valid = 0; char pipebuf[S_BUFFER_LEN]; - FILE *fp = NULL; char *parameter[] = {"sh", WPS_PIN_VALIDATION_FILE, pin_code, NULL}; memset(pipebuf, 0, sizeof(pipebuf)); - fp = fopen(WPS_PIN_VALIDATION_FILE, "r"); - if (fp) { + if (0 == access(WPS_PIN_VALIDATION_FILE, F_OK)) { len = pipe_command(pipebuf, sizeof(pipebuf), "/bin/sh", parameter); if (len && atoi(pipebuf)) { indigo_logger(LOG_LEVEL_INFO, "Valid PIN Code: %s", pin_code); From 1654d217d2e4c9eb0c60e9c274d365f2fabaab66 Mon Sep 17 00:00:00 2001 From: Kenny Date: Mon, 7 Mar 2022 12:21:07 +0800 Subject: [PATCH 59/90] Add RECONFIGURE TLV for ap_stop by default --- indigo_api_callback_tp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index f89f533..9f80ed2 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -131,9 +131,6 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re stop_loopback_data(NULL); if (reset == RESET_TYPE_INIT) { - /* reset interfaces info */ - clear_interfaces_resource(); - len = unlink(get_hapd_conf_file()); if (len) { indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove hostapd.conf"); @@ -157,6 +154,11 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re memset(band_transmitter, 0, sizeof(band_transmitter)); } + if ((reset == RESET_TYPE_INIT) || (reset == RESET_TYPE_TEARDOWN) || (reset == RESET_TYPE_RECONFIGURE)) { + /* reset interfaces info */ + clear_interfaces_resource(); + } + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); From 3262f8cfb0216bc521604aaaef1dc142ac85647c Mon Sep 17 00:00:00 2001 From: Kenny Date: Mon, 7 Mar 2022 12:48:11 +0800 Subject: [PATCH 60/90] Remove extra space --- indigo_api_callback_tp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 9f80ed2..7886f59 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -154,7 +154,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re memset(band_transmitter, 0, sizeof(band_transmitter)); } - if ((reset == RESET_TYPE_INIT) || (reset == RESET_TYPE_TEARDOWN) || (reset == RESET_TYPE_RECONFIGURE)) { + if ((reset == RESET_TYPE_INIT) || (reset == RESET_TYPE_TEARDOWN) || (reset == RESET_TYPE_RECONFIGURE)) { /* reset interfaces info */ clear_interfaces_resource(); } From 1bb429a679b986d7d5ffc3f38825288ec221c2ad Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Mon, 7 Mar 2022 14:58:29 +0800 Subject: [PATCH 61/90] Add the handler for new api - ap_configure_wsc() --- indigo_api.c | 2 + indigo_api.h | 2 + indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 172 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index fa30b05..b51c4e5 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -37,6 +37,7 @@ struct indigo_api indigo_api_list[] = { { API_AP_SEND_BTM_REQ, "API_AP_SEND_BTM_REQ", NULL, NULL }, { API_AP_SEND_ARP_MSGS, "API_AP_SEND_ARP_MSGS", NULL, NULL }, { API_AP_START_WPS, "AP_START_WPS", NULL, NULL }, + { API_AP_CONFIGURE_WSC, "AP_CONFIGURE_WSC", NULL, NULL }, /* Station specific */ { API_STA_START_UP, "STA_START_UP", NULL, NULL }, { API_STA_ASSOCIATE, "STA_ASSOCIATE", NULL, NULL }, @@ -253,6 +254,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, { TLV_WSC_CONFIG_METHOD, "WSC_CONFIG_METHOD"}, { TLV_PERSISTENT, "PERSISTENT_GROUP" }, + { TLV_WSC_CONFIG_ONLY, "WSC_CONFIG_ONLY" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 1eb7ef4..fb82641 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -50,6 +50,7 @@ struct indigo_api { #define API_AP_SEND_BTM_REQ 0x1006 #define API_AP_SEND_ARP_MSGS 0x1007 #define API_AP_START_WPS 0x1008 +#define API_AP_CONFIGURE_WSC 0x1009 #define API_STA_ASSOCIATE 0x2000 #define API_STA_CONFIGURE 0x2001 @@ -262,6 +263,7 @@ struct indigo_api { #define TLV_ADVICE_OF_CHARGE 0x00d0 #define TLV_WSC_CONFIG_METHOD 0x00d1 #define TLV_PERSISTENT 0x00d2 +#define TLV_WSC_CONFIG_ONLY 0x00d3 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 42203ae..7584d09 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -250,6 +250,7 @@ static int send_ap_btm_handler(struct packet_wrapper *req, struct packet_wrapper static int trigger_ap_channel_switch(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_ap_arp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int configure_ap_wsc_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* STA */ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int configure_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index cc7c189..ab8a016 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -58,6 +58,7 @@ void register_apis() { register_api(API_AP_SET_PARAM , NULL, set_ap_parameter_handler); register_api(API_AP_SEND_BTM_REQ, NULL, send_ap_btm_handler); register_api(API_AP_START_WPS, NULL, start_wps_ap_handler); + register_api(API_AP_CONFIGURE_WSC, NULL, configure_ap_wsc_handler); /* STA */ register_api(API_STA_ASSOCIATE, NULL, associate_sta_handler); register_api(API_STA_CONFIGURE, NULL, configure_sta_handler); @@ -890,6 +891,177 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r return 0; } +// RESP: {: '0', : 'Configure and start wsc ap successfully. (Configure and start)'} +static int configure_ap_wsc_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int len_1 = -1, len_2 = 0, len_3 = -1; + char buffer[L_BUFFER_LEN], ifname[S_BUFFER_LEN]; + struct tlv_hdr *tlv; + char *message = NULL; + int bss_identifier = 0, band; + struct interface_info* wlan = NULL; + char bss_identifier_str[16], hw_mode_str[8]; + struct bss_identifier_info bss_info; + char *parameter[] = {"pidof", get_hapd_exec_file(), NULL}; + int swap_hostapd = 0; + + /* Stop hostapd [Begin] */ + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_hapd_exec_file()); + system(buffer); + sleep(2); + +#ifdef _OPENWRT_ +#else + len_1 = system("rfkill unblock wlan"); + if (len_1) { + indigo_logger(LOG_LEVEL_DEBUG, "Failed to run rfkill unblock wlan"); + } + sleep(1); +#endif + + memset(buffer, 0, sizeof(buffer)); + len_1 = pipe_command(buffer, sizeof(buffer), "/bin/pidof", parameter); + if (len_1) { + message = TLV_VALUE_HOSTAPD_STOP_NOT_OK; + goto done; + } + /* Stop hostapd [End] */ + + /* Generate hostapd configuration file [Begin] */ + memset(buffer, 0, sizeof(buffer)); + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_IDENTIFIER); + memset(ifname, 0, sizeof(ifname)); + memset(&bss_info, 0, sizeof(bss_info)); + if (tlv) { + /* Multiple wlans configure must carry TLV_BSS_IDENTIFIER */ + memset(bss_identifier_str, 0, sizeof(bss_identifier_str)); + memcpy(bss_identifier_str, tlv->value, tlv->len); + bss_identifier = atoi(bss_identifier_str); + parse_bss_identifier(bss_identifier, &bss_info); + wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); + if (NULL == wlan) { + wlan = assign_wireless_interface_info(&bss_info); + } + if (wlan && bss_info.mbssid_enable) { + configure_ap_enable_mbssid(); + if (bss_info.transmitter) { + band_transmitter[bss_info.band] = wlan; + } + } + printf("TLV_BSS_IDENTIFIER 0x%x band %d multiple_bssid %d transmitter %d identifier %d\n", + bss_identifier, + bss_info.band, + bss_info.mbssid_enable, + bss_info.transmitter, + bss_info.identifier + ); + } else { + /* Single wlan case */ + /* reset interfaces info */ + clear_interfaces_resource(); + + tlv = find_wrapper_tlv_by_id(req, TLV_HW_MODE); + if (tlv) + { + memset(hw_mode_str, 0, sizeof(hw_mode_str)); + memcpy(hw_mode_str, tlv->value, tlv->len); + if (find_wrapper_tlv_by_id(req, TLV_HE_6G_ONLY)) { + band = BAND_6GHZ; + } else if (!strncmp(hw_mode_str, "a", 1)) { + band = BAND_5GHZ; + } else { + band = BAND_24GHZ; + } + /* Single wlan use ID 1 */ + bss_info.band = band; + bss_info.identifier = 1; + wlan = assign_wireless_interface_info(&bss_info); + } + } + if (wlan) { + printf("ifname %s hostapd conf file %s\n", + wlan ? wlan->ifname : "n/a", + wlan ? wlan->hapd_conf_file: "n/a" + ); + len_2 = generate_hostapd_config(buffer, sizeof(buffer), req, wlan); + if (len_2) + { +#if HOSTAPD_SUPPORT_MBSSID + if (bss_info.mbssid_enable && !bss_info.transmitter) { + if (band_transmitter[bss_info.band]) { + append_file(band_transmitter[bss_info.band]->hapd_conf_file, buffer, len_2); + } + memset(wlan->hapd_conf_file, 0, sizeof(wlan->hapd_conf_file)); + } + else +#endif + write_file(wlan->hapd_conf_file, buffer, len_2); + } else { + message = "Failed to generate hostapd configuration file."; + goto done; + } + } + show_wireless_interface_info(); + /* Generate hostapd configuration file [End] */ + + tlv = find_wrapper_tlv_by_id(req, TLV_WSC_CONFIG_ONLY); + if (tlv) { + /* Configure only (without starting hostapd) */ + message = "Configure wsc ap successfully. (Configure only)"; + goto done; + } + + /* Start hostapd [Begin] */ +#ifdef _WTS_OPENWRT_ + openwrt_apply_radio_config(); + // DFS wait again if set wlan params after hostapd starts + iterate_all_wlan_interfaces(start_ap_set_wlan_params); +#endif + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "%s -B -t -P /var/run/hostapd.pid -g %s %s -f /var/log/hostapd.log %s", + get_hapd_full_exec_path(), + get_hapd_global_ctrl_path(), + get_hostapd_debug_arguments(), + get_all_hapd_conf_files(&swap_hostapd)); + len_3 = system(buffer); + sleep(1); + + /* Bring up VAPs with MBSSID disable using WFA hostapd */ + if (swap_hostapd) { +#ifdef HOSTAPD_SUPPORT_MBSSID_WAR + indigo_logger(LOG_LEVEL_INFO, "Use WFA hostapd for MBSSID disable VAPs with RNR"); + system("cp /overlay/hostapd /usr/sbin/hostapd"); + use_openwrt_wpad = 0; + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "%s -B -t -P /var/run/hostapd_1.pid %s -f /var/log/hostapd_1.log %s", + get_hapd_full_exec_path(), + get_hostapd_debug_arguments(), + get_all_hapd_conf_files(&swap_hostapd)); + len_3 = system(buffer); + sleep(1); +#endif + } + +#ifndef _WTS_OPENWRT_ + iterate_all_wlan_interfaces(start_ap_set_wlan_params); +#endif + + bridge_init(get_wlans_bridge()); + if (len_3 == 0) + message = "Confiugre and start wsc ap successfully. (Configure and start)"; + else + message = "Failed to start hostapd."; + /* Start hostapd [End] */ + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, (len_1 == 0 || len_2 > 0 || len_3 == 0) ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + + return 0; +} + /* deprecated */ static int create_bridge_network_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int err = 0; From 7db8aeb74aaa6fd13740d506f41d6460bc2657cf Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 8 Mar 2022 14:28:59 +0800 Subject: [PATCH 62/90] ITT-1181 upload test platform's hostapd conf to Test Tool --- indigo_api_callback_tp.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 7886f59..76c00b0 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -75,6 +75,18 @@ static int get_control_app_handler(struct packet_wrapper *req, struct packet_wra return 0; } +/* + * void (*callback_fn)(void *), callback of active wlans iterator + */ +void upload_wlan_hapd_conf(void *if_info) { + struct interface_info *wlan = (struct interface_info *) if_info; + + if (tool_addr != NULL) { + http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, HAPD_UPLOAD_API, wlan->hapd_conf_file); + sleep(1); + } +} + // RESP: {: '0', : 'AP stop completed : Hostapd service is inactive.'} static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len = 0, reset = 0; @@ -117,7 +129,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re if (reset == RESET_TYPE_TEARDOWN) { /* Send hostapd conf and log to Tool */ if (tool_addr != NULL) { - http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, HAPD_UPLOAD_API, get_hapd_conf_file()); + iterate_all_wlan_interfaces(upload_wlan_hapd_conf); sleep(1); http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, HAPD_UPLOAD_API, HAPD_LOG_FILE); } else { From d4df4dc77d8f3fc3a4f98f0412b096c80039e3a2 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 8 Mar 2022 16:14:11 +0800 Subject: [PATCH 63/90] Update ap_stop default behavior --- indigo_api.h | 1 + indigo_api_callback_tp.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/indigo_api.h b/indigo_api.h index 1eb7ef4..95e7377 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -356,6 +356,7 @@ struct indigo_api { #define RESET_TYPE_INIT 0x01 #define RESET_TYPE_TEARDOWN 0x02 #define RESET_TYPE_RECONFIGURE 0x03 +#define RESET_TYPE_KEEP_CONFIG 0x04 #define WPA_CTRL_OK "OK" #define WPA_CTRL_FAIL "FAIL" diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 76c00b0..0732ccf 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -166,7 +166,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re memset(band_transmitter, 0, sizeof(band_transmitter)); } - if ((reset == RESET_TYPE_INIT) || (reset == RESET_TYPE_TEARDOWN) || (reset == RESET_TYPE_RECONFIGURE)) { + if (reset != RESET_TYPE_KEEP_CONFIG) { /* reset interfaces info */ clear_interfaces_resource(); } From e2b1730dee51ba20e97523ad551db0695e194419 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Wed, 9 Mar 2022 14:56:49 +0800 Subject: [PATCH 64/90] ITS-2116 to apply dynamic OOB settings --- indigo_api.c | 1 - indigo_api.h | 2 +- indigo_api_callback_dut.c | 82 +++++++------------------- indigo_api_callback_tp.c | 23 ++++---- vendor_specific.h | 17 ++---- vendor_specific_dut.c | 118 +++++++++++++++++++++++++++++--------- 6 files changed, 128 insertions(+), 115 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index b51c4e5..b57fa26 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -252,7 +252,6 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_EAP_FRAG_SIZE, "EAP_FRAG_SIZE" }, { TLV_PERFORM_WPS_IE_FRAG, "PERFORM_WPS_IE_FRAG" }, { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, - { TLV_WSC_CONFIG_METHOD, "WSC_CONFIG_METHOD"}, { TLV_PERSISTENT, "PERSISTENT_GROUP" }, { TLV_WSC_CONFIG_ONLY, "WSC_CONFIG_ONLY" }, }; diff --git a/indigo_api.h b/indigo_api.h index fb82641..d3882ee 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -261,7 +261,6 @@ struct indigo_api { #define TLV_EAP_FRAG_SIZE 0x00ce #define TLV_PERFORM_WPS_IE_FRAG 0x00cf #define TLV_ADVICE_OF_CHARGE 0x00d0 -#define TLV_WSC_CONFIG_METHOD 0x00d1 #define TLV_PERSISTENT 0x00d2 #define TLV_WSC_CONFIG_ONLY 0x00d3 @@ -354,6 +353,7 @@ struct indigo_api { #define TLV_VALUE_HS2_INSTALL_PPSMO_NOT_OK "Failed to install PPSMO file" #define TLV_VALUE_AP_START_WPS_NOT_OK "Failed to start WPS on AP interface" +#define TLV_VALUE_AP_WSC_PIN_CODE_NOT_OK "AP detects invalid PIN code" #define RESET_TYPE_INIT 0x01 #define RESET_TYPE_TEARDOWN 0x02 diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index ab8a016..1bd1e91 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -31,7 +31,6 @@ static char pac_file_path[S_BUFFER_LEN] = {0}; struct interface_info* band_transmitter[16]; extern struct sockaddr_in *tool_addr; -extern conf_method_map CM_map[13]; int sta_configured = 0; int sta_started = 0; @@ -388,14 +387,17 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (tlv->id == TLV_WSC_OOB) { int j; + /* To get AP wps vendor info */ + wps_setting *s = get_vendor_wps_settings(WPS_AP); + if (!s) { + indigo_logger(LOG_LEVEL_WARNING, "Failed to get AP wps settings"); + continue; + } enable_wps = 1; memcpy(buffer, tlv->value, tlv->len); - wps_setting *s = get_vendor_wps_settings(WPS_AP); if (atoi(buffer)) { /* Use OOB */ for (j = 0; j < AP_SETTING_NUM; j++) { - if (0 == strlen(s[j].value)) - continue; memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); strcat(output, cfg_item); @@ -403,48 +405,23 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } else { /* NOT use OOB: Configure manually. */ for (j = 0; j < AP_SETTING_NUM; j++) { - if (0 == strlen(s[j].value)) - continue; memset(cfg_item, 0, sizeof(cfg_item)); - if (s[j].attr & WPS_COMMON) { - if (strlen(s[j].wkey) == strlen(WPS_OOB_STATE) && - !(memcmp(s[j].wkey, WPS_OOB_STATE, strlen(WPS_OOB_STATE)))) { - if (atoi(s[j].value) == atoi(WPS_OOB_NOT_CONFIGURED)) { - /* Change wps oob state to Configured. */ - sprintf(cfg_item, "%s=%s\n", s[j].wkey, WPS_OOB_CONFIGURED); - } else { - indigo_logger(LOG_LEVEL_ERROR, "DUT OOB state Mismatch: 0x%s", s[j].value); - continue; - } - } else { - sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + /* set wps state */ + if (atoi(s[j].attr) == atoi(WPS_OOB_ONLY)) { + if (!(memcmp(s[j].wkey, WPS_OOB_STATE, strlen(WPS_OOB_STATE)))) { + /* set wps state to Configured compulsorily */ + sprintf(cfg_item, "%s=%s\n", s[j].wkey, WPS_OOB_CONFIGURED); } - strcat(output, cfg_item); } + /* set wps common settings */ + if (atoi(s[j].attr) == atoi(WPS_COMMON)) { + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + } + strcat(output, cfg_item); } } } - /* wsc config methods */ - if (tlv->id == TLV_WSC_CONFIG_METHOD) { - int k, len = 0, conf_methods; - int count = sizeof(CM_map)/sizeof(CM_map[0]); - - memcpy(buffer, tlv->value, tlv->len); - conf_methods = atoi(buffer); - memset(buffer, 0, sizeof(buffer)); - indigo_logger(LOG_LEVEL_DEBUG, "APUT config methods: 0x%04X", conf_methods); - for (k = 0; k < count; k++) { - if (conf_methods & CM_map[k].attr_bit) - len += snprintf(buffer + len, sizeof(buffer) - len, "%s ", CM_map[k].name); - } - indigo_logger(LOG_LEVEL_DEBUG, "APUT config methods: %s, len=%d", buffer, len); - if (len) { - sprintf(cfg_item, "config_methods=%s\n", buffer); - strcat(output, cfg_item); - } - } - cfg = find_tlv_config(tlv->id); if (!cfg) { indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id); @@ -1854,26 +1831,6 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra } } - /* wsc config methods */ - tlv = find_wrapper_tlv_by_id(wrapper, TLV_WSC_CONFIG_METHOD); - if (tlv) { - count = sizeof(CM_map)/sizeof(CM_map[0]); - memset(value, 0, sizeof(value)); - memcpy(value, tlv->value, tlv->len); - conf_methods = atoi(value); - memset(buf, 0, sizeof(buf)); - indigo_logger(LOG_LEVEL_DEBUG, "STAUT config methods: 0x%04X", conf_methods); - for (i = 0; i < count; i++) { - if (conf_methods & CM_map[i].attr_bit) - len += snprintf(buf + len, sizeof(buf) - len, "%s ", CM_map[i].name); - } - indigo_logger(LOG_LEVEL_DEBUG, "STAUT config methods: %s, len=%d", buf, len); - if (len) { - sprintf(cfg_item, "config_methods=%s\n", buf); - strcat(buffer, cfg_item); - } - } - /* wps settings */ tlv = find_wrapper_tlv_by_id(wrapper, TLV_WSC_OOB); if (tlv) { @@ -1881,10 +1838,10 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra memcpy(value, tlv->value, tlv->len); /* To get STA wps vendor info */ wps_setting *s = get_vendor_wps_settings(WPS_STA); - if (atoi(value)) { + if (!s) { + indigo_logger(LOG_LEVEL_WARNING, "Failed to get STA wps settings"); + } else if (atoi(value)) { for (i = 0; i < STA_SETTING_NUM; i++) { - if (0 == strlen(s[i].value)) - continue; memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); strcat(buffer, cfg_item); @@ -3307,6 +3264,7 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe indigo_logger(LOG_LEVEL_INFO, "Valid PIN Code: %s", pin_code); } else { indigo_logger(LOG_LEVEL_INFO, "Invalid PIN Code: %s", pin_code); + message = TLV_VALUE_AP_WSC_PIN_CODE_NOT_OK; goto done; } } diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 7886f59..1621948 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -368,21 +368,18 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ /* NOT use OOB: Configure manually. */ for (j = 0; j < AP_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); - if (s[j].attr & WPS_COMMON) { - if (strlen(s[j].wkey) == strlen(WPS_OOB_STATE) && - !(memcmp(s[j].wkey, WPS_OOB_STATE, strlen(WPS_OOB_STATE)))) { - if (atoi(s[j].value) == atoi(WPS_OOB_NOT_CONFIGURED)) { - /* Change wps oob state to Configured. */ - sprintf(cfg_item, "%s=%s\n", s[j].wkey, WPS_OOB_CONFIGURED); - } else { - indigo_logger(LOG_LEVEL_ERROR, "DUT OOB state Mismatch: 0x%s", s[j].value); - continue; - } - } else { - sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + /* set wps state */ + if (atoi(s[j].attr) == atoi(WPS_OOB_ONLY)) { + if (!(memcmp(s[j].wkey, WPS_OOB_STATE, strlen(WPS_OOB_STATE)))) { + /* set wps state to Configured compulsorily */ + sprintf(cfg_item, "%s=%s\n", s[j].wkey, WPS_OOB_CONFIGURED); } - strcat(output, cfg_item); } + /* set wps common settings */ + if (atoi(s[j].attr) == atoi(WPS_COMMON)) { + sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); + } + strcat(output, cfg_item); } } } diff --git a/vendor_specific.h b/vendor_specific.h index 6df9a05..febfd9a 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -118,10 +118,8 @@ void vendor_device_reset(); #define SUPPORTED_CONF_METHOD_AP "label keypad push_button virtual_push_button display virtual_display" #define SUPPORTED_CONF_METHOD_STA "keypad push_button virtual_push_button display virtual_display" -enum param_attr { - WPS_COMMON = 0x0001, - WPS_OOB_ONLY = 0x0010 -}; +#define WPS_OOB_ONLY "1" +#define WPS_COMMON "2" enum wps_device_role { WPS_AP, @@ -134,16 +132,11 @@ enum wps_device_role { typedef struct _wps_setting { /* key-value for each setting pair */ - char *wkey; - char *value; - enum param_attr attr; + char wkey[64]; + char value[512]; + char attr[64]; } wps_setting; -typedef struct _conf_method_map { - unsigned int attr_bit; - char *name; -} conf_method_map; - #ifdef _TEST_PLATFORM_ /** diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index d06b769..320e359 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -385,23 +385,6 @@ void stop_dhcp_client() system("killall dhclient 1>/dev/null 2>/dev/null"); } -conf_method_map CM_map[13] = { - {0x0001, "usba"}, - {0x0002, "ethernet"}, - {0x0004, "label"}, - {0x0008, "display"}, - {0x0010, "ext_nfc_token"}, - {0x0020, "int_nfc_token"}, - {0x0040, "nfc_interface"}, - {0x0080, "pushbutton"}, - {0x0100, "keypad"}, - {0x0200, "virtual_pushbutton"}, - {0x0400, "physical_pushbutton"}, - {0x2000, "virtual_display"}, - {0x4000, "physical_display"}, - -}; - wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { /* @@ -412,12 +395,12 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_OOB_ONLY }, /* wps oob state */ /* * General * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ - { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ - { WPS_CONFIG, "", WPS_COMMON }, /* config methods */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ @@ -434,12 +417,12 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_OOB_ONLY }, /* wps oob state */ /* * General * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ - { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_COMMON }, /* wps oob state */ - { WPS_CONFIG, "", WPS_COMMON }, /* config methods */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ @@ -450,17 +433,100 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { }; wps_setting wps_settings_sta[STA_SETTING_NUM] = { - { WPS_CONFIG, "", WPS_COMMON }, /* config methods */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_STA, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Intel Wireless STA", WPS_COMMON }, /* device name */ { WPS_MANUFACTURER, "Intel.com", WPS_COMMON }, /* manufacturer */ { WPS_MODEL_NAME, "Intel Wireless STA", WPS_COMMON }, /* model name */ { WPS_MODEL_NUMBER, "Intel Wireless STA-001", WPS_COMMON }, /* model number */ }; -wps_setting* get_vendor_wps_settings(enum wps_device_role role) +wps_setting *p_wps_setting = NULL; +wps_setting customized_wps_settings_ap[AP_SETTING_NUM]; +wps_setting customized_wps_settings_sta[STA_SETTING_NUM]; + +void save_wsc_setting(wps_setting *s, char *entry, int len) { - if (role == WPS_AP) - return wps_settings_ap[0]; + char *p = NULL; + + p = strchr(entry, '\n'); + if (p) + p++; else - return wps_settings_sta; + p = entry; + + sscanf(p, "%[^:]:%[^:]:%s", s->wkey, s->value, s->attr); +} + +wps_setting* __get_wps_setting(int len, char *buffer, enum wps_device_role role) +{ + char *token = strtok(buffer , ","); + wps_setting *s = NULL; + int i = 0; + + if (role == WPS_AP) { + memset(customized_wps_settings_ap, 0, sizeof(customized_wps_settings_ap)); + p_wps_setting = customized_wps_settings_ap; + while (token != NULL) { + s = &p_wps_setting[i++]; + save_wsc_setting(s, token, strlen(token)); + token = strtok(NULL, ","); + } + } else { + memset(customized_wps_settings_sta, 0, sizeof(customized_wps_settings_sta)); + p_wps_setting = customized_wps_settings_sta; + while (token != NULL) { + s = &p_wps_setting[i++]; + save_wsc_setting(s, token, strlen(token)); + token = strtok(NULL, ","); + } + } + return p_wps_setting; +} + +wps_setting* get_vendor_wps_settings(enum wps_device_role role) +{ + /* + * Please implement the function to get wps OOB and required settings as per vendor's direction. + * */ +#define WSC_SETTINGS_FILE_AP "/tmp/wsc_settings_APUT" +#define WSC_SETTINGS_FILE_STA "/tmp/wsc_settings_STAUT" + int len = 0, is_valid = 0; + char pipebuf[S_BUFFER_LEN]; + char *parameter_ap[] = {"cat", WSC_SETTINGS_FILE_AP, NULL, NULL}; + char *parameter_sta[] = {"cat", WSC_SETTINGS_FILE_STA, NULL, NULL}; + + memset(pipebuf, 0, sizeof(pipebuf)); + if (role == WPS_AP) { + if (0 == access(WSC_SETTINGS_FILE_AP, F_OK)) { + // use customized ap wsc settings +#ifdef _OPENWRT_ + len = pipe_command(pipebuf, sizeof(pipebuf), "/bin/cat", parameter_ap); +#else + len = pipe_command(pipebuf, sizeof(pipebuf), "/usr/bin/cat", parameter_ap); +#endif + if (len) { + indigo_logger(LOG_LEVEL_INFO, "wsc settings APUT:\n %s", pipebuf); + return __get_wps_setting(len, pipebuf, WPS_AP); + } else { + indigo_logger(LOG_LEVEL_INFO, "wsc settings APUT: no data"); + } + } else { + // use default + return wps_settings_ap[0]; + } + } else { + if (0 == access(WSC_SETTINGS_FILE_STA, F_OK)) { + // use customized sta wsc settings + len = pipe_command(pipebuf, sizeof(pipebuf), "/usr/bin/cat", parameter_sta); + if (len) { + indigo_logger(LOG_LEVEL_INFO, "wsc settings STAUT:\n %s", pipebuf); + return __get_wps_setting(len, pipebuf, WPS_STA); + } else { + indigo_logger(LOG_LEVEL_INFO, "wsc settings STAUT: no data"); + } + } else { + // use default + return wps_settings_sta; + } + } } From 6211c401cffee37143b1c237c52c01df95076030 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Thu, 10 Mar 2022 16:18:09 +0800 Subject: [PATCH 65/90] Add P2P_SET_SERV_DISC API --- indigo_api.c | 1 + indigo_api.h | 2 ++ indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 67 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index 3a77a78..ae86ef3 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -63,6 +63,7 @@ struct indigo_api indigo_api_list[] = { { API_STA_START_WPS, "STA_START_WPS", NULL, NULL }, { API_P2P_INVITE, "P2P_INVITE", NULL, NULL }, { API_P2P_STOP_GROUP, "P2P_STOP_GROUP", NULL, NULL }, + { API_P2P_SET_SERV_DISC, "P2P_SET_SERV_DISC", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index d71c8e5..755279e 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -77,6 +77,7 @@ struct indigo_api { #define API_STA_INSTALL_PPSMO 0x2017 #define API_P2P_INVITE 0x2018 #define API_P2P_STOP_GROUP 0x2019 +#define API_P2P_SET_SERV_DISC 0x201a #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -341,6 +342,7 @@ struct indigo_api { #define TLV_VALUE_P2P_START_WPS_NOT_OK "Failed to start WPS on GO interface" #define TLV_VALUE_P2P_CONNECT_NOT_OK "Failed to trigger P2P connect" #define TLV_VALUE_P2P_INVITE_NOT_OK "Failed to invite P2P device" +#define TLV_VALUE_P2P_SET_SERV_DISC_NOT_OK "Failed to set service discovery" #define TLV_VALUE_HS2_INSTALL_PPSMO_OK "PPSMO file is installed" #define TLV_VALUE_HS2_INSTALL_PPSMO_NOT_OK "Failed to install PPSMO file" diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 3bc1ffc..f0705f6 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -274,4 +274,5 @@ static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapp static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); #endif // __INDIGO_API_CALLBACK diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index b39e059..2383511 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -81,6 +81,7 @@ void register_apis() { register_api(API_P2P_GET_INTENT_VALUE, NULL, get_intent_value_p2p_handler); register_api(API_P2P_INVITE, NULL, invite_p2p_handler); register_api(API_P2P_STOP_GROUP, NULL, stop_group_p2p_handler); + register_api(API_P2P_SET_SERV_DISC, NULL, set_serv_disc_p2p_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -3280,3 +3281,69 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper } return 0; } + +static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[BUFFER_LEN], response[BUFFER_LEN]; + char addr[32], p2p_dev_if[32]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_SET_SERV_DISC_NOT_OK; + struct tlv_hdr *tlv = NULL; + + memset(addr, 0, sizeof(addr)); + tlv = find_wrapper_tlv_by_id(req, TLV_ADDRESS); + if (tlv) { + /* Send Service Discovery Req */ + memcpy(addr, tlv->value, tlv->len); + } else { + /* Set Services case */ + /* Add bonjour and upnp Service */ + } + + get_p2p_dev_if(p2p_dev_if, sizeof(p2p_dev_if)); + indigo_logger(LOG_LEVEL_DEBUG, "P2P Dev IF: %s", p2p_dev_if); + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_if_ctrl_path(p2p_dev_if)); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + if (addr[0] != 0) { + sprintf(buffer, "P2P_SERV_DISC_REQ %s 02000001", addr); + indigo_logger(LOG_LEVEL_DEBUG, "Command: %s", buffer); + } else { + sprintf(buffer, "P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074"); + } + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + + if (addr[0] == 0) { + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + sprintf(buffer, "P2P_SERVICE_ADD upnp 10 uuid:5566d33e-9774-09ab-4822-333456785632::urn:schemas-upnp-org:service:ContentDirectory:2"); + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} From 3a1b28973e4298d94c6f3c7204eceb6dc2455a73 Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 11 Mar 2022 11:29:41 +0800 Subject: [PATCH 66/90] ITT-1182 Upload per test case control app logs to Test-Logs/per-test-case-folder --- indigo_api_callback_dut.c | 16 ++++++++------ indigo_api_callback_tp.c | 16 ++++++++------ utils.c | 45 +++++++++++++++++++++++++++++++++++++++ utils.h | 8 +++++++ 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 1bd1e91..6e0661e 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -228,6 +228,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re /* Test case teardown case */ if (reset == RESET_TYPE_TEARDOWN) { + close_tc_app_log(); } /* reset interfaces info */ @@ -235,6 +236,7 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re if (reset == RESET_TYPE_INIT) { system("rm -rf /var/log/hostapd.log >/dev/null 2>/dev/null"); + open_tc_app_log(); } fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); @@ -542,7 +544,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (NULL == wlan) { wlan = assign_wireless_interface_info(&bss_info); } - printf("TLV_OWE_TRANSITION_BSS_IDENTIFIER: TLV_BSS_IDENTIFIER 0x%x identifier %d mapping ifname %s\n", + indigo_logger(LOG_LEVEL_DEBUG, "TLV_OWE_TRANSITION_BSS_IDENTIFIER: TLV_BSS_IDENTIFIER 0x%x identifier %d mapping ifname %s\n", bss_identifier, bss_info.identifier, wlan ? wlan->ifname : "n/a" @@ -757,7 +759,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe band_transmitter[bss_info.band] = wlan; } } - printf("TLV_BSS_IDENTIFIER 0x%x band %d multiple_bssid %d transmitter %d identifier %d\n", + indigo_logger(LOG_LEVEL_DEBUG, "TLV_BSS_IDENTIFIER 0x%x band %d multiple_bssid %d transmitter %d identifier %d\n", bss_identifier, bss_info.band, bss_info.mbssid_enable, @@ -785,7 +787,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe } } if (wlan) { - printf("ifname %s hostapd conf file %s\n", + indigo_logger(LOG_LEVEL_DEBUG, "ifname %s hostapd conf file %s\n", wlan ? wlan->ifname : "n/a", wlan ? wlan->hapd_conf_file: "n/a" ); @@ -1179,7 +1181,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe bss_identifier = atoi(bss_identifier_str); parse_bss_identifier(bss_identifier, &bss_info); - printf("TLV_BSS_IDENTIFIER 0x%x identifier %d band %d\n", + indigo_logger(LOG_LEVEL_DEBUG, "TLV_BSS_IDENTIFIER 0x%x identifier %d band %d\n", bss_identifier, bss_info.identifier, bss_info.band @@ -1245,7 +1247,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe } if (bss_info.identifier >= 0) { - printf("Get mac_addr %s\n", mac_addr); + indigo_logger(LOG_LEVEL_DEBUG, "Get mac_addr %s\n", mac_addr); status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; goto done; @@ -1748,6 +1750,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r /* Test case teardown case */ if (reset == RESET_TYPE_TEARDOWN) { + close_tc_app_log(); } if (reset == RESET_TYPE_INIT) { @@ -1758,7 +1761,8 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r if (strlen(pac_file_path)) { remove_pac_file(pac_file_path); memset(pac_file_path, 0, sizeof(pac_file_path)); - } + } + open_tc_app_log(); } len = reset_interface_ip(get_wireless_interface()); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 292388f..3ddc456 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -136,13 +136,15 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re indigo_logger(LOG_LEVEL_ERROR, "Can't get tool IP address"); } - reset_bridge(get_wlans_bridge()); - reset_interface_ip(get_wireless_interface()); + reset_bridge(get_wlans_bridge()); + reset_interface_ip(get_wireless_interface()); + close_tc_app_log(); } stop_loopback_data(NULL); if (reset == RESET_TYPE_INIT) { + open_tc_app_log(); len = unlink(get_hapd_conf_file()); if (len) { indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove hostapd.conf"); @@ -489,7 +491,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (NULL == wlan) { wlan = assign_wireless_interface_info(&bss_info); } - printf("TLV_OWE_TRANSITION_BSS_IDENTIFIER: TLV_BSS_IDENTIFIER 0x%x identifier %d mapping ifname %s\n", + indigo_logger(LOG_LEVEL_DEBUG, "TLV_OWE_TRANSITION_BSS_IDENTIFIER: TLV_BSS_IDENTIFIER 0x%x identifier %d mapping ifname %s\n", bss_identifier, bss_info.identifier, wlan ? wlan->ifname : "n/a" @@ -654,7 +656,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe band_transmitter[bss_info.band] = wlan; } } - printf("TLV_BSS_IDENTIFIER 0x%x band %d multiple_bssid %d transmitter %d identifier %d\n", + indigo_logger(LOG_LEVEL_DEBUG, "TLV_BSS_IDENTIFIER 0x%x band %d multiple_bssid %d transmitter %d identifier %d\n", bss_identifier, bss_info.band, bss_info.mbssid_enable, @@ -687,7 +689,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe } } if (wlan) { - printf("ifname %s hostapd conf file %s\n", + indigo_logger(LOG_LEVEL_DEBUG, "ifname %s hostapd conf file %s\n", wlan ? wlan->ifname : "n/a", wlan ? wlan->hapd_conf_file: "n/a" ); @@ -882,7 +884,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe bss_identifier = atoi(bss_identifier_str); parse_bss_identifier(bss_identifier, &bss_info); - printf("TLV_BSS_IDENTIFIER 0x%x identifier %d band %d\n", + indigo_logger(LOG_LEVEL_DEBUG, "TLV_BSS_IDENTIFIER 0x%x identifier %d band %d\n", bss_identifier, bss_info.identifier, bss_info.band); @@ -1126,9 +1128,11 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r set_channel_width(); } reconf_count = 0; + close_tc_app_log(); } if (reset == RESET_TYPE_INIT) { + open_tc_app_log(); len = unlink(get_wpas_conf_file()); if (len) { indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove wpa_supplicant.conf"); diff --git a/utils.c b/utils.c index 8a3a94d..b9cc84d 100644 --- a/utils.c +++ b/utils.c @@ -58,6 +58,12 @@ static struct loopback_info loopback = {}; /* bridge used for wireless interfaces */ char wlans_bridge[32]; +#if UPLOAD_TC_APP_LOG +/* per test case control app log */ +FILE *app_log; +extern struct sockaddr_in *tool_addr; +#endif + #ifdef HOSTAPD_SUPPORT_MBSSID_WAR int use_openwrt_wpad = 0; #endif @@ -75,6 +81,11 @@ void debug_print_timestamp(void) { strftime(buffer, sizeof(buffer), "%b %d %H:%M:%S", info); } printf("%s ", buffer); +#if UPLOAD_TC_APP_LOG + if (app_log) { + fprintf(app_log, "%s ", buffer); + } +#endif } void indigo_logger(int level, const char *fmt, ...) { @@ -118,6 +129,14 @@ void indigo_logger(int level, const char *fmt, ...) { vprintf(format, ap); va_end(ap); printf("\n"); +#if UPLOAD_TC_APP_LOG + if (app_log) { + va_start(ap, fmt); + vfprintf(app_log, format, ap); + fprintf(app_log, "\n"); + va_end(ap); + } +#endif } if (level >= stdout_level) { @@ -145,6 +164,32 @@ void indigo_logger(int level, const char *fmt, ...) { } } +void open_tc_app_log() { +#if UPLOAD_TC_APP_LOG + if (app_log) { + fclose(app_log); + app_log = NULL; + } + app_log = fopen(APP_LOG_FILE, "w"); + if (app_log == NULL) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to open the file %s", APP_LOG_FILE); + } +#endif +} + +/* Close file handle and upload test case control app log */ +void close_tc_app_log() { +#if UPLOAD_TC_APP_LOG + if (app_log) { + fclose(app_log); + app_log = NULL; + if (tool_addr != NULL) { + http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, HAPD_UPLOAD_API, APP_LOG_FILE); + } + } +#endif +} + /* System */ int pipe_command(char *buffer, int buffer_size, char *cmd, char *parameter[]) { int pipefds[2], len; diff --git a/utils.h b/utils.h index bf1ec87..609cd53 100644 --- a/utils.h +++ b/utils.h @@ -26,6 +26,12 @@ #define TOOL_POST_PORT 8080 #define HAPD_UPLOAD_API "/upload-platform-hapd-log" #define WPAS_UPLOAD_API "/upload-platform-wpas-log" +#ifdef _DUT_ +#define APP_LOG_FILE "controlappc_DUT.log" +#else +#define APP_LOG_FILE "controlappc_tool_platform.log" +#endif +#define UPLOAD_TC_APP_LOG 1 /* Log */ enum { @@ -125,6 +131,8 @@ int pipe_command(char *buffer, int buffer_size, char *cmd, char *parameter[]); char* read_file(char *fn); int write_file(char *fn, char *buffer, int len); int append_file(char *fn, char *buffer, int len); +void open_tc_app_log(); +void close_tc_app_log(); /* network interface and loopback API */ int get_mac_address(char *buffer, int size, char *interface); From ebdf6f33980695c8917d9a27c64c2eb0e7186f54 Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Fri, 11 Mar 2022 15:29:28 +0800 Subject: [PATCH 67/90] Support OSU providers list setting and icon request API --- hs2_profile.h | 5 +- indigo_api.c | 2 + indigo_api.h | 3 ++ indigo_api_callback.h | 1 + indigo_api_callback_tp.c | 102 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 2 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index f10c8f1..d24d217 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -118,7 +118,7 @@ const char * operating_class_indication[] = { const char * osu_providers_list[] = { "", - "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\nosu_friendly_name=eng:SP Red Test Only\nosu_friendly_name=kor:SP 빨강 테스트 전용\nosu_method_list=1\nosu_service_desc=eng:Free service for test purpose\nosu_service_desc=kor:테스트 목적으로 무료 서비스\n", + "osu_ssid=\"OSU\"\nosu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\nosu_friendly_name=eng:SP Red Test Only\nosu_friendly_name=kor:SP 빨강 테스트 전용\nosu_method_list=1\nosu_icon=icon_red_eng.png\nosu_icon=icon_red_zxx.png\nosu_service_desc=eng:Free service for test purpose\nosu_service_desc=kor:테스트 목적으로 무료 서비스\n", "", "", "", @@ -158,7 +158,8 @@ const char * advice_of_charge[] = { // ::::: const char * hs20_icon[] = { - "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/overlay/icon_red_eng.png\n", + "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/overlay/passpoint/icon_red_eng.png\n", + "hs20_icon=128:61:zxx:image/png:icon_red_zxx.png:/overlay/passpoint/icon_red_zxx.png\n", }; struct tlv_to_profile hs2_profile[] = { diff --git a/indigo_api.c b/indigo_api.c index b2544f1..7ef6c1c 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -66,6 +66,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_INVITE, "P2P_INVITE", NULL, NULL }, { API_P2P_STOP_GROUP, "P2P_STOP_GROUP", NULL, NULL }, { API_P2P_SET_SERV_DISC, "P2P_SET_SERV_DISC", NULL, NULL }, + { API_STA_SEND_ICON_REQ, "STA_SEND_ICON_REQ", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, @@ -255,6 +256,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, { TLV_PERSISTENT, "PERSISTENT_GROUP" }, { TLV_WSC_CONFIG_ONLY, "WSC_CONFIG_ONLY" }, + { TLV_ICON_FILE, "ICON_FILE" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 37dea36..6064205 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -79,6 +79,7 @@ struct indigo_api { #define API_P2P_INVITE 0x2018 #define API_P2P_STOP_GROUP 0x2019 #define API_P2P_SET_SERV_DISC 0x201a +#define API_STA_SEND_ICON_REQ 0x201b #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -264,6 +265,7 @@ struct indigo_api { #define TLV_ADVICE_OF_CHARGE 0x00d0 #define TLV_PERSISTENT 0x00d2 #define TLV_WSC_CONFIG_ONLY 0x00d3 +#define TLV_ICON_FILE 0x00d4 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT @@ -282,6 +284,7 @@ struct indigo_api { #define TLV_WSC_SSID 0xa00c #define TLV_WSC_WPA_KEY_MGMT 0xa00d #define TLV_WSC_WPA_PASSPHRASS 0xa00e +#define TLV_PASSPOINT_ICON_CHECKSUM 0xa00f /* TLV Value */ #define DUT_TYPE_STAUT 0x01 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index e26bb05..4999acf 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -269,6 +269,7 @@ static int set_sta_phy_mode_handler(struct packet_wrapper *req, struct packet_wr static int set_sta_channel_width_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* P2P */ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 292388f..20b1b9a 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -50,6 +50,7 @@ void register_apis() { register_api(API_START_DHCP, NULL, start_dhcp_handler); register_api(API_STOP_DHCP, NULL, stop_dhcp_handler); register_api(API_GET_WSC_CRED, NULL, get_wsc_cred_handler); + register_api(API_STA_SEND_ICON_REQ, NULL, send_sta_icon_req_handler); /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); @@ -1958,3 +1959,104 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe } return 0; } + + +static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int len, status = TLV_VALUE_STATUS_NOT_OK, i; + char *message = TLV_VALUE_NOT_OK; + char buffer[1024]; + char response[1024]; + char bssid[256]; + char icon_file[256], icon_checksum[64]; + struct tlv_hdr *tlv = NULL; + struct wpa_ctrl *w = NULL; + size_t resp_len; + FILE *fp; + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + + /* TLV: BSSID */ + tlv = find_wrapper_tlv_by_id(req, TLV_BSSID); + if (tlv) { + memset(bssid, 0, sizeof(bssid)); + memcpy(bssid, tlv->value, tlv->len); + } else { + indigo_logger(LOG_LEVEL_ERROR, "missing BSSID configuration"); + goto done; + } + + /* TLV: ICON_FILE */ + tlv = find_wrapper_tlv_by_id(req, TLV_ICON_FILE); + if (tlv) { + memset(icon_file, 0, sizeof(icon_file)); + memcpy(icon_file, tlv->value, tlv->len); + } else { + indigo_logger(LOG_LEVEL_ERROR, "missing icon_file configuration"); + goto done; + } + + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + + /* remove previous downloaded temp icon file */ + snprintf(buffer, sizeof(buffer), "rm /tmp/osu-icon-*"); + system(buffer); + + /* set the default icon downloaded folder */ + snprintf(buffer, sizeof(buffer), "SET osu_dir /tmp"); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + + indigo_logger(LOG_LEVEL_DEBUG, "%s -> resp: %s\n", buffer, response); + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + + /* send icon request */ + snprintf(buffer, sizeof(buffer), "HS20_ICON_REQUEST %s %s", bssid, icon_file); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + + indigo_logger(LOG_LEVEL_DEBUG, "%s -> resp: %s\n", buffer, response); + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + + sleep(5); + + /* calculate checksum of the downloaded icon file */ + sprintf(buffer, "md5sum /tmp/osu-icon-1.png"); + indigo_logger(LOG_LEVEL_DEBUG, "cmd: %s", buffer); + + fp = popen(buffer, "r"); + if (fp == NULL) + goto done; + + fscanf(fp, "%s %*s", (char *)&icon_checksum); + pclose(fp); + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (status == TLV_VALUE_STATUS_OK) { + fill_wrapper_tlv_bytes(resp, TLV_PASSPOINT_ICON_CHECKSUM, strlen(icon_checksum), icon_checksum); + } + + if (w) { + wpa_ctrl_close(w); + } + return 0; +} \ No newline at end of file From 32e03db40f76f9e0cb64d71192fa0bb815326328 Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 11 Mar 2022 16:24:52 +0800 Subject: [PATCH 68/90] Move RESET_TYPE_INIT and RESET_TYPE_TEARDOWN code blocks --- indigo_api_callback_dut.c | 42 ++++++++++---------- indigo_api_callback_tp.c | 81 +++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 9efebad..1eda2fd 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -205,6 +205,11 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re indigo_logger(LOG_LEVEL_DEBUG, "Reset Type: %d", reset); } + if (reset == RESET_TYPE_INIT) { + open_tc_app_log(); + system("rm -rf /var/log/hostapd.log >/dev/null 2>/dev/null"); + } + memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_hapd_exec_file()); system(buffer); @@ -227,17 +232,12 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re message = TLV_VALUE_HOSTAPD_STOP_OK; } - /* Test case teardown case */ - if (reset == RESET_TYPE_TEARDOWN) { - close_tc_app_log(); - } - /* reset interfaces info */ clear_interfaces_resource(); - if (reset == RESET_TYPE_INIT) { - system("rm -rf /var/log/hostapd.log >/dev/null 2>/dev/null"); - open_tc_app_log(); + /* Test case teardown case */ + if (reset == RESET_TYPE_TEARDOWN) { + close_tc_app_log(); } fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); @@ -1742,19 +1742,8 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r indigo_logger(LOG_LEVEL_DEBUG, "Reset Type: %d", reset); } - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); - system(buffer); - sleep(2); - sta_configured = 0; - sta_started = 0; - - /* Test case teardown case */ - if (reset == RESET_TYPE_TEARDOWN) { - close_tc_app_log(); - } - if (reset == RESET_TYPE_INIT) { + open_tc_app_log(); /* clean the log */ system("rm -rf /var/log/supplicant.log >/dev/null 2>/dev/null"); @@ -1763,9 +1752,15 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r remove_pac_file(pac_file_path); memset(pac_file_path, 0, sizeof(pac_file_path)); } - open_tc_app_log(); } + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + system(buffer); + sleep(2); + sta_configured = 0; + sta_started = 0; + len = reset_interface_ip(get_wireless_interface()); if (len) { indigo_logger(LOG_LEVEL_DEBUG, "Failed to free IP address"); @@ -1779,6 +1774,11 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r message = TLV_VALUE_WPA_S_STOP_OK; } + /* Test case teardown case */ + if (reset == RESET_TYPE_TEARDOWN) { + close_tc_app_log(); + } + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, len == 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 3ddc456..3190b30 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -104,6 +104,32 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re reset = atoi(reset_type); indigo_logger(LOG_LEVEL_DEBUG, "Reset Type: %d", reset); } + + if (reset == RESET_TYPE_INIT) { + open_tc_app_log(); + len = unlink(get_hapd_conf_file()); + if (len) { + indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove hostapd.conf"); + } + + /* clean the log */ + snprintf(buffer, sizeof(buffer), "rm -rf %s >/dev/null 2>/dev/null", HAPD_LOG_FILE); + system(buffer); + memset(buffer, 0, sizeof(buffer)); +#ifdef _WTS_OPENWRT_ + /* Reset uci configurations */ + snprintf(buffer, sizeof(buffer), "uci -q delete wireless.wifi0.country"); + system(buffer); + + snprintf(buffer, sizeof(buffer), "uci -q delete wireless.wifi1.country"); + system(buffer); + + system("uci -q delete wireless.@wifi-iface[0].own_ie_override"); + system("uci -q delete wireless.@wifi-iface[1].own_ie_override"); +#endif + memset(band_transmitter, 0, sizeof(band_transmitter)); + } + memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_hapd_exec_file()); system(buffer); @@ -138,40 +164,18 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re reset_bridge(get_wlans_bridge()); reset_interface_ip(get_wireless_interface()); - close_tc_app_log(); } stop_loopback_data(NULL); - if (reset == RESET_TYPE_INIT) { - open_tc_app_log(); - len = unlink(get_hapd_conf_file()); - if (len) { - indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove hostapd.conf"); - } - - /* clean the log */ - snprintf(buffer, sizeof(buffer), "rm -rf %s >/dev/null 2>/dev/null", HAPD_LOG_FILE); - system(buffer); - memset(buffer, 0, sizeof(buffer)); -#ifdef _WTS_OPENWRT_ - /* Reset uci configurations */ - snprintf(buffer, sizeof(buffer), "uci -q delete wireless.wifi0.country"); - system(buffer); - - snprintf(buffer, sizeof(buffer), "uci -q delete wireless.wifi1.country"); - system(buffer); - - system("uci -q delete wireless.@wifi-iface[0].own_ie_override"); - system("uci -q delete wireless.@wifi-iface[1].own_ie_override"); -#endif - memset(band_transmitter, 0, sizeof(band_transmitter)); - } if (reset != RESET_TYPE_KEEP_CONFIG) { /* reset interfaces info */ clear_interfaces_resource(); } + if (reset == RESET_TYPE_TEARDOWN) { + close_tc_app_log(); + } fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); @@ -1098,6 +1102,17 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r reset = atoi(reset_type); indigo_logger(LOG_LEVEL_DEBUG, "Reset Type: %d", reset); } + if (reset == RESET_TYPE_INIT) { + open_tc_app_log(); + len = unlink(get_wpas_conf_file()); + if (len) { + indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove wpa_supplicant.conf"); + } + + /* clean the log */ + snprintf(buffer, sizeof(buffer), "rm -rf %s >/dev/null 2>/dev/null", WPAS_LOG_FILE); + system(buffer); + } memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); @@ -1128,20 +1143,8 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r set_channel_width(); } reconf_count = 0; - close_tc_app_log(); } - if (reset == RESET_TYPE_INIT) { - open_tc_app_log(); - len = unlink(get_wpas_conf_file()); - if (len) { - indigo_logger(LOG_LEVEL_DEBUG, "Failed to remove wpa_supplicant.conf"); - } - - /* clean the log */ - snprintf(buffer, sizeof(buffer), "rm -rf %s >/dev/null 2>/dev/null", WPAS_LOG_FILE); - system(buffer); - } if (reset == RESET_TYPE_RECONFIGURE) { reconf_count++; @@ -1190,6 +1193,10 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r message = TLV_VALUE_WPA_S_STOP_OK; } + if (reset == RESET_TYPE_TEARDOWN) { + close_tc_app_log(); + } + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, len == 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); From 41bbe51e20f81434e4ae2783b9e7f09a1a796683 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Mon, 14 Mar 2022 13:18:36 +0800 Subject: [PATCH 69/90] Add freq and he config in P2P persistent invitation --- indigo_api_callback_dut.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index efcc885..4ac9300 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -2422,7 +2422,7 @@ static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; - char freq[64]; + char freq[64], he[16]; size_t resp_len; int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_P2P_ADD_GROUP_NOT_OK; @@ -2440,6 +2440,11 @@ static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapp goto done; } + memset(he, 0, sizeof(he)); + tlv = find_wrapper_tlv_by_id(req, TLV_IEEE80211_AX); + if (tlv) + snprintf(he, sizeof(he), " he"); + /* Open wpa_supplicant UDS socket */ w = wpa_ctrl_open(get_wpas_ctrl_path()); if (!w) { @@ -2451,7 +2456,7 @@ static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapp memset(buffer, 0, sizeof(buffer)); memset(response, 0, sizeof(response)); - sprintf(buffer, "P2P_GROUP_ADD freq=%s", freq); + sprintf(buffer, "P2P_GROUP_ADD freq=%s%s", freq, he); resp_len = sizeof(response) - 1; wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); /* Check response */ @@ -3478,6 +3483,7 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; char addr[32], if_name[16], persist[32], p2p_dev_if[32]; + char freq[16], he[16]; size_t resp_len; int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_P2P_INVITE_NOT_OK; @@ -3517,10 +3523,23 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper memset(buffer, 0, sizeof(buffer)); memset(response, 0, sizeof(response)); - if (persist[0] != 0) - sprintf(buffer, "P2P_INVITE %s peer=%s", persist, addr); - else + if (persist[0] != 0) { + memset(he, 0, sizeof(he)); + tlv = find_wrapper_tlv_by_id(req, TLV_IEEE80211_AX); + if (tlv) + snprintf(he, sizeof(he), " he"); + + tlv = find_wrapper_tlv_by_id(req, TLV_FREQUENCY); + if (tlv) { + memset(freq, 0, sizeof(freq)); + memcpy(freq, tlv->value, tlv->len); + sprintf(buffer, "P2P_INVITE %s peer=%s%s freq=%s", persist, addr, he, freq); + } else { + sprintf(buffer, "P2P_INVITE %s peer=%s%s", persist, addr, he); + } + } else { sprintf(buffer, "P2P_INVITE group=%s peer=%s", if_name, addr); + } indigo_logger(LOG_LEVEL_DEBUG, "Command: %s", buffer); resp_len = sizeof(response) - 1; wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); From 05bcd8688fc590ad606f88c878850081fcddfb15 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Tue, 15 Mar 2022 14:09:51 +0800 Subject: [PATCH 70/90] Add new TLV to apply ignore_broadcast_ssid and adjust OOB attr --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 1 + indigo_api_callback_tp.c | 3 ++- vendor_specific_tp.c | 6 +++--- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 7ef6c1c..5ae52b5 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -254,6 +254,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_EAP_FRAG_SIZE, "EAP_FRAG_SIZE" }, { TLV_PERFORM_WPS_IE_FRAG, "PERFORM_WPS_IE_FRAG" }, { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, + { TLV_IGNORE_BROADCAST_SSID, "IGNORE_BROADCAST_SSID"}, { TLV_PERSISTENT, "PERSISTENT_GROUP" }, { TLV_WSC_CONFIG_ONLY, "WSC_CONFIG_ONLY" }, { TLV_ICON_FILE, "ICON_FILE" }, diff --git a/indigo_api.h b/indigo_api.h index 6064205..e46b77c 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -263,6 +263,7 @@ struct indigo_api { #define TLV_EAP_FRAG_SIZE 0x00ce #define TLV_PERFORM_WPS_IE_FRAG 0x00cf #define TLV_ADVICE_OF_CHARGE 0x00d0 +#define TLV_IGNORE_BROADCAST_SSID 0x00d1 #define TLV_PERSISTENT 0x00d2 #define TLV_WSC_CONFIG_ONLY 0x00d3 #define TLV_ICON_FILE 0x00d4 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 4999acf..828dab7 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -102,6 +102,7 @@ struct tlv_to_config_name maps[] = { { TLV_OSU_SERVER_URI, "osu_server_uri", 0 }, { TLV_OSU_METHOD, "osu_method_list", 0 }, { TLV_DOMAIN_LIST, "domain_name", 0 }, + { TLV_IGNORE_BROADCAST_SSID, "ignore_broadcast_ssid", 0 }, /* wpas, seperate? */ { TLV_STA_SSID, "ssid", 1 }, diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 31c9a0b..7a5095c 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -423,6 +423,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, cfg_item); } } + continue; } cfg = find_tlv_config(tlv->id); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 220f71e..d4fcadb 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -401,6 +401,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, cfg_item); } } + continue; } cfg = find_tlv_config(tlv->id); if (!cfg) { @@ -2070,4 +2071,4 @@ static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_w wpa_ctrl_close(w); } return 0; -} \ No newline at end of file +} diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 5696b6f..82d1ffb 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -606,11 +606,11 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_OOB_ONLY }, /* wps oob state */ /* * General * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ - { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ @@ -628,11 +628,11 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_OOB_ONLY }, /* wps oob state */ /* * General * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ - { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_COMMON }, /* wps oob state */ { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ @@ -650,11 +650,11 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ + { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_OOB_ONLY }, /* wps oob state */ /* * General * */ { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ - { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_COMMON }, /* wps oob state */ { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ From 1807e8765cc053e3367f5480fb45219deadba8ea Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Tue, 15 Mar 2022 16:21:11 +0800 Subject: [PATCH 71/90] Add P2P_DISABLED TLV --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback.h | 1 + indigo_api_callback_tp.c | 8 ++++---- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index b2544f1..91efe25 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -255,6 +255,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_ADVICE_OF_CHARGE, "ADVICE_OF_CHARGE"}, { TLV_PERSISTENT, "PERSISTENT_GROUP" }, { TLV_WSC_CONFIG_ONLY, "WSC_CONFIG_ONLY" }, + { TLV_P2P_DISABLED, "P2P_DISABLED" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 37dea36..9123e4e 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -264,6 +264,7 @@ struct indigo_api { #define TLV_ADVICE_OF_CHARGE 0x00d0 #define TLV_PERSISTENT 0x00d2 #define TLV_WSC_CONFIG_ONLY 0x00d3 +#define TLV_P2P_DISABLED 0x00d4 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index e26bb05..625b558 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -203,6 +203,7 @@ struct tlv_to_config_name wpas_global_maps[] = { { TLV_ACCESS_NETWORK_TYPE, "access_network_type", 0 }, { TLV_FREQ_LIST, "freq_list", 0 }, { TLV_UPDATE_CONFIG, "update_config", 0 }, + { TLV_P2P_DISABLED, "p2p_disabled", 0 }, }; struct tlv_to_config_name* find_wpas_global_config_name(int tlv_id) { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 292388f..b6a02b2 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1784,8 +1784,8 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper } else { } } else { - indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); - goto done; + indigo_logger(LOG_LEVEL_INFO, "Missed TLV_ROLE, Use default wireless IF"); + snprintf(if_name, sizeof(if_name), "%s", get_wireless_interface()); } /* TLV: TLV_STATIC_IP */ @@ -1832,8 +1832,8 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * } else { } } else { - indigo_logger(LOG_LEVEL_ERROR, "Missed TLV: TLV_ROLE"); - goto done; + snprintf(if_name, sizeof(if_name), "%s", get_wireless_interface()); + reset_interface_ip(if_name); } /* TLV: TLV_STATIC_IP */ From a111e495f3ab6f06f027fc4dc74f51acafd81462 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 22 Mar 2022 17:18:55 +0800 Subject: [PATCH 72/90] Remove Reset_Type KEEP_CONFIG --- indigo_api.h | 1 - indigo_api_callback_tp.c | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/indigo_api.h b/indigo_api.h index bd662aa..e1c7381 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -365,7 +365,6 @@ struct indigo_api { #define RESET_TYPE_INIT 0x01 #define RESET_TYPE_TEARDOWN 0x02 #define RESET_TYPE_RECONFIGURE 0x03 -#define RESET_TYPE_KEEP_CONFIG 0x04 #define WPA_CTRL_OK "OK" #define WPA_CTRL_FAIL "FAIL" diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 2ba243e..f0b38e4 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -169,11 +169,9 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re stop_loopback_data(NULL); + /* reset interfaces info */ + clear_interfaces_resource(); - if (reset != RESET_TYPE_KEEP_CONFIG) { - /* reset interfaces info */ - clear_interfaces_resource(); - } if (reset == RESET_TYPE_TEARDOWN) { close_tc_app_log(); } From 6b04fcdaad01434be2af13fe961012388b8ada30 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Fri, 25 Mar 2022 10:20:24 +0800 Subject: [PATCH 73/90] Add P2P_SET_EXT_LISTEN API --- indigo_api.c | 1 + indigo_api.h | 2 ++ indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index 0a9bec4..1f458a3 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -67,6 +67,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_STOP_GROUP, "P2P_STOP_GROUP", NULL, NULL }, { API_P2P_SET_SERV_DISC, "P2P_SET_SERV_DISC", NULL, NULL }, { API_STA_SEND_ICON_REQ, "STA_SEND_ICON_REQ", NULL, NULL }, + { API_P2P_SET_EXT_LISTEN, "P2P_SET_EXT_LISTEN", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index e1c7381..717999c 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -80,6 +80,7 @@ struct indigo_api { #define API_P2P_STOP_GROUP 0x2019 #define API_P2P_SET_SERV_DISC 0x201a #define API_STA_SEND_ICON_REQ 0x201b +#define API_P2P_SET_EXT_LISTEN 0x201c #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 @@ -355,6 +356,7 @@ struct indigo_api { #define TLV_VALUE_P2P_CONNECT_NOT_OK "Failed to trigger P2P connect" #define TLV_VALUE_P2P_INVITE_NOT_OK "Failed to invite P2P device" #define TLV_VALUE_P2P_SET_SERV_DISC_NOT_OK "Failed to set service discovery" +#define TLV_VALUE_P2P_SET_EXT_LISTEN_NOT_OK "Failed to set extended listen timing" #define TLV_VALUE_HS2_INSTALL_PPSMO_OK "PPSMO file is installed" #define TLV_VALUE_HS2_INSTALL_PPSMO_NOT_OK "Failed to install PPSMO file" diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 2b6d296..6c150e8 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -283,4 +283,5 @@ static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int set_ext_listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); #endif // __INDIGO_API_CALLBACK diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 7a5095c..5b61d5d 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -85,6 +85,7 @@ void register_apis() { register_api(API_P2P_INVITE, NULL, invite_p2p_handler); register_api(API_P2P_STOP_GROUP, NULL, stop_group_p2p_handler); register_api(API_P2P_SET_SERV_DISC, NULL, set_serv_disc_p2p_handler); + register_api(API_P2P_SET_EXT_LISTEN, NULL, set_ext_listen_p2p_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -3631,3 +3632,41 @@ static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_w } return 0; } + +static int set_ext_listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + struct wpa_ctrl *w = NULL; + char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; + size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + char *message = TLV_VALUE_P2P_SET_EXT_LISTEN_NOT_OK; + + /* Open wpa_supplicant UDS socket */ + w = wpa_ctrl_open(get_wpas_ctrl_path()); + if (!w) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); + status = TLV_VALUE_STATUS_NOT_OK; + message = TLV_VALUE_WPA_S_CTRL_NOT_OK; + goto done; + } + memset(buffer, 0, sizeof(buffer)); + memset(response, 0, sizeof(response)); + sprintf(buffer, "P2P_EXT_LISTEN 1000 4000"); + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, buffer, strlen(buffer), response, &resp_len, NULL); + /* Check response */ + if (strncmp(response, WPA_CTRL_OK, strlen(WPA_CTRL_OK)) != 0) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to execute the command. Response: %s", response); + goto done; + } + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + if (w) { + wpa_ctrl_close(w); + } + return 0; +} From 2d7c9322dc4f01bcbd331544ce619d7ab6b9401d Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Tue, 29 Mar 2022 11:14:06 +0800 Subject: [PATCH 74/90] Apply STA WSC IEs Fragmentation used in ITS-2013 (TCID#10290) --- indigo_api_callback_tp.c | 17 +++++++++++++++-- vendor_specific.h | 2 +- vendor_specific_tp.c | 28 +++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index f0b38e4..edd5f90 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1419,6 +1419,7 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; struct tlv_hdr *tlv = NULL; struct tlv_to_config_name* cfg = NULL; + int perform_wps_ie_frag = 0; #ifdef _OPENWRT_ #else system("rfkill unblock wlan"); @@ -1464,17 +1465,29 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe } } + /* wps settings */ + tlv = find_wrapper_tlv_by_id(req, TLV_PERFORM_WPS_IE_FRAG); + if (tlv) { + perform_wps_ie_frag = 1; + } + /* wps settings */ tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); if (tlv) { int j; + wps_setting *s = NULL; memset(value, 0, sizeof(value)); memcpy(value, tlv->value, tlv->len); /* To get STA wps vendor info */ - wps_setting *s = get_vendor_wps_settings(WPS_STA); - if (atoi(value)) { + if (perform_wps_ie_frag == 1) + s = get_vendor_wps_settings_for_ie_frag_test(WPS_STA); + else + s = get_vendor_wps_settings(WPS_STA); + if (!s) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to get vendor wps settings."); + } else if (atoi(value)) { for (j = 0; j < STA_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); diff --git a/vendor_specific.h b/vendor_specific.h index febfd9a..bc779a2 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -128,7 +128,7 @@ enum wps_device_role { #define GROUP_NUM (3) #define AP_SETTING_NUM (14) -#define STA_SETTING_NUM (5) +#define STA_SETTING_NUM (6) typedef struct _wps_setting { /* key-value for each setting pair */ diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 82d1ffb..e57a5ae 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -665,12 +665,32 @@ wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { }, }; -wps_setting wps_settings_sta[STA_SETTING_NUM] = { +wps_setting wps_settings_sta[GROUP_NUM][STA_SETTING_NUM] = { + { + /* + * General + * */ { WPS_CONFIG, SUPPORTED_CONF_METHOD_STA, WPS_COMMON }, /* config methods */ { WPS_DEV_NAME, "Intel Wireless STA", WPS_COMMON }, /* device name */ { WPS_MANUFACTURER, "Intel.com", WPS_COMMON }, /* manufacturer */ { WPS_MODEL_NAME, "Intel Wireless STA", WPS_COMMON }, /* model name */ { WPS_MODEL_NUMBER, "Intel Wireless STA-001", WPS_COMMON }, /* model number */ + { WPS_SERIAL_NUMBER, "STA-001", WPS_COMMON }, /* serial number */ + }, + { + /* + * Test purpose for WPS IE fragmentation. + * */ + { WPS_CONFIG, SUPPORTED_CONF_METHOD_STA, WPS_COMMON }, /* config methods */ + { WPS_DEV_NAME, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* device name */ + { WPS_MANUFACTURER, "1234567890abcdef1234567890abcdef1234567890abcdef1234567890", WPS_COMMON }, /* manufacturer */ + { WPS_MODEL_NAME, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* model name */ + { WPS_MODEL_NUMBER, "1234567890abcdef1234567890abcdef", WPS_COMMON }, /* model number */ + { WPS_SERIAL_NUMBER, "001", WPS_COMMON }, /* serial number */ + }, + { + {0} + } }; wps_setting* get_vendor_wps_settings(enum wps_device_role role) @@ -678,17 +698,19 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) if (role == WPS_AP) return wps_settings_ap[0]; else - return wps_settings_sta; + return wps_settings_sta[0]; } wps_setting* get_vendor_wps_settings_for_ie_frag_test(enum wps_device_role role) { /* - * Test purpose to enlarge wps ie payload and perform wps ie fragmentation automatically. (AP only) + * Test purpose to enlarge wps ie payload and perform wps ie fragmentation automatically. * */ if (role == WPS_AP) return wps_settings_ap[1]; + else if (role == WPS_STA) + return wps_settings_sta[1]; else return NULL; } From dd1f60ff0ac156a88c3ff0c22f9a550aa64ada7c Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Fri, 1 Apr 2022 10:28:43 +0800 Subject: [PATCH 75/90] Add TLV MANAGE_P2P and AP_STA_COEXIST --- indigo_api.c | 2 ++ indigo_api.h | 2 ++ indigo_api_callback.h | 2 ++ indigo_api_callback_tp.c | 18 +++++++++++++++++- vendor_specific.h | 3 +++ vendor_specific_dut.c | 17 ++++++++++------- vendor_specific_tp.c | 34 ++++++++++++++++++++++++++-------- 7 files changed, 62 insertions(+), 16 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 1f458a3..9f31bef 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -260,6 +260,8 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_WSC_CONFIG_ONLY, "WSC_CONFIG_ONLY" }, { TLV_ICON_FILE, "ICON_FILE" }, { TLV_P2P_DISABLED, "P2P_DISABLED" }, + { TLV_MANAGE_P2P, "MANAGE_P2P" }, + { TLV_AP_STA_COEXIST, "AP_STA_COEXIST" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 717999c..8c52f35 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -269,6 +269,8 @@ struct indigo_api { #define TLV_WSC_CONFIG_ONLY 0x00d3 #define TLV_ICON_FILE 0x00d4 #define TLV_P2P_DISABLED 0x00d5 +#define TLV_MANAGE_P2P 0x00d6 +#define TLV_AP_STA_COEXIST 0x00d7 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 6c150e8..a0b4cab 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -103,6 +103,7 @@ struct tlv_to_config_name maps[] = { { TLV_OSU_METHOD, "osu_method_list", 0 }, { TLV_DOMAIN_LIST, "domain_name", 0 }, { TLV_IGNORE_BROADCAST_SSID, "ignore_broadcast_ssid", 0 }, + { TLV_MANAGE_P2P, "manage_p2p", 0 }, /* wpas, seperate? */ { TLV_STA_SSID, "ssid", 1 }, @@ -138,6 +139,7 @@ struct tlv_to_config_name maps[] = { /* hapd + wpas */ { TLV_EAP_FRAG_SIZE, "fragment_size", 0 }, + { TLV_AP_STA_COEXIST, "ap_sta_coexist", 0 }, }; struct tlv_to_config_name semicolon_list[] = { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index f0b38e4..8b922de 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1086,6 +1086,7 @@ static int send_ap_arp_handler(struct packet_wrapper *req, struct packet_wrapper return 0; } +int delete_sta_if = 0; static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len = 0, reset = 0; char buffer[S_BUFFER_LEN*2], reset_type[16], buffer1[S_BUFFER_LEN], buffer2[S_BUFFER_LEN]; @@ -1197,6 +1198,11 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r close_tc_app_log(); } + if (delete_sta_if) { + delete_sta_interface(); + delete_sta_if = 0; + } + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, len == 0 ? TLV_VALUE_STATUS_OK : TLV_VALUE_STATUS_NOT_OK); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); @@ -1705,6 +1711,7 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe size_t resp_len; char *parameter[] = {"pidof", get_wpas_exec_file(), NULL}; struct tlv_hdr *tlv = NULL; + char if_name[32]; #ifdef _OPENWRT_ #else @@ -1717,6 +1724,15 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe system(buffer); sleep(3); + tlv = find_wrapper_tlv_by_id(req, TLV_AP_STA_COEXIST); + if (tlv) { + create_sta_interface(); + snprintf(if_name, sizeof(if_name), "%s_sta", get_wireless_interface()); + delete_sta_if = 1; + } else { + snprintf(if_name, sizeof(if_name), "%s", get_wireless_interface()); + } + tlv = find_wrapper_tlv_by_id(req, TLV_CONTROL_INTERFACE); if (tlv) { memset(buffer, 0, sizeof(buffer)); @@ -1756,7 +1772,7 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe get_wpas_full_exec_path(), get_wpas_conf_file(), get_wpas_debug_arguments(), - get_wireless_interface(), + if_name, WPAS_LOG_FILE); len = system(buffer); sleep(2); diff --git a/vendor_specific.h b/vendor_specific.h index febfd9a..0bf45bc 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -164,6 +164,9 @@ void openwrt_apply_radio_config(void); int detect_third_radio(void); #endif +void create_sta_interface(); +void delete_sta_interface(); + void configure_ap_enable_mbssid(); void configure_ap_radio_params(char *band, char *country, int channel, int chwidth); void start_ap_set_wlan_params(void *if_info); diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 320e359..6c83ff1 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -262,10 +262,11 @@ void start_ap_set_wlan_params(void *if_info) { printf("set_wlan_params: %s\n", buffer); } +/* Return addr of P2P-device if there is no GO or client interface */ int get_p2p_mac_addr(char *mac_addr, size_t size) { FILE *fp; char buffer[S_BUFFER_LEN], *ptr, addr[32]; - int error = 1; + int error = 1, match = 0; fp = popen("iw dev", "r"); if (fp) { @@ -273,22 +274,23 @@ int get_p2p_mac_addr(char *mac_addr, size_t size) { ptr = strstr(buffer, "addr"); if (ptr != NULL) { sscanf(ptr, "%*s %s", addr); - if (fgets(buffer, sizeof(buffer), fp) != NULL) { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { ptr = strstr(buffer, "type"); if (ptr != NULL) { ptr += 5; if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { snprintf(mac_addr, size, "%s", addr); error = 0; - break; + match = 1; } else if (!strncmp(ptr, "P2P-device", 10)) { snprintf(mac_addr, size, "%s", addr); error = 0; } - } else { - printf("Format changed??? Can't detect device type"); + break; } } + if (match) + break; } } pclose(fp); @@ -315,11 +317,12 @@ int get_p2p_group_if(char *if_name, size_t size) { if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { snprintf(if_name, size, "%s", name); error = 0; - break; } + break; } } - break; + if (!error) + break; } } pclose(fp); diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 82d1ffb..830a4f8 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -203,6 +203,22 @@ void interfaces_init() { #endif } +void create_sta_interface() { + char buffer[S_BUFFER_LEN]; + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "iw phy phy0 interface add %s_sta type managed >/dev/null 2>/dev/null", get_wireless_interface()); + system(buffer); +} + +void delete_sta_interface() { + char buffer[S_BUFFER_LEN]; + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "iw dev %s_sta del", get_wireless_interface()); + system(buffer); +} + /* Be invoked when start controlApp */ void vendor_init() { /* Make sure native hostapd/wpa_supplicant is inactive */ @@ -477,11 +493,11 @@ const struct sta_driver_ops sta_driver_platform2_ops = { .set_phy_mode = set_phy_mode_platform2, }; - +/* Return addr of P2P-device if there is no GO or client interface */ int get_p2p_mac_addr(char *mac_addr, size_t size) { FILE *fp; char buffer[S_BUFFER_LEN], *ptr, addr[32]; - int error = 1; + int error = 1, match = 0; fp = popen("iw dev", "r"); if (fp) { @@ -489,22 +505,23 @@ int get_p2p_mac_addr(char *mac_addr, size_t size) { ptr = strstr(buffer, "addr"); if (ptr != NULL) { sscanf(ptr, "%*s %s", addr); - if (fgets(buffer, sizeof(buffer), fp) != NULL) { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { ptr = strstr(buffer, "type"); if (ptr != NULL) { ptr += 5; if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { snprintf(mac_addr, size, "%s", addr); error = 0; - break; + match = 1; } else if (!strncmp(ptr, "P2P-device", 10)) { snprintf(mac_addr, size, "%s", addr); error = 0; } - } else { - printf("Format changed??? Can't detect device type"); + break; } } + if (match) + break; } } pclose(fp); @@ -531,11 +548,12 @@ int get_p2p_group_if(char *if_name, size_t size) { if (!strncmp(ptr, "P2P-GO", 6) || !strncmp(ptr, "P2P-client", 10)) { snprintf(if_name, size, "%s", name); error = 0; - break; } + break; } } - break; + if (!error) + break; } } pclose(fp); From 8010778a48313c74a3b04fc9b1706ca196a70e9f Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Fri, 1 Apr 2022 13:28:12 +0800 Subject: [PATCH 76/90] Remove ap_sta_coexist config --- indigo_api_callback.h | 1 - 1 file changed, 1 deletion(-) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index a0b4cab..f752f2b 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -139,7 +139,6 @@ struct tlv_to_config_name maps[] = { /* hapd + wpas */ { TLV_EAP_FRAG_SIZE, "fragment_size", 0 }, - { TLV_AP_STA_COEXIST, "ap_sta_coexist", 0 }, }; struct tlv_to_config_name semicolon_list[] = { From 0b0d20972d80dee85ed3c6cc48ae5b7b791862f4 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 12 Apr 2022 10:21:16 +0800 Subject: [PATCH 77/90] ITT-1178 Support DFS channels --- indigo_api_callback_dut.c | 28 +++++++++++++++++++++++++--- utils.c | 6 ++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 5b61d5d..d8200e7 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -30,6 +30,7 @@ static char pac_file_path[S_BUFFER_LEN] = {0}; struct interface_info* band_transmitter[16]; +struct interface_info* band_first_wlan[16]; extern struct sockaddr_in *tool_addr; int sta_configured = 0; int sta_started = 0; @@ -173,6 +174,7 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe } memset(band_transmitter, 0, sizeof(band_transmitter)); + memset(band_first_wlan, 0, sizeof(band_first_wlan)); vendor_device_reset(); @@ -235,6 +237,8 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re /* reset interfaces info */ clear_interfaces_resource(); + memset(band_transmitter, 0, sizeof(band_transmitter)); + memset(band_first_wlan, 0, sizeof(band_first_wlan)); /* Test case teardown case */ if (reset == RESET_TYPE_TEARDOWN) { @@ -301,10 +305,13 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ struct tlv_to_profile *profile = NULL; int semicolon_list_size = sizeof(semicolon_list) / sizeof(struct tlv_to_config_name); int hs20_icons_attached = 0; + int is_multiple_bssid = 0; #if HOSTAPD_SUPPORT_MBSSID - if (wlanp->mbssid_enable && !wlanp->transmitter) + if ((wlanp->mbssid_enable && !wlanp->transmitter) || (band_first_wlan[wlanp->band])) { sprintf(output, "bss=%s\nctrl_interface=%s\n", wlanp->ifname, HAPD_CTRL_PATH_DEFAULT); + is_multiple_bssid = 1; + } else sprintf(output, "ctrl_interface=%s\nctrl_interface_group=0\ninterface=%s\n", HAPD_CTRL_PATH_DEFAULT, wlanp->ifname); #else @@ -324,6 +331,11 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ memset(buffer, 0, sizeof(buffer)); memset(cfg_item, 0, sizeof(cfg_item)); + /* channel will be configured on the first wlan */ + if (is_multiple_bssid && (tlv->id == TLV_CHANNEL)) { + continue; + } + if (tlv->id == TLV_HE_6G_ONLY) { is_6g_only = 1; continue; @@ -800,14 +812,24 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe #if HOSTAPD_SUPPORT_MBSSID if (bss_info.mbssid_enable && !bss_info.transmitter) { if (band_transmitter[bss_info.band]) { + indigo_logger(LOG_LEVEL_DEBUG, "Append bss conf to %s", band_transmitter[bss_info.band]->hapd_conf_file); append_file(band_transmitter[bss_info.band]->hapd_conf_file, buffer, len); } memset(wlan->hapd_conf_file, 0, sizeof(wlan->hapd_conf_file)); } - else + else if (band_first_wlan[bss_info.band]) { + indigo_logger(LOG_LEVEL_DEBUG, "Append bss conf to %s", band_first_wlan[bss_info.band]->hapd_conf_file); + append_file(band_first_wlan[bss_info.band]->hapd_conf_file, buffer, len); + memset(wlan->hapd_conf_file, 0, sizeof(wlan->hapd_conf_file)); + } else #endif write_file(wlan->hapd_conf_file, buffer, len); } + + if (!band_first_wlan[bss_info.band]) { + /* For the first configured ap */ + band_first_wlan[bss_info.band] = wlan; + } } show_wireless_interface_info(); @@ -1234,7 +1256,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe get_key_value(mac_addr, response, "address"); } else { #if HOSTAPD_SUPPORT_MBSSID - if(wlan && wlan->mbssid_enable) { + if(bss_info.identifier >= 0) { sprintf(buff, "ssid[%d]", wlan->hapd_bss_id); get_key_value(connected_ssid, response, buff); sprintf(buff, "bssid[%d]", wlan->hapd_bss_id); diff --git a/utils.c b/utils.c index b9cc84d..9efcaf1 100644 --- a/utils.c +++ b/utils.c @@ -964,10 +964,8 @@ struct interface_info* assign_wireless_interface_info(struct bss_identifier_info interfaces[i].identifier = bss->identifier; interfaces[i].mbssid_enable = bss->mbssid_enable; interfaces[i].transmitter = bss->transmitter; - if (bss->mbssid_enable) { - interfaces[i].hapd_bss_id = band_mbssid_cnt[bss->band]; - band_mbssid_cnt[bss->band]++; - } + interfaces[i].hapd_bss_id = band_mbssid_cnt[bss->band]; + band_mbssid_cnt[bss->band]++; memset(interfaces[i].hapd_conf_file, 0, sizeof(interfaces[i].hapd_conf_file)); snprintf(interfaces[i].hapd_conf_file, sizeof(interfaces[i].hapd_conf_file), "%s/hostapd_%s.conf", HAPD_CONF_FILE_DEFAULT_PATH, interfaces[i].ifname); From 5158cd66c5bedc250bd2b660ce956e3b78159606 Mon Sep 17 00:00:00 2001 From: Kenny Date: Fri, 15 Apr 2022 13:51:28 +0800 Subject: [PATCH 78/90] ITT-1178 Use single hostapd conf for multiple vaps Change platform codes as well --- indigo_api_callback_tp.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index c31932e..e192819 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -31,6 +31,7 @@ struct sta_platform_config sta_hw_config = {PHYMODE_AUTO, CHWIDTH_AUTO, false, false}; struct interface_info* band_transmitter[16]; +struct interface_info* band_first_wlan[16]; #ifdef _WTS_OPENWRT_ int rrm = 0, he_mu_edca = 0; @@ -128,7 +129,6 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re system("uci -q delete wireless.@wifi-iface[0].own_ie_override"); system("uci -q delete wireless.@wifi-iface[1].own_ie_override"); #endif - memset(band_transmitter, 0, sizeof(band_transmitter)); } memset(buffer, 0, sizeof(buffer)); @@ -171,6 +171,8 @@ static int stop_ap_handler(struct packet_wrapper *req, struct packet_wrapper *re /* reset interfaces info */ clear_interfaces_resource(); + memset(band_transmitter, 0, sizeof(band_transmitter)); + memset(band_first_wlan, 0, sizeof(band_first_wlan)); if (reset == RESET_TYPE_TEARDOWN) { close_tc_app_log(); @@ -267,12 +269,14 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int enable_wps = 0, is_g_mode = 0, is_a_mode = 0, use_mbss = 0; int bss_load_tlv = 0; int perform_wps_ie_frag = 0; + int is_multiple_bssid = 0; #if HOSTAPD_SUPPORT_MBSSID - if (wlanp->mbssid_enable && !wlanp->transmitter) + if ((wlanp->mbssid_enable && !wlanp->transmitter) || (band_first_wlan[wlanp->band])) { sprintf(output, "bss=%s\n", wlanp->ifname); - else + is_multiple_bssid = 1; + } else sprintf(output, "ctrl_interface_group=0\ninterface=%s\n", wlanp->ifname); #else sprintf(output, "ctrl_interface_group=0\ninterface=%s\n", wlanp->ifname); @@ -288,6 +292,11 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ memset(buffer, 0, sizeof(buffer)); memset(cfg_item, 0, sizeof(cfg_item)); + /* channel will be configured on the first wlan */ + if (is_multiple_bssid && (tlv->id == TLV_CHANNEL)) { + continue; + } + /* This is used when hostapd will use multiple lines to * configure multiple items in the same configuration parameter * (use semicolon to separate multiple configurations) */ @@ -703,14 +712,25 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe #if HOSTAPD_SUPPORT_MBSSID if (bss_info.mbssid_enable && !bss_info.transmitter) { if (band_transmitter[bss_info.band]) { + indigo_logger(LOG_LEVEL_DEBUG, "Append bss conf to %s", band_transmitter[bss_info.band]->hapd_conf_file); append_file(band_transmitter[bss_info.band]->hapd_conf_file, buffer, len); } memset(wlan->hapd_conf_file, 0, sizeof(wlan->hapd_conf_file)); } + else if (band_first_wlan[bss_info.band]) { + indigo_logger(LOG_LEVEL_DEBUG, "Append bss conf to %s", band_first_wlan[bss_info.band]->hapd_conf_file); + append_file(band_first_wlan[bss_info.band]->hapd_conf_file, buffer, len); + memset(wlan->hapd_conf_file, 0, sizeof(wlan->hapd_conf_file)); + } else #endif write_file(wlan->hapd_conf_file, buffer, len); } + + if (!band_first_wlan[bss_info.band]) { + /* For the first configured ap */ + band_first_wlan[bss_info.band] = wlan; + } } show_wireless_interface_info(); @@ -895,6 +915,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); if (wlan) { get_mac_address(mac_addr, sizeof(mac_addr), wlan->ifname); + indigo_logger(LOG_LEVEL_DEBUG, "Get mac_addr %s\n", mac_addr); status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; } From ba9910684142a8fc6f9a8d11f45f9a6998fca0fc Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 15 Apr 2022 15:55:37 +0800 Subject: [PATCH 79/90] ITS-2148 to remove the response TLV WSC_PIN_CODE when runs PBC test case. --- indigo_api_callback_dut.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 5b61d5d..b7919ea 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -3326,6 +3326,7 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp int i, status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_AP_START_WPS_NOT_OK; struct tlv_hdr *tlv = NULL; + int use_dynamic_pin = 0; memset(buffer, 0 ,sizeof(buffer)); sprintf(buffer, "%s -B -t -c %s -i %s -f /var/log/supplicant.log", @@ -3342,6 +3343,7 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp memcpy(pin_code, tlv->value, tlv->len); if (strlen(pin_code) == 1 && atoi(pin_code) == 0) sprintf(buffer, "WPS_PIN any"); + use_dynamic_pin = 1; else sprintf(buffer, "WPS_PIN any %s", pin_code); } else { @@ -3372,7 +3374,7 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); - if (status == TLV_VALUE_STATUS_OK) { + if (status == TLV_VALUE_STATUS_OK && use_dynamic_pin) { fill_wrapper_tlv_bytes(resp, TLV_WSC_PIN_CODE, strlen(response), response); } if (w) { From dd1c1728caf817a957b105327c2deaf0f9a88c07 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Mon, 18 Apr 2022 13:00:45 +0800 Subject: [PATCH 80/90] ITS-2148 to fix build error. --- indigo_api_callback_dut.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index b7919ea..db9a34b 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -3341,11 +3341,12 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp if (tlv) { memset(pin_code, 0, sizeof(pin_code)); memcpy(pin_code, tlv->value, tlv->len); - if (strlen(pin_code) == 1 && atoi(pin_code) == 0) + if (strlen(pin_code) == 1 && atoi(pin_code) == 0) { sprintf(buffer, "WPS_PIN any"); use_dynamic_pin = 1; - else + } else { sprintf(buffer, "WPS_PIN any %s", pin_code); + } } else { sprintf(buffer, "WPS_PBC"); } From 93aacae3a6c8c994a6b7be544eda44b67ba5e67e Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 20 Apr 2022 13:55:25 +0800 Subject: [PATCH 81/90] Fix 6g wlan is not up on 10453_1 Store channel for the following code segments --- indigo_api_callback_dut.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 77b70dd..d49472f 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -331,9 +331,14 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ memset(buffer, 0, sizeof(buffer)); memset(cfg_item, 0, sizeof(cfg_item)); - /* channel will be configured on the first wlan */ - if (is_multiple_bssid && (tlv->id == TLV_CHANNEL)) { - continue; + if (tlv->id == TLV_CHANNEL) { + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + channel = atoi(value); + if (is_multiple_bssid) { + /* channel will be configured on the first wlan */ + continue; + } } if (tlv->id == TLV_HE_6G_ONLY) { @@ -470,12 +475,6 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ memcpy(band, tlv->value, tlv->len); } - if (tlv->id == TLV_CHANNEL) { - memset(value, 0, sizeof(value)); - memcpy(value, tlv->value, tlv->len); - channel = atoi(value); - } - if (tlv->id == TLV_HE_OPER_CHWIDTH) { memset(value, 0, sizeof(value)); memcpy(value, tlv->value, tlv->len); From f4a610229889c492f2000e33c53b8e26438c4830 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Thu, 21 Apr 2022 16:20:49 +0800 Subject: [PATCH 82/90] ITS-2152: Add API handler for STA_ENABLE_WSC --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback.h | 1 + indigo_api_callback_dut.c | 116 ++++++++++++++++++++++++++++---------- 4 files changed, 88 insertions(+), 31 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index 9f31bef..16e4b11 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -68,6 +68,7 @@ struct indigo_api indigo_api_list[] = { { API_P2P_SET_SERV_DISC, "P2P_SET_SERV_DISC", NULL, NULL }, { API_STA_SEND_ICON_REQ, "STA_SEND_ICON_REQ", NULL, NULL }, { API_P2P_SET_EXT_LISTEN, "P2P_SET_EXT_LISTEN", NULL, NULL }, + { API_STA_ENABLE_WSC, "STA_ENABLE_WSC", NULL, NULL }, /* Network operation. E.g., get/set IP address, get MAC address, send the UDP data and reset */ { API_GET_IP_ADDR, "GET_IP_ADDR", NULL, NULL }, { API_GET_MAC_ADDR, "GET_MAC_ADDR", NULL, NULL }, diff --git a/indigo_api.h b/indigo_api.h index 8c52f35..33e2f61 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -81,6 +81,7 @@ struct indigo_api { #define API_P2P_SET_SERV_DISC 0x201a #define API_STA_SEND_ICON_REQ 0x201b #define API_P2P_SET_EXT_LISTEN 0x201c +#define API_STA_ENABLE_WSC 0x201d #define API_GET_IP_ADDR 0x5000 #define API_GET_MAC_ADDR 0x5001 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index f752f2b..a7525ee 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -273,6 +273,7 @@ static int set_sta_channel_width_handler(struct packet_wrapper *req, struct pack static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int enable_wsc_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* P2P */ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index d49472f..5a02709 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -87,6 +87,7 @@ void register_apis() { register_api(API_P2P_STOP_GROUP, NULL, stop_group_p2p_handler); register_api(API_P2P_SET_SERV_DISC, NULL, set_serv_disc_p2p_handler); register_api(API_P2P_SET_EXT_LISTEN, NULL, set_ext_listen_p2p_handler); + register_api(API_STA_ENABLE_WSC, NULL, enable_wsc_sta_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -1859,26 +1860,6 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra } } - /* wps settings */ - tlv = find_wrapper_tlv_by_id(wrapper, TLV_WSC_OOB); - if (tlv) { - memset(value, 0, sizeof(value)); - memcpy(value, tlv->value, tlv->len); - /* To get STA wps vendor info */ - wps_setting *s = get_vendor_wps_settings(WPS_STA); - if (!s) { - indigo_logger(LOG_LEVEL_WARNING, "Failed to get STA wps settings"); - } else if (atoi(value)) { - for (i = 0; i < STA_SETTING_NUM; i++) { - memset(cfg_item, 0, sizeof(cfg_item)); - sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); - strcat(buffer, cfg_item); - } - } - /* WPS: no network profile configuration and return. */ - goto done; - } - strcat(buffer, "network={\n"); #ifdef _RESERVED_ @@ -3342,21 +3323,13 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; - char pin_code[64], if_name[32]; + char pin_code[64]; size_t resp_len; - int i, status = TLV_VALUE_STATUS_NOT_OK; + int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_AP_START_WPS_NOT_OK; struct tlv_hdr *tlv = NULL; int use_dynamic_pin = 0; - memset(buffer, 0 ,sizeof(buffer)); - sprintf(buffer, "%s -B -t -c %s -i %s -f /var/log/supplicant.log", - get_wpas_full_exec_path(), - get_wpas_conf_file(), - get_wireless_interface()); - system(buffer); - sleep(2); - memset(buffer, 0, sizeof(buffer)); tlv = find_wrapper_tlv_by_id(req, TLV_PIN_CODE); if (tlv) { @@ -3372,7 +3345,7 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp sprintf(buffer, "WPS_PBC"); } - /* Open hostapd UDS socket */ + /* Open wpa_supplicant UDS socket */ w = wpa_ctrl_open(get_wpas_ctrl_path()); if (!w) { indigo_logger(LOG_LEVEL_ERROR, "Failed to connect to wpa_supplicant"); @@ -3694,3 +3667,84 @@ static int set_ext_listen_p2p_handler(struct packet_wrapper *req, struct packet_ } return 0; } + +static int enable_wsc_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; + char buffer[L_BUFFER_LEN]; + char value[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN], buf[S_BUFFER_LEN]; + int i, len = 0, status = TLV_VALUE_STATUS_NOT_OK; + struct tlv_hdr *tlv = NULL; + struct tlv_to_config_name* cfg = NULL; + +#ifdef _OPENWRT_ +#else + system("rfkill unblock wlan"); + sleep(1); +#endif + + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_wpas_exec_file()); + system(buffer); + sleep(3); + + /* Generate configuration */ + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, "ctrl_interface=%s\nap_scan=1\npmf=1\n", WPAS_CTRL_PATH_DEFAULT); + + for (i = 0; i < req->tlv_num; i++) { + cfg = find_wpas_global_config_name(req->tlv[i]->id); + if (cfg) { + memset(value, 0, sizeof(value)); + memcpy(value, req->tlv[i]->value, req->tlv[i]->len); + sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); + strcat(buffer, cfg_item); + } + } + + /* wps settings */ + tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); + if (tlv) { + memset(value, 0, sizeof(value)); + memcpy(value, tlv->value, tlv->len); + /* To get STA wps vendor info */ + wps_setting *s = get_vendor_wps_settings(WPS_STA); + if (!s) { + indigo_logger(LOG_LEVEL_WARNING, "Failed to get STA wps settings"); + } else if (atoi(value)) { + for (i = 0; i < STA_SETTING_NUM; i++) { + memset(cfg_item, 0, sizeof(cfg_item)); + sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); + strcat(buffer, cfg_item); + } + indigo_logger(LOG_LEVEL_DEBUG, "Appended STA WSC data"); + } else { + indigo_logger(LOG_LEVEL_WARNING, "Failed to append STA WSC data"); + } + } else { + indigo_logger(LOG_LEVEL_WARNING, "No WSC TLV found. Failed to append STA WSC data"); + } + + len = strlen(buffer); + + if (len) { + write_file(get_wpas_conf_file(), buffer, len); + } + + /* Start wpa supplicant */ + memset(buffer, 0 ,sizeof(buffer)); + sprintf(buffer, "%s -B -t -c %s -i %s -f /var/log/supplicant.log", + get_wpas_full_exec_path(), + get_wpas_conf_file(), + get_wireless_interface()); + system(buffer); + sleep(2); + + status = TLV_VALUE_STATUS_OK; + message = TLV_VALUE_WPA_S_START_UP_OK; + +done: + fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); + fill_wrapper_tlv_byte(resp, TLV_STATUS, status); + fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); + return 0; +} From e5d9de425834e5fa1275e971fd695039acc01499 Mon Sep 17 00:00:00 2001 From: WFA-RickWang Date: Sat, 23 Apr 2022 11:03:22 +0800 Subject: [PATCH 83/90] add wps_independent parameter to support multiple WPS APs --- indigo_api.c | 1 + indigo_api.h | 1 + indigo_api_callback.h | 1 + 3 files changed, 3 insertions(+) diff --git a/indigo_api.c b/indigo_api.c index 9f31bef..f03d3e3 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -262,6 +262,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_P2P_DISABLED, "P2P_DISABLED" }, { TLV_MANAGE_P2P, "MANAGE_P2P" }, { TLV_AP_STA_COEXIST, "AP_STA_COEXIST" }, + { TLV_WPS_INDEPENDENT, "WPS_INDEPENDENT" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 8c52f35..1ebdeb8 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -271,6 +271,7 @@ struct indigo_api { #define TLV_P2P_DISABLED 0x00d5 #define TLV_MANAGE_P2P 0x00d6 #define TLV_AP_STA_COEXIST 0x00d7 +#define TLV_WPS_INDEPENDENT 0x00d8 // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index f752f2b..304bcf4 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -104,6 +104,7 @@ struct tlv_to_config_name maps[] = { { TLV_DOMAIN_LIST, "domain_name", 0 }, { TLV_IGNORE_BROADCAST_SSID, "ignore_broadcast_ssid", 0 }, { TLV_MANAGE_P2P, "manage_p2p", 0 }, + { TLV_WPS_INDEPENDENT, "wps_independent", 0 }, /* wpas, seperate? */ { TLV_STA_SSID, "ssid", 1 }, From 1425eb67c001362e1101ce9e7eb511877bb4dc3a Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Tue, 3 May 2022 17:01:20 +0800 Subject: [PATCH 84/90] Update the naming of P2P handlers and add comments --- indigo_api.h | 4 ++-- indigo_api_callback.h | 20 ++++++++-------- indigo_api_callback_dut.c | 50 +++++++++++++++++++++------------------ vendor_specific_dut.c | 12 ++++++---- vendor_specific_tp.c | 12 ++++++---- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/indigo_api.h b/indigo_api.h index 8c52f35..0b47ae6 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -300,8 +300,8 @@ struct indigo_api { #define TLV_BAND_5GHZ "5GHz" #define TLV_BAND_6GHZ "6GHz" -#define TLV_VALUE_APP_VERSION "v1.0" -#define TLV_VALUE_TEST_PLATFORM_APP_VERSION "v1.0" +#define TLV_VALUE_APP_VERSION "v2.0" +#define TLV_VALUE_TEST_PLATFORM_APP_VERSION "v2.0" #define TLV_VALUE_OK "OK" #define TLV_VALUE_NOT_OK "Failed" #define TLV_VALUE_INSUFFICIENT_TLV "TLV is insufficient to run the command" diff --git a/indigo_api_callback.h b/indigo_api_callback.h index f752f2b..4ded01f 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -275,14 +275,14 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp); /* P2P */ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int stop_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int set_ext_listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int p2p_find_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int p2p_listen_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int add_p2p_group_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int stop_p2p_group_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int p2p_start_wps_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int p2p_connect_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int get_p2p_intent_value_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int p2p_invite_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int set_p2p_serv_disc_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +static int set_p2p_ext_listen_handler(struct packet_wrapper *req, struct packet_wrapper *resp); #endif // __INDIGO_API_CALLBACK diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 5b61d5d..9b4654c 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -76,16 +76,16 @@ void register_apis() { register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL); register_api(API_STA_POWER_SAVE, NULL, NULL); register_api(API_P2P_START_UP, NULL, start_up_p2p_handler); - register_api(API_P2P_FIND, NULL, find_p2p_handler); - register_api(API_P2P_LISTEN, NULL, listen_p2p_handler); - register_api(API_P2P_ADD_GROUP, NULL, add_group_p2p_handler); - register_api(API_P2P_START_WPS, NULL, start_wps_p2p_handler); - register_api(API_P2P_CONNECT, NULL, connect_p2p_handler); - register_api(API_P2P_GET_INTENT_VALUE, NULL, get_intent_value_p2p_handler); - register_api(API_P2P_INVITE, NULL, invite_p2p_handler); - register_api(API_P2P_STOP_GROUP, NULL, stop_group_p2p_handler); - register_api(API_P2P_SET_SERV_DISC, NULL, set_serv_disc_p2p_handler); - register_api(API_P2P_SET_EXT_LISTEN, NULL, set_ext_listen_p2p_handler); + register_api(API_P2P_FIND, NULL, p2p_find_handler); + register_api(API_P2P_LISTEN, NULL, p2p_listen_handler); + register_api(API_P2P_ADD_GROUP, NULL, add_p2p_group_handler); + register_api(API_P2P_START_WPS, NULL, p2p_start_wps_handler); + register_api(API_P2P_CONNECT, NULL, p2p_connect_handler); + register_api(API_P2P_GET_INTENT_VALUE, NULL, get_p2p_intent_value_handler); + register_api(API_P2P_INVITE, NULL, p2p_invite_handler); + register_api(API_P2P_STOP_GROUP, NULL, stop_p2p_group_handler); + register_api(API_P2P_SET_SERV_DISC, NULL, set_p2p_serv_disc_handler); + register_api(API_P2P_SET_EXT_LISTEN, NULL, set_p2p_ext_listen_handler); } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -1313,7 +1313,7 @@ static int start_loopback_server(struct packet_wrapper *req, struct packet_wrapp char tool_udp_port[16]; char if_name[32]; - /* Find network interface. If bridge exists, then use it. Otherwise, it uses the initiation value. */ + /* Find network interface. If P2P Group or bridge exists, then use it. Otherwise, it uses the initiation value. */ memset(local_ip, 0, sizeof(local_ip)); if (get_p2p_group_if(if_name, sizeof(if_name)) == 0 && find_interface_ip(local_ip, sizeof(local_ip), if_name)) { indigo_logger(LOG_LEVEL_DEBUG, "use %s", if_name); @@ -2347,7 +2347,7 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe return 0; } -static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int p2p_find_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; size_t resp_len; @@ -2386,7 +2386,7 @@ static int find_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *r return 0; } -static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int p2p_listen_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; size_t resp_len; @@ -2425,7 +2425,7 @@ static int listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper return 0; } -static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int add_p2p_group_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; char freq[64], he[16]; @@ -2483,7 +2483,7 @@ static int add_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapp return 0; } -static int stop_group_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int stop_p2p_group_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; int persist = 0; @@ -2527,6 +2527,7 @@ static int stop_group_p2p_handler(struct packet_wrapper *req, struct packet_wrap } if (persist == 1) { + /* Can use global ctrl if global ctrl is initialized */ get_p2p_dev_if(p2p_dev_if, sizeof(p2p_dev_if)); indigo_logger(LOG_LEVEL_DEBUG, "P2P Dev IF: %s", p2p_dev_if); /* Open wpa_supplicant UDS socket */ @@ -2538,7 +2539,7 @@ static int stop_group_p2p_handler(struct packet_wrapper *req, struct packet_wrap goto done; } - /* Clear the persistent group */ + /* Clear the persistent group with id 0 */ memset(buffer, 0, sizeof(buffer)); memset(response, 0, sizeof(response)); sprintf(buffer, "REMOVE_NETWORK 0"); @@ -2563,7 +2564,7 @@ static int stop_group_p2p_handler(struct packet_wrapper *req, struct packet_wrap return 0; } -static int start_wps_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int p2p_start_wps_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; char pin_code[64], if_name[32]; @@ -2966,7 +2967,7 @@ static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct pack return 0; } -static int connect_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int p2p_connect_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; char pin_code[64], if_name[32]; @@ -3228,7 +3229,7 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper return 0; } -static int get_intent_value_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int get_p2p_intent_value_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_OK; char *message = TLV_VALUE_OK; char response[S_BUFFER_LEN]; @@ -3485,7 +3486,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe return 0; } -static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int p2p_invite_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; char addr[32], if_name[16], persist[32], p2p_dev_if[32]; @@ -3510,12 +3511,14 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper memset(persist, 0, sizeof(persist)); tlv = find_wrapper_tlv_by_id(req, TLV_PERSISTENT); if (tlv) { - snprintf(persist, sizeof(persist), "persistent=0"); + /* Assume persistent group id is 0 */ + snprintf(persist, sizeof(persist), "persistent=0"); } else if (get_p2p_group_if(if_name, sizeof(if_name)) != 0) { message = "Failed to get P2P Group Interface"; goto done; } + /* Can use global ctrl if global ctrl is initialized */ get_p2p_dev_if(p2p_dev_if, sizeof(p2p_dev_if)); indigo_logger(LOG_LEVEL_DEBUG, "P2P Dev IF: %s", p2p_dev_if); /* Open wpa_supplicant UDS socket */ @@ -3567,7 +3570,7 @@ static int invite_p2p_handler(struct packet_wrapper *req, struct packet_wrapper return 0; } -static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int set_p2p_serv_disc_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[BUFFER_LEN], response[BUFFER_LEN]; char addr[32], p2p_dev_if[32]; @@ -3586,6 +3589,7 @@ static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_w /* Add bonjour and upnp Service */ } + /* Can use global ctrl if global ctrl is initialized */ get_p2p_dev_if(p2p_dev_if, sizeof(p2p_dev_if)); indigo_logger(LOG_LEVEL_DEBUG, "P2P Dev IF: %s", p2p_dev_if); /* Open wpa_supplicant UDS socket */ @@ -3633,7 +3637,7 @@ static int set_serv_disc_p2p_handler(struct packet_wrapper *req, struct packet_w return 0; } -static int set_ext_listen_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { +static int set_p2p_ext_listen_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; char buffer[S_BUFFER_LEN], response[BUFFER_LEN]; size_t resp_len; diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 6c83ff1..8d986df 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -299,6 +299,7 @@ int get_p2p_mac_addr(char *mac_addr, size_t size) { return error; } +/* Get the name of P2P Group(GO or Client) interface */ int get_p2p_group_if(char *if_name, size_t size) { FILE *fp; char buffer[S_BUFFER_LEN], *ptr, name[32]; @@ -331,26 +332,29 @@ int get_p2p_group_if(char *if_name, size_t size) { return error; } +/* "iw dev" doesn't show the name of P2P device. The naming rule is based on wpa_supplicant */ int get_p2p_dev_if(char *if_name, size_t size) { snprintf(if_name, size, "p2p-dev-%s", get_wireless_interface()); return 0; } +/* Append IP range config and start dhcpd */ void start_dhcp_server(char *if_name, char *ip_addr) { char buffer[S_BUFFER_LEN]; char ip_sub[32], *ptr; FILE *fp; - /* + /* Avoid using system dhcp server service snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); system(buffer); snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); system(buffer); */ - // dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf p2p-wlp2s0-0 - // Avoid apparmor check because we manually start dhcpd + /* Sample command from isc-dhcp-server: dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf p2p-wlp2s0-0 */ + + /* Avoid apparmor check because we manually start dhcpd */ memset(ip_sub, 0, sizeof(ip_sub)); ptr = strrchr(ip_addr, '.'); memcpy(ip_sub, ip_addr, ptr - ip_addr); @@ -371,7 +375,7 @@ void start_dhcp_server(char *if_name, char *ip_addr) void stop_dhcp_server() { - //system("systemctl stop isc-dhcp-server.service"); + /* system("systemctl stop isc-dhcp-server.service"); */ system("killall dhcpd 1>/dev/null 2>/dev/null"); } diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index dda7ae1..3d4fdb7 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -530,6 +530,7 @@ int get_p2p_mac_addr(char *mac_addr, size_t size) { return error; } +/* Get the name of P2P Group(GO or Client) interface */ int get_p2p_group_if(char *if_name, size_t size) { FILE *fp; char buffer[S_BUFFER_LEN], *ptr, name[32]; @@ -562,21 +563,22 @@ int get_p2p_group_if(char *if_name, size_t size) { return error; } - +/* Append IP range config and start dhcpd */ void start_dhcp_server(char *if_name, char *ip_addr) { char buffer[S_BUFFER_LEN]; char ip_sub[32], *ptr; FILE *fp; - /* + /* Avoid using system dhcp server service snprintf(buffer, sizeof(buffer), "sed -i -e 's/INTERFACESv4=\".*\"/INTERFACESv4=\"%s\"/g' /etc/default/isc-dhcp-server", if_name); system(buffer); snprintf(buffer, sizeof(buffer), "systemctl restart isc-dhcp-server.service"); system(buffer); */ - // dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf p2p-wlp2s0-0 - // Avoid apparmor check because we manually start dhcpd + /* Sample command from isc-dhcp-server: dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf p2p-wlp2s0-0 */ + + /* Avoid apparmor check because we manually start dhcpd */ memset(ip_sub, 0, sizeof(ip_sub)); ptr = strrchr(ip_addr, '.'); memcpy(ip_sub, ip_addr, ptr - ip_addr); @@ -597,7 +599,7 @@ void start_dhcp_server(char *if_name, char *ip_addr) void stop_dhcp_server() { - //system("systemctl stop isc-dhcp-server.service"); + /* system("systemctl stop isc-dhcp-server.service"); */ system("killall dhcpd 1>/dev/null 2>/dev/null"); } From 802e93548ce7c20e75562e8d3e6dbefb094cb99a Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Fri, 6 May 2022 17:11:59 +0800 Subject: [PATCH 85/90] ITT-1188 WPS Code refactoring - change WPS TLV from WSC_OOB to WPS_ENABLE (ControlAppC) Remove proprietary code. --- indigo_api.c | 2 +- indigo_api.h | 5 +++- indigo_api_callback_dut.c | 28 +++++++++-------- indigo_api_callback_tp.c | 27 ++++++++++------- vendor_specific_dut.c | 63 ++------------------------------------- 5 files changed, 41 insertions(+), 84 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index bf5cf5d..084d205 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -251,7 +251,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_PIN_CODE, "PIN_CODE" }, { TLV_P2P_CONN_TYPE, "P2P_CONN_TYPE" }, { TLV_HS20_OPERATING_CLASS_INDICATION, "HS20_OPERATING_CLASS_INDICATION"}, - { TLV_WSC_OOB, "WSC_OOB" }, + { TLV_WPS_ENABLE, "WPS_ENABLE" }, { TLV_UPDATE_CONFIG, "UPDATE_CONFIG" }, { TLV_EAP_FRAG_SIZE, "EAP_FRAG_SIZE" }, { TLV_PERFORM_WPS_IE_FRAG, "PERFORM_WPS_IE_FRAG" }, diff --git a/indigo_api.h b/indigo_api.h index 32e572b..91dafd5 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -260,7 +260,7 @@ struct indigo_api { #define TLV_PIN_CODE 0x00c9 #define TLV_P2P_CONN_TYPE 0x00ca #define TLV_HS20_OPERATING_CLASS_INDICATION 0x00cb -#define TLV_WSC_OOB 0x00cc +#define TLV_WPS_ENABLE 0x00cc #define TLV_UPDATE_CONFIG 0x00cd #define TLV_EAP_FRAG_SIZE 0x00ce #define TLV_PERFORM_WPS_IE_FRAG 0x00cf @@ -378,6 +378,9 @@ struct indigo_api { #define P2P_CONN_TYPE_JOIN 0x01 #define P2P_CONN_TYPE_AUTH 0x02 +#define WPS_ENABLE_NORMAL 0x01 +#define WPS_ENABLE_OOB 0x02 + struct indigo_api* get_api_by_id(int id); struct indigo_tlv* get_tlv_by_id(int id); char* get_api_type_by_id(int id); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 1c7d8f2..0be0945 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -406,26 +406,27 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } /* wps settings */ - if (tlv->id == TLV_WSC_OOB) { + if (tlv->id == TLV_WPS_ENABLE) { int j; /* To get AP wps vendor info */ wps_setting *s = get_vendor_wps_settings(WPS_AP); if (!s) { - indigo_logger(LOG_LEVEL_WARNING, "Failed to get AP wps settings"); + indigo_logger(LOG_LEVEL_WARNING, "Failed to get APUT WPS settings"); continue; } enable_wps = 1; memcpy(buffer, tlv->value, tlv->len); - if (atoi(buffer)) { - /* Use OOB */ + if (atoi(buffer) == WPS_ENABLE_OOB) { + /* WPS OOB: Out-of-Box */ for (j = 0; j < AP_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); strcat(output, cfg_item); } - } else { - /* NOT use OOB: Configure manually. */ + indigo_logger(LOG_LEVEL_INFO, "APUT Configure WPS: OOB."); + } else if (atoi(buffer) == WPS_ENABLE_NORMAL){ + /* WPS Normal: Configure manually. */ for (j = 0; j < AP_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); /* set wps state */ @@ -441,6 +442,9 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } strcat(output, cfg_item); } + indigo_logger(LOG_LEVEL_INFO, "APUT Configure WPS: Manually Configured."); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Unknown WPS TLV value: %d (TLV ID 0x%04x)", atoi(buffer), tlv->id); } continue; } @@ -581,7 +585,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } } - /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WSC_OOB */ + /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WPS_ENABLE */ if (enable_wps) { if (use_mbss) { /* The wps test for mbss should always be dual concurrent. */ @@ -3706,23 +3710,23 @@ static int enable_wsc_sta_handler(struct packet_wrapper *req, struct packet_wrap } /* wps settings */ - tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); + tlv = find_wrapper_tlv_by_id(req, TLV_WPS_ENABLE); if (tlv) { memset(value, 0, sizeof(value)); memcpy(value, tlv->value, tlv->len); /* To get STA wps vendor info */ wps_setting *s = get_vendor_wps_settings(WPS_STA); if (!s) { - indigo_logger(LOG_LEVEL_WARNING, "Failed to get STA wps settings"); - } else if (atoi(value)) { + indigo_logger(LOG_LEVEL_WARNING, "Failed to get STAUT WPS settings"); + } else if (atoi(value) == WPS_ENABLE_NORMAL) { for (i = 0; i < STA_SETTING_NUM; i++) { memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[i].wkey, s[i].value); strcat(buffer, cfg_item); } - indigo_logger(LOG_LEVEL_DEBUG, "Appended STA WSC data"); + indigo_logger(LOG_LEVEL_INFO, "STAUT Configure WPS"); } else { - indigo_logger(LOG_LEVEL_WARNING, "Failed to append STA WSC data"); + indigo_logger(LOG_LEVEL_ERROR, "Invalid WPS TLV value: %d (TLV ID 0x%04x)", atoi(value), tlv->id); } } else { indigo_logger(LOG_LEVEL_WARNING, "No WSC TLV found. Failed to append STA WSC data"); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index e192819..e4640b3 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -369,7 +369,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } /* wps settings */ - if (tlv->id == TLV_WSC_OOB) { + if (tlv->id == TLV_WPS_ENABLE) { int j; wps_setting *s = NULL; @@ -380,18 +380,19 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ else s = get_vendor_wps_settings(WPS_AP); if (!s) { - indigo_logger(LOG_LEVEL_ERROR, "Failed to get vendor wps settings."); + indigo_logger(LOG_LEVEL_ERROR, "Failed to get AP WPS settings."); continue; } - if (atoi(buffer)) { - /* Use OOB */ + if (atoi(buffer) == WPS_ENABLE_OOB) { + /* WPS OOB: Out-of-Box */ for (j = 0; j < AP_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); strcat(output, cfg_item); } - } else { - /* NOT use OOB: Configure manually. */ + indigo_logger(LOG_LEVEL_INFO, "AP Configure WPS: OOB."); + } else if (atoi(buffer) == WPS_ENABLE_NORMAL) { + /* WPS Normal: Configure manually. */ for (j = 0; j < AP_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); /* set wps state */ @@ -407,6 +408,9 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ } strcat(output, cfg_item); } + indigo_logger(LOG_LEVEL_INFO, "AP Configure WPS: Manually Configured."); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Unknown WPS TLV value: %d (TLV ID 0x%04x)", atoi(buffer), tlv->id); } continue; } @@ -538,7 +542,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ add_mu_edca_params(output); } - /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WSC_OOB */ + /* add rf band according to TLV_BSS_IDENTIFIER/TLV_HW_MODE/TLV_WPS_ENABLE */ if (enable_wps) { if (use_mbss) { /* The wps test for mbss should always be dual concurrent. */ @@ -1499,7 +1503,7 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe } /* wps settings */ - tlv = find_wrapper_tlv_by_id(req, TLV_WSC_OOB); + tlv = find_wrapper_tlv_by_id(req, TLV_WPS_ENABLE); if (tlv) { int j; wps_setting *s = NULL; @@ -1513,13 +1517,16 @@ static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrappe else s = get_vendor_wps_settings(WPS_STA); if (!s) { - indigo_logger(LOG_LEVEL_ERROR, "Failed to get vendor wps settings."); - } else if (atoi(value)) { + indigo_logger(LOG_LEVEL_ERROR, "Failed to get AP WPS settings."); + } else if (atoi(value) == WPS_ENABLE_NORMAL) { for (j = 0; j < STA_SETTING_NUM; j++) { memset(cfg_item, 0, sizeof(cfg_item)); sprintf(cfg_item, "%s=%s\n", s[j].wkey, s[j].value); strcat(buffer, cfg_item); } + indigo_logger(LOG_LEVEL_INFO, "STA Configure WPS"); + } else { + indigo_logger(LOG_LEVEL_ERROR, "Invalid WPS TLV value: %d (TLV ID 0x%04x)", atoi(value), tlv->id); } } diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 8d986df..eef2f0a 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -392,61 +392,6 @@ void stop_dhcp_client() system("killall dhclient 1>/dev/null 2>/dev/null"); } -wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = { - { - /* - * WPS OOB required. (Not-Configured OOB state) - * */ - { WPS_OOB_SSID, "Openwrt-WPS-dut", WPS_OOB_ONLY }, /* ap broadcasts ssid */ - { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ - { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ - { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ - { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ - { WPS_OOB_STATE, WPS_OOB_NOT_CONFIGURED, WPS_OOB_ONLY }, /* wps oob state */ - /* - * General - * */ - { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ - { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ - { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ - { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ - { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ - { WPS_MODEL_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* model name */ - { WPS_MODEL_NUMBER, "Openwrt Wireless AP-001", WPS_COMMON }, /* model number */ - { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ - }, - { - /* - * WPS OOB required. (Configured OOB state) - * */ - { WPS_OOB_SSID, "Openwrt-WPS-dut", WPS_OOB_ONLY }, /* ap broadcasts ssid */ - { WPS_OOB_AUTH_TYPE, "WPA-PSK", WPS_OOB_ONLY }, /* authentication type */ - { WPS_OOB_ENC_TYPE, "CCMP", WPS_OOB_ONLY }, /* encryption type */ - { WPS_OOB_WPA_VER, "2", WPS_OOB_ONLY }, /* wpa version. 1: wpa, 2: wpa2 */ - { WPS_OOB_PSK, "1qaz2wsx", WPS_OOB_ONLY }, /* passphrass */ - { WPS_OOB_STATE, WPS_OOB_CONFIGURED, WPS_OOB_ONLY }, /* wps oob state */ - /* - * General - * */ - { WPS_OOB_AP_PIN, "12345670", WPS_COMMON }, /* wps ap pin */ - { WPS_CONFIG, SUPPORTED_CONF_METHOD_AP, WPS_COMMON }, /* config methods */ - { WPS_DEV_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* device name */ - { WPS_DEV_TYPE, "6-0050F204-1", WPS_COMMON }, /* primary device type */ - { WPS_MANUFACTURER, "OpenwrtProject.org", WPS_COMMON }, /* manufacturer */ - { WPS_MODEL_NAME, "Openwrt Wireless AP", WPS_COMMON }, /* model name */ - { WPS_MODEL_NUMBER, "Openwrt Wireless AP-001", WPS_COMMON }, /* model number */ - { WPS_SERIAL_NUMBER, "OA14998888", WPS_COMMON }, /* serial number */ - }, -}; - -wps_setting wps_settings_sta[STA_SETTING_NUM] = { - { WPS_CONFIG, SUPPORTED_CONF_METHOD_STA, WPS_COMMON }, /* config methods */ - { WPS_DEV_NAME, "Intel Wireless STA", WPS_COMMON }, /* device name */ - { WPS_MANUFACTURER, "Intel.com", WPS_COMMON }, /* manufacturer */ - { WPS_MODEL_NAME, "Intel Wireless STA", WPS_COMMON }, /* model name */ - { WPS_MODEL_NUMBER, "Intel Wireless STA-001", WPS_COMMON }, /* model number */ -}; - wps_setting *p_wps_setting = NULL; wps_setting customized_wps_settings_ap[AP_SETTING_NUM]; wps_setting customized_wps_settings_sta[STA_SETTING_NUM]; @@ -493,7 +438,7 @@ wps_setting* __get_wps_setting(int len, char *buffer, enum wps_device_role role) wps_setting* get_vendor_wps_settings(enum wps_device_role role) { /* - * Please implement the function to get wps OOB and required settings as per vendor's direction. + * Please implement the vendor proprietary function to get WPS OOB and required settings. * */ #define WSC_SETTINGS_FILE_AP "/tmp/wsc_settings_APUT" #define WSC_SETTINGS_FILE_STA "/tmp/wsc_settings_STAUT" @@ -518,8 +463,7 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) indigo_logger(LOG_LEVEL_INFO, "wsc settings APUT: no data"); } } else { - // use default - return wps_settings_ap[0]; + return NULL; } } else { if (0 == access(WSC_SETTINGS_FILE_STA, F_OK)) { @@ -532,8 +476,7 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) indigo_logger(LOG_LEVEL_INFO, "wsc settings STAUT: no data"); } } else { - // use default - return wps_settings_sta; + return NULL; } } } From 0358fb5460dfaab93f89b7b5f3ef1a118022958d Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Sun, 8 May 2022 22:30:47 +0800 Subject: [PATCH 86/90] fix typo and rename for backup file. --- indigo_api.h | 2 +- indigo_api_callback_dut.c | 4 ++-- indigo_api_callback_tp.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/indigo_api.h b/indigo_api.h index 91dafd5..c0a48f9 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -290,7 +290,7 @@ struct indigo_api { #define TLV_P2P_INTENT_VALUE 0xa00b #define TLV_WSC_SSID 0xa00c #define TLV_WSC_WPA_KEY_MGMT 0xa00d -#define TLV_WSC_WPA_PASSPHRASS 0xa00e +#define TLV_WSC_WPA_PASSPHRASE 0xa00e #define TLV_PASSPOINT_ICON_CHECKSUM 0xa00f /* TLV Value */ diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 0be0945..e1e085d 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -3412,7 +3412,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe // APUT struct _cfg_cred cfg_creds[] = { {"ssid", "ssid=", {0}, TLV_WSC_SSID}, - {"wpa_passphrase", "wpa_passphrase=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"wpa_passphrase", "wpa_passphrase=", {0}, TLV_WSC_WPA_PASSPHRASE}, {"wpa_key_mgmt", "wpa_key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} }; count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); @@ -3436,7 +3436,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe // STAUT struct _cfg_cred cfg_creds[] = { {"ssid", "ssid=", {0}, TLV_WSC_SSID}, - {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASE}, {"key_mgmt", "key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} }; count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index e4640b3..ab7587f 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -1179,7 +1179,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r /* wpas conf file rename and send */ memset(buffer, 0, sizeof(buffer)); memset(buffer1, 0, sizeof(buffer1)); - snprintf(buffer1, sizeof(buffer1), "%s.m%d", get_wpas_conf_file(), reconf_count); + snprintf(buffer1, sizeof(buffer1), "%s.reconfig_%d", get_wpas_conf_file(), reconf_count); snprintf(buffer, sizeof(buffer), "mv %s %s", get_wpas_conf_file(), buffer1); system(buffer); http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, WPAS_UPLOAD_API, buffer1); @@ -1187,7 +1187,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r /* wpas log file rename and send */ memset(buffer, 0, sizeof(buffer)); memset(buffer2, 0, sizeof(buffer2)); - snprintf(buffer2, sizeof(buffer2), "%s.m%d", WPAS_LOG_FILE, reconf_count); + snprintf(buffer2, sizeof(buffer2), "%s.reconfig_%d", WPAS_LOG_FILE, reconf_count); snprintf(buffer, sizeof(buffer), "mv %s %s", WPAS_LOG_FILE, buffer2); system(buffer); http_file_post(inet_ntoa(tool_addr->sin_addr), TOOL_POST_PORT, WPAS_UPLOAD_API, buffer2); @@ -1952,7 +1952,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe // Test Platform: STA struct _cfg_cred cfg_creds[] = { {"ssid", "ssid=", {0}, TLV_WSC_SSID}, - {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"psk", "psk=", {0}, TLV_WSC_WPA_PASSPHRASE}, {"key_mgmt", "key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} }; count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); @@ -1966,7 +1966,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe // Test Platform: AP struct _cfg_cred cfg_creds[] = { {"ssid", "ssid=", {0}, TLV_WSC_SSID}, - {"wpa_passphrase", "wpa_passphrase=", {0}, TLV_WSC_WPA_PASSPHRASS}, + {"wpa_passphrase", "wpa_passphrase=", {0}, TLV_WSC_WPA_PASSPHRASE}, {"wpa_key_mgmt", "wpa_key_mgmt=", {0}, TLV_WSC_WPA_KEY_MGMT} }; count = sizeof(cfg_creds)/sizeof(struct _cfg_cred); From 4d4801a726bdc30cd2f5d35a6e6d4e225744e2b7 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Mon, 9 May 2022 11:24:14 +0800 Subject: [PATCH 87/90] Add error message if failing to get wps settings. --- vendor_specific_dut.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index eef2f0a..f859063 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -463,6 +463,7 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) indigo_logger(LOG_LEVEL_INFO, "wsc settings APUT: no data"); } } else { + indigo_logger(LOG_LEVEL_ERROR, "APUT: WPS Erorr. Failed to get settings."); return NULL; } } else { @@ -476,6 +477,7 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) indigo_logger(LOG_LEVEL_INFO, "wsc settings STAUT: no data"); } } else { + indigo_logger(LOG_LEVEL_ERROR, "STAUT: WPS Erorr. Failed to get settings."); return NULL; } } From 6865b46daf62b27784c25b56ef4018a42bd36738 Mon Sep 17 00:00:00 2001 From: WFA-EnzoTsai Date: Thu, 12 May 2022 16:54:43 +0800 Subject: [PATCH 88/90] ITS-2150 to modify sta_start_wps function to alarm PIN code with dash --- indigo_api_callback_dut.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index e1e085d..7c2c322 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -3343,8 +3343,15 @@ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapp if (strlen(pin_code) == 1 && atoi(pin_code) == 0) { sprintf(buffer, "WPS_PIN any"); use_dynamic_pin = 1; - } else { + } else if (strlen(pin_code) == 4 || strlen(pin_code) == 8){ sprintf(buffer, "WPS_PIN any %s", pin_code); + } else { + /* Please implement the function to strip the extraneous + * hyphen(dash) attached with 4 or 8-digit PIN code, then + * start WPS PIN Registration with stripped PIN code. + * */ + indigo_logger(LOG_LEVEL_ERROR, "Unrecognized PIN: %s", pin_code); + goto done; } } else { sprintf(buffer, "WPS_PBC"); From b24805b6be0dc140bffd6bf36bf9568544227cd0 Mon Sep 17 00:00:00 2001 From: WFA-achuang Date: Wed, 1 Jun 2022 20:32:54 +0800 Subject: [PATCH 89/90] Add pwr constraint and spectrum mgmt req in hostapd conf for 6G radio --- indigo_api.c | 4 +++- indigo_api.h | 2 ++ indigo_api_callback.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/indigo_api.c b/indigo_api.c index 084d205..7560c63 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -263,7 +263,9 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_P2P_DISABLED, "P2P_DISABLED" }, { TLV_MANAGE_P2P, "MANAGE_P2P" }, { TLV_AP_STA_COEXIST, "AP_STA_COEXIST" }, - { TLV_WPS_INDEPENDENT, "WPS_INDEPENDENT" }, + { TLV_WPS_INDEPENDENT, "WPS_INDEPENDENT" }, + { TLV_LOCAL_PWR_CONST, "LOCAL_PWR_CONST" }, + { TLV_SPECTRUM_MGMT_REQ, "SPECTRUM_MGMT_REQ" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index c0a48f9..cf3b3d7 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -273,6 +273,8 @@ struct indigo_api { #define TLV_MANAGE_P2P 0x00d6 #define TLV_AP_STA_COEXIST 0x00d7 #define TLV_WPS_INDEPENDENT 0x00d8 +#define TLV_LOCAL_PWR_CONST 0x00d9 +#define TLV_SPECTRUM_MGMT_REQ 0x00da // class ResponseTLV // List of TLV used in the QuickTrack API response and ACK messages from the DUT diff --git a/indigo_api_callback.h b/indigo_api_callback.h index a7fdb75..5e1f765 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -105,6 +105,8 @@ struct tlv_to_config_name maps[] = { { TLV_IGNORE_BROADCAST_SSID, "ignore_broadcast_ssid", 0 }, { TLV_MANAGE_P2P, "manage_p2p", 0 }, { TLV_WPS_INDEPENDENT, "wps_independent", 0 }, + { TLV_LOCAL_PWR_CONST, "local_pwr_constraint", 0 }, + { TLV_SPECTRUM_MGMT_REQ, "spectrum_mgmt_required", 0 }, /* wpas, seperate? */ { TLV_STA_SSID, "ssid", 1 }, From 6c94e9743e1e42c80dcc718d6db2ab99dce4ccd4 Mon Sep 17 00:00:00 2001 From: Kenny Date: Tue, 21 Jun 2022 15:58:13 +0800 Subject: [PATCH 90/90] Update Makefile APP_VERSION --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3d6aec7..1f012d1 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ TYPE = laptop # Role is dut or platform ROLE = dut # Package Version -APP_VERSION = "1.2.0" +APP_VERSION = "2.0.0" VERSION = "" OBJS = main.o eloop.o indigo_api.o indigo_packet.o utils.o wpa_ctrl.o