Skip to content

Commit

Permalink
[nrf fromlist] Add WPS feature flag
Browse files Browse the repository at this point in the history
Protects WPS code in case the DUT doesn't support it yet.

Upstream-Pr: Wi-FiQuickTrack/Wi-FiQuickTrack-ControlAppC#5

Signed-off-by: Triveni Danda <[email protected]>
(cherry picked from commit ed5aeaa)
  • Loading branch information
krish2718 authored and cvinayak committed Oct 19, 2023
1 parent 7c8daba commit ccb503f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ endif

# Feature flags
# Enable by default
CFLAGS += -DCONFIG_P2P -DCONFIG_WNM -DCONFIG_HS20 -DCONFIG_AP
CFLAGS += -DCONFIG_P2P -DCONFIG_WNM -DCONFIG_HS20 -DCONFIG_AP -DCONFIG_WPS

# Define the package version
ifneq ($(VERSION),)
Expand Down
9 changes: 7 additions & 2 deletions indigo_api_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ 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);
static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrapper *resp);

#ifdef CONFIG_AP
/* AP */
Expand All @@ -255,8 +253,11 @@ 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);
#endif /* End Of CONFIG_WNM */
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);
#ifdef CONFIG_WPS
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);
#endif /* End Of CONFIG_WPS */
#endif /* End Of CONFIG_AP */

/* STA */
Expand All @@ -277,8 +278,12 @@ static int sta_add_credential_handler(struct packet_wrapper *req, struct packet_
static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct packet_wrapper *resp);
static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp);
#endif /* End Of CONFIG_HS20 */
#ifdef CONFIG_WPS
static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp);
static int enable_wsc_sta_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);
#endif /* End Of CONFIG_WPS */

#ifdef CONFIG_P2P
/* P2P */
Expand Down
171 changes: 87 additions & 84 deletions indigo_api_callback_dut.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ 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);
#ifdef CONFIG_WPS
register_api(API_GET_WSC_PIN, NULL, get_wsc_pin_handler);
register_api(API_GET_WSC_CRED, NULL, get_wsc_cred_handler);
register_api(API_STA_START_WPS, NULL, start_wps_sta_handler);
register_api(API_STA_ENABLE_WSC, NULL, enable_wsc_sta_handler);
#endif /* End Of CONFIG_WPS */
#ifdef CONFIG_AP
/* AP */
register_api(API_AP_START_UP, NULL, start_ap_handler);
Expand All @@ -70,11 +74,10 @@ void register_apis() {
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_SCAN, NULL, sta_scan_handler);
#ifdef CONFIG_WNM
register_api(API_STA_SEND_BTM_QUERY, NULL, send_sta_btm_query_handler);
#endif /* End Of CONFIG_WNM */
register_api(API_STA_SCAN, NULL, sta_scan_handler);
register_api(API_STA_START_WPS, NULL, start_wps_sta_handler);
#ifdef CONFIG_HS20
register_api(API_STA_SEND_ANQP_QUERY, NULL, send_sta_anqp_query_handler);
register_api(API_STA_HS2_ASSOCIATE, NULL, set_sta_hs2_associate_handler);
Expand All @@ -97,7 +100,6 @@ void register_apis() {
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);
#endif /*End Of CONFIG_P2P */
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) {
Expand Down Expand Up @@ -3338,7 +3340,7 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *
return 0;
}


#ifdef CONFIG_WPS
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;
Expand Down Expand Up @@ -3654,6 +3656,87 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe
}
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];
int len = 0, status = TLV_VALUE_STATUS_NOT_OK;
unsigned int i = 0;
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_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 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_INFO, "STAUT Configure WPS");
} else {
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");
}

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;

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;
}
#endif /* End Of CONFIG_WPS */

#ifdef CONFIG_P2P
static int set_p2p_serv_disc_handler(struct packet_wrapper *req, struct packet_wrapper *resp) {
Expand Down Expand Up @@ -3762,83 +3845,3 @@ static int set_p2p_ext_listen_handler(struct packet_wrapper *req, struct packet_
}
#endif /* End OF CONFIG_P2P */

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];
int len = 0, status = TLV_VALUE_STATUS_NOT_OK;
size_t i = 0;
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_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 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_INFO, "STAUT Configure WPS");
} else {
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");
}

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;

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;
}
10 changes: 8 additions & 2 deletions indigo_api_callback_tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ int rrm = 0, he_mu_edca = 0;
#endif

extern struct sockaddr_in *tool_addr;
#ifdef CONFIG_WPS
extern wps_setting* get_vendor_wps_settings_for_ie_frag_test(enum wps_device_role role);
#endif
int additional_tp_id = 0;

void register_apis() {
Expand All @@ -53,7 +55,9 @@ 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);
#ifdef CONFIG_WPS
register_api(API_GET_WSC_CRED, NULL, get_wsc_cred_handler);
#endif /* End Of CONFIG_WPS */
#ifdef CONFIG_HS20
register_api(API_STA_SEND_ICON_REQ, NULL, send_sta_icon_req_handler);
#endif /* End Of CONFIG_HS20 */
Expand Down Expand Up @@ -425,7 +429,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_
strcat(output, cfg_item);
continue;
}

#ifdef CONFIG_WPS
/* wps settings */
if (tlv->id == TLV_PERFORM_WPS_IE_FRAG) {
perform_wps_ie_frag = 1;
Expand Down Expand Up @@ -477,6 +481,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_
}
continue;
}
#endif /* End Of CONFIG_WPS */
cfg = find_tlv_config(tlv->id);
if (!cfg) {
indigo_logger(LOG_LEVEL_ERROR, "Unknown AP configuration name: TLV ID 0x%04x", tlv->id);
Expand Down Expand Up @@ -2107,6 +2112,7 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *
return 0;
}

#ifdef CONFIG_WPS
struct _cfg_cred {
char *key;
char *tok;
Expand Down Expand Up @@ -2212,7 +2218,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe
}
return 0;
}

#endif /* End Of CONFIG_WPS */

#ifdef CONFIG_HS20
static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp) {
Expand Down
2 changes: 2 additions & 0 deletions vendor_specific_dut.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ void stop_dhcp_client()
system("killall dhclient 1>/dev/null 2>/dev/null");
}

#ifdef CONFIG_WPS
wps_setting *p_wps_setting = NULL;
wps_setting customized_wps_settings_ap[AP_SETTING_NUM];
wps_setting customized_wps_settings_sta[STA_SETTING_NUM];
Expand Down Expand Up @@ -500,3 +501,4 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role)

return NULL;
}
#endif /* End Of CONFIG_WPS */
2 changes: 2 additions & 0 deletions vendor_specific_tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ void stop_dhcp_client()
system("killall dhclient 1>/dev/null 2>/dev/null");
}

#ifdef CONFIG_WPS
wps_setting wps_settings_ap[GROUP_NUM][AP_SETTING_NUM] = {
{
/*
Expand Down Expand Up @@ -738,4 +739,5 @@ wps_setting* get_vendor_wps_settings_for_ie_frag_test(enum wps_device_role role)
else
return NULL;
}
#endif /* End Of CONFIG_WPS */
#endif /* _TEST_PLATFORM_ */

0 comments on commit ccb503f

Please sign in to comment.