Skip to content

Commit

Permalink
[nrf fromlist] Add HotSpot 2.0 feature flag
Browse files Browse the repository at this point in the history
Protects HS2.0 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 32bc648)
  • Loading branch information
krish2718 authored and cvinayak committed Oct 19, 2023
1 parent 30ba0b8 commit b9efbe9
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 120 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
CFLAGS += -DCONFIG_P2P -DCONFIG_WNM -DCONFIG_HS20

# Define the package version
ifneq ($(VERSION),)
Expand Down
5 changes: 4 additions & 1 deletion indigo_api_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,15 @@ static int send_sta_reconnect_handler(struct packet_wrapper *req, struct packet_
#ifdef CONFIG_WNM
static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp);
#endif /* End Of CONFIG_WNM */
static int send_sta_anqp_query_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);
#ifdef CONFIG_HS20
static int send_sta_anqp_query_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 send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp);
#endif /* End Of CONFIG_HS20 */
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);
#ifdef CONFIG_P2P
Expand Down
240 changes: 122 additions & 118 deletions indigo_api_callback_dut.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ void register_apis() {
#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_SEND_ANQP_QUERY, NULL, send_sta_anqp_query_handler);
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);
register_api(API_STA_ADD_CREDENTIAL, NULL, sta_add_credential_handler);
register_api(API_STA_INSTALL_PPSMO, NULL, set_sta_install_ppsmo_handler);
#endif /* End Of CONFIG_HS20 */
/* TODO: Add the handlers */
register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL);
register_api(API_STA_POWER_SAVE, NULL, NULL);
Expand Down Expand Up @@ -2240,123 +2242,6 @@ static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_
}
#endif /* End Of CONFIG_WNM */

static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp) {
int len, status = TLV_VALUE_STATUS_NOT_OK;
char *message = TLV_VALUE_WPA_S_BTM_QUERY_NOT_OK;
char buffer[1024];
char response[1024];
char bssid[256];
char anqp_info_id[256];
struct tlv_hdr *tlv = NULL;
struct wpa_ctrl *w = NULL;
size_t resp_len, i;
char *token = NULL;
char *delimit = ";";
char realm[S_BUFFER_LEN];

/* It may need to check whether to just scan */
memset(buffer, 0, sizeof(buffer));
len = sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT);
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;
}
sleep(10);

/* 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 {
goto done;
}

/* TLV: ANQP_INFO_ID */
tlv = find_wrapper_tlv_by_id(req, TLV_ANQP_INFO_ID);
if (tlv) {
memset(anqp_info_id, 0, sizeof(anqp_info_id));
memcpy(anqp_info_id, tlv->value, tlv->len);
}

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, ",");
}
}
}

/* Send command to wpa_supplicant UDS socket */
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);
/* 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;
}

#ifdef CONFIG_P2P
static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp) {
char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK;
Expand Down Expand Up @@ -2957,6 +2842,124 @@ static int sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *r
return 0;
}

#ifdef CONFIG_HS20
static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp) {
int len, status = TLV_VALUE_STATUS_NOT_OK;
char *message = TLV_VALUE_WPA_S_BTM_QUERY_NOT_OK;
char buffer[1024];
char response[1024];
char bssid[256];
char anqp_info_id[256];
struct tlv_hdr *tlv = NULL;
struct wpa_ctrl *w = NULL;
size_t resp_len, i;
char *token = NULL;
char *delimit = ";";
char realm[S_BUFFER_LEN];

/* It may need to check whether to just scan */
memset(buffer, 0, sizeof(buffer));
len = sprintf(buffer, "ctrl_interface=%s\nap_scan=1\n", WPAS_CTRL_PATH_DEFAULT);
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;
}
sleep(10);

/* 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 {
goto done;
}

/* TLV: ANQP_INFO_ID */
tlv = find_wrapper_tlv_by_id(req, TLV_ANQP_INFO_ID);
if (tlv) {
memset(anqp_info_id, 0, sizeof(anqp_info_id));
memcpy(anqp_info_id, tlv->value, tlv->len);
}

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, ",");
}
}
}

/* Send command to wpa_supplicant UDS socket */
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);
/* 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 set_sta_hs2_associate_handler(struct packet_wrapper *req, struct packet_wrapper *resp) {
int status = TLV_VALUE_STATUS_NOT_OK;
size_t resp_len;
Expand Down Expand Up @@ -3228,6 +3231,7 @@ static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct pack

return 0;
}
#endif /* End Of CONFIG_HS20 */


static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp) {
Expand Down
4 changes: 4 additions & 0 deletions indigo_api_callback_tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ 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);
#ifdef CONFIG_HS20
register_api(API_STA_SEND_ICON_REQ, NULL, send_sta_icon_req_handler);
#endif /* End Of CONFIG_HS20 */
/* AP */
register_api(API_AP_START_UP, NULL, start_ap_handler);
register_api(API_AP_STOP, NULL, stop_ap_handler);
Expand Down Expand Up @@ -2206,6 +2208,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe
}


#ifdef CONFIG_HS20
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;
Expand Down Expand Up @@ -2305,3 +2308,4 @@ static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_w
}
return 0;
}
#endif /* End Of CONFIG_HS20 */

0 comments on commit b9efbe9

Please sign in to comment.