From 50dd48135d98a0451cbc2890b8952c576d2e1da6 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:18 +0530 Subject: [PATCH 01/20] Fix build issues without syslog This should be controlled by syslog feature define. Signed-off-by: Chaitanya Tata --- utils.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils.c b/utils.c index d152fb4..0694cf4 100644 --- a/utils.c +++ b/utils.c @@ -18,7 +18,9 @@ #include #include #include +#ifdef _SYSLOG_ #include +#endif #include #include #include @@ -91,7 +93,9 @@ void debug_print_timestamp(void) { void indigo_logger(int level, const char *fmt, ...) { char *format, *log_type; int maxlen; +#ifdef _SYSLOG_ int priority; +#endif va_list ap; maxlen = strlen(fmt) + 100; @@ -139,6 +143,7 @@ void indigo_logger(int level, const char *fmt, ...) { #endif } +#ifdef _SYSLOG_ if (level >= stdout_level) { switch (level) { case LOG_LEVEL_DEBUG_VERBOSE: @@ -162,6 +167,7 @@ void indigo_logger(int level, const char *fmt, ...) { vsyslog(priority, format, ap); va_end(ap); } +#endif } void open_tc_app_log() { From 7566c14a2334aa62d8dd170ac9738cca964ce316 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:21 +0530 Subject: [PATCH 02/20] Fix uninitialized build warnings Signed-off-by: Chaitanya Tata --- utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 0694cf4..221ba7b 100644 --- a/utils.c +++ b/utils.c @@ -1189,7 +1189,7 @@ int add_wireless_interface_info(int band, int bssid, char *name) { int show_wireless_interface_info() { int i; - char *band; + char *band = "Unknown"; indigo_logger(LOG_LEVEL_INFO, "interface_count=%d", interface_count); for (i = 0; i < interface_count; i++) { From da06a8cba7030182f4c115e70888b19619d3741a Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:24 +0530 Subject: [PATCH 03/20] Fix bug in channel comparison This was found as a build warning, a typo in using logical OR condition to compare channels. Signed-off-by: Chaitanya Tata --- utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.c b/utils.c index 221ba7b..691011a 100644 --- a/utils.c +++ b/utils.c @@ -1440,7 +1440,7 @@ int get_6g_center_freq_index(int channel, int width) { int is_ht40plus_chan(int chan) { if (chan == 36 || chan == 44 || chan == 52 || chan == 60 || - chan == 100 || chan == 108 || chan == 116 | chan == 124 || + chan == 100 || chan == 108 || chan == 116 || chan == 124 || chan == 132 || chan == 140 || chan == 149 || chan == 157) return 1; else @@ -1449,7 +1449,7 @@ int is_ht40plus_chan(int chan) { int is_ht40minus_chan(int chan) { if (chan == 40 || chan == 48 || chan == 56 || chan == 64 || - chan == 104 || chan == 112 || chan == 120 | chan == 128 || + chan == 104 || chan == 112 || chan == 120 || chan == 128 || chan == 136 || chan == 144 || chan == 153 || chan == 161) return 1; else From 7b836abcd7c8fc56e1bed3de76efda902c0ed318 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:25 +0530 Subject: [PATCH 04/20] Enable minimal warnings These help point out trivial issues. Signed-off-by: Chaitanya Tata --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 339d8d6..598b3e0 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ ROLE = dut VERSION = "2.1.0.42" OBJS = main.o eloop.o indigo_api.o indigo_packet.o utils.o wpa_ctrl.o -CFLAGS += -g +CFLAGS += -g -Wall -Wextra -Wpedantic -Werror ifeq ($(TYPE),laptop) CC = gcc From 4e6f2dd346f06ee70dab3f022010d38afd95fa22 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:26 +0530 Subject: [PATCH 05/20] Fix signedness warning Signed-off-by: Chaitanya Tata --- hs2_profile.h | 4 ++-- indigo_api.c | 6 +++--- indigo_api_callback.h | 6 +++--- indigo_api_callback_dut.c | 24 +++++++++++++----------- indigo_packet.c | 30 ++++++++++++++++-------------- indigo_packet.h | 22 +++++++++++----------- main.c | 2 +- utils.c | 21 ++++++++++++--------- 8 files changed, 61 insertions(+), 54 deletions(-) diff --git a/hs2_profile.h b/hs2_profile.h index d24d217..d043520 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -180,7 +180,7 @@ struct tlv_to_profile hs2_profile[] = { }; struct tlv_to_profile* find_tlv_hs2_profile(int tlv_id) { - int i; + unsigned int i; for (i = 0; i < ARRAY_SIZE(hs2_profile); i++) { if (tlv_id == hs2_profile[i].tlv_id) { return &hs2_profile[i]; @@ -190,7 +190,7 @@ struct tlv_to_profile* find_tlv_hs2_profile(int tlv_id) { } void attach_hs20_icons(char * buffer) { - int i; + unsigned int i; for (i = 0; i < ARRAY_SIZE(hs20_icon); i++) { strcat(buffer, hs20_icon[i]); } diff --git a/indigo_api.c b/indigo_api.c index e69a830..a3a0085 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -277,7 +277,7 @@ struct indigo_tlv indigo_tlv_list[] = { /* Find the type of the API stucture by the ID from the list */ char* get_api_type_by_id(int id) { - int i = 0; + unsigned int i = 0; for (i = 0; i < sizeof(indigo_api_list)/sizeof(struct indigo_api); i++) { if (id == indigo_api_list[i].type) { return indigo_api_list[i].name; @@ -288,7 +288,7 @@ char* get_api_type_by_id(int id) { /* Find the API stucture by the ID from the list */ struct indigo_api* get_api_by_id(int id) { - int i = 0; + unsigned int i = 0; for (i = 0; i < sizeof(indigo_api_list)/sizeof(struct indigo_api); i++) { if (id == indigo_api_list[i].type) { return &indigo_api_list[i]; @@ -299,7 +299,7 @@ struct indigo_api* get_api_by_id(int id) { /* Find the TLV by the ID from the list */ struct indigo_tlv* get_tlv_by_id(int id) { - int i = 0; + unsigned int i = 0; for (i = 0; i < sizeof(indigo_tlv_list)/sizeof(struct indigo_tlv); i++) { if (id == indigo_tlv_list[i].id) { diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 758513e..52f1e24 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -174,7 +174,7 @@ struct anqp_tlv_to_config_name anqp_maps[] = { }; char* find_tlv_config_name(int tlv_id) { - int i; + unsigned int i; for (i = 0; i < sizeof(maps)/sizeof(struct tlv_to_config_name); i++) { if (tlv_id == maps[i].tlv_id) { return maps[i].config_name; @@ -184,7 +184,7 @@ char* find_tlv_config_name(int tlv_id) { } struct tlv_to_config_name* find_tlv_config(int tlv_id) { - int i; + unsigned int i; for (i = 0; i < sizeof(maps)/sizeof(struct tlv_to_config_name); i++) { if (tlv_id == maps[i].tlv_id) { return &maps[i]; @@ -211,7 +211,7 @@ struct tlv_to_config_name wpas_global_maps[] = { }; struct tlv_to_config_name* find_wpas_global_config_name(int tlv_id) { - int i; + unsigned int i; for (i = 0; i < sizeof(wpas_global_maps)/sizeof(struct tlv_to_config_name); i++) { if (tlv_id == wpas_global_maps[i].tlv_id) { return &wpas_global_maps[i]; diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index b3eda4e..f3cf513 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -301,7 +301,8 @@ 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, enable_hs20 = 0; + int enable_ac = 0, enable_11h = 0, enable_hs20 = 0; + size_t i; int enable_wps = 0, use_mbss = 0; char buffer[S_BUFFER_LEN], cfg_item[2*BUFFER_LEN]; char band[64], value[16]; @@ -1864,7 +1865,7 @@ static void append_wpas_network_default_config(struct packet_wrapper *wrapper) { #endif /* _RESERVED_ */ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wrapper *wrapper) { - int i, j; + size_t i, j; char value[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN], buf[S_BUFFER_LEN]; int ieee80211w_configured = 0; int transition_mode_enabled = 0; @@ -2097,8 +2098,8 @@ 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, i; - size_t resp_len; + int status = TLV_VALUE_STATUS_NOT_OK; + size_t resp_len, i; char *message = NULL; char buffer[BUFFER_LEN]; char response[BUFFER_LEN]; @@ -2210,7 +2211,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, i; + int len, status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_WPA_S_BTM_QUERY_NOT_OK; char buffer[1024]; char response[1024]; @@ -2218,7 +2219,7 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet char anqp_info_id[256]; struct tlv_hdr *tlv = NULL; struct wpa_ctrl *w = NULL; - size_t resp_len; + size_t resp_len, i; char *token = NULL; char *delimit = ";"; char realm[S_BUFFER_LEN]; @@ -2647,13 +2648,13 @@ static int p2p_start_wps_handler(struct packet_wrapper *req, struct packet_wrapp } static int sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - int len, status = TLV_VALUE_STATUS_NOT_OK, i; + int len, status = TLV_VALUE_STATUS_NOT_OK; 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; + size_t resp_len, i; struct tlv_to_config_name* cfg = NULL; char value[TLV_VALUE_SIZE], cfg_item[2*S_BUFFER_LEN]; @@ -2777,8 +2778,8 @@ static int set_sta_hs2_associate_handler(struct packet_wrapper *req, struct pack 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; + int len, status = TLV_VALUE_STATUS_NOT_OK, cred_id, wpa_ret; + size_t resp_len, i; char response[BUFFER_LEN]; char param_value[256]; struct tlv_hdr *tlv = NULL; @@ -3709,7 +3710,8 @@ static int enable_wsc_sta_handler(struct packet_wrapper *req, struct packet_wrap 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; + 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; diff --git a/indigo_packet.c b/indigo_packet.c index 36a2166..cf98d27 100644 --- a/indigo_packet.c +++ b/indigo_packet.c @@ -26,8 +26,9 @@ int capture_packet = 0, capture_count = 0; /* debug. Write the received packets int debug_packet = 0; /* used by the packet hexstring print */ /* Parse the QuickTrack message from the packet to the wrapper */ -int parse_packet(struct packet_wrapper *req, char *packet, int packet_len) { - int i = 0, parser = 0, ret = 0; +int parse_packet(struct packet_wrapper *req, char *packet, size_t packet_len) { + int parser = 0, ret = 0; + size_t i = 0; struct indigo_api *api = NULL; struct indigo_tlv *tlv = NULL; @@ -143,7 +144,7 @@ int free_packet_wrapper(struct packet_wrapper *wrapper) { } /* Parse the message header */ -int parse_message_hdr(struct message_hdr *hdr, char *message, int message_len) { +int parse_message_hdr(struct message_hdr *hdr, char *message, size_t message_len) { if (message_len < sizeof(struct message_hdr)) { return -1; } @@ -158,7 +159,7 @@ int parse_message_hdr(struct message_hdr *hdr, char *message, int message_len) { } /* Convert the packet message header from the structure */ -int gen_message_hdr(char *message, int message_len, struct message_hdr *hdr) { +int gen_message_hdr(char *message, size_t message_len, struct message_hdr *hdr) { int len = 0; if (message_len < sizeof(struct message_hdr)) { @@ -186,8 +187,8 @@ void print_message_hdr(struct message_hdr *hdr) { } /* Print the hexstring of the specific range */ -int print_hex(char *message, int message_len) { - int i; +int print_hex(char *message, size_t message_len) { + size_t i; for(i = 0; i < message_len; i++) { printf("0x%02x ", (unsigned char)message[i]); } @@ -196,7 +197,7 @@ int print_hex(char *message, int message_len) { } /* Add the TLV to the wrapper */ -int add_wrapper_tlv(struct packet_wrapper *wrapper, int id, int len, char *value) { +int add_wrapper_tlv(struct packet_wrapper *wrapper, int id, size_t len, char *value) { if (add_tlv(wrapper->tlv[wrapper->tlv_num], id, len, value) == 0) { wrapper->tlv_num++; return 0; @@ -205,7 +206,7 @@ int add_wrapper_tlv(struct packet_wrapper *wrapper, int id, int len, char *value } /* Fill the TLV with the ID, length and value */ -int add_tlv(struct tlv_hdr *tlv, int id, int len, char *value) { +int add_tlv(struct tlv_hdr *tlv, int id, size_t len, char *value) { if (!tlv) return 1; tlv->id = id; @@ -216,7 +217,7 @@ int add_tlv(struct tlv_hdr *tlv, int id, int len, char *value) { } /* Parse the TLV from the packet to the structure */ -int parse_tlv(struct tlv_hdr *tlv, char *packet, int packet_len) { +int parse_tlv(struct tlv_hdr *tlv, char *packet, size_t packet_len) { if (packet_len < 3) { return -1; } @@ -230,10 +231,10 @@ int parse_tlv(struct tlv_hdr *tlv, char *packet, int packet_len) { } /* Convert the TLV structure to the packet */ -int gen_tlv(char *packet, int packet_size, struct tlv_hdr *t) { - int len = 0; +int gen_tlv(char *packet, size_t packet_size, struct tlv_hdr *t) { + size_t len = 0; - if (packet_size < t->len + 3) { + if (packet_size < (size_t)t->len + 3) { return -1; } @@ -269,8 +270,9 @@ void print_tlv(struct tlv_hdr *t) { } /* Convert the wrapper to the packet includes the message header and all TLVs. Used by the ACK and resposne */ -int assemble_packet(char *packet, int packet_size, struct packet_wrapper *wrapper) { - int i = 0, ret = 0, packet_len = 0; +int assemble_packet(char *packet, size_t packet_size, struct packet_wrapper *wrapper) { + int ret = 0; + size_t packet_len = 0, i = 0; ret = gen_message_hdr(packet, packet_size, &wrapper->hdr); packet_len += ret; diff --git a/indigo_packet.h b/indigo_packet.h index 3846370..0af4407 100644 --- a/indigo_packet.h +++ b/indigo_packet.h @@ -32,34 +32,34 @@ struct __attribute__((__packed__)) message_hdr { struct __attribute__((__packed__)) tlv_hdr { unsigned short id; unsigned char len; - unsigned char *value; + char *value; }; struct packet_wrapper { struct message_hdr hdr; struct tlv_hdr *tlv[TLV_NUM]; - int tlv_num; + size_t tlv_num; }; /* API */ -int assemble_packet(char *packet, int packet_size, struct packet_wrapper *wrapper); -int parse_packet(struct packet_wrapper *req, char *packet, int packet_len); +int assemble_packet(char *packet, size_t packet_size, struct packet_wrapper *wrapper); +int parse_packet(struct packet_wrapper *req, char *packet, size_t packet_len); int free_packet_wrapper(struct packet_wrapper *wrapper); /* Debug */ -int print_hex(char *message, int message_len); +int print_hex(char *message, size_t message_len); /* Message header */ -int parse_message_hdr(struct message_hdr *hdr, char *message, int message_len); -int add_message_hdr(char *message, int message_len, struct message_hdr *hdr); +int parse_message_hdr(struct message_hdr *hdr, char *message, size_t message_len); +int add_message_hdr(char *message, size_t message_len, struct message_hdr *hdr); void print_message_hdr(struct message_hdr *hdr); /* TLV header */ -int parse_tlv(struct tlv_hdr *tlv, char *message, int message_len); -int gen_tlv(char *message, int message_len, struct tlv_hdr *t); +int parse_tlv(struct tlv_hdr *tlv, char *message, size_t message_len); +int gen_tlv(char *message, size_t message_len, struct tlv_hdr *t); void print_tlv(struct tlv_hdr *t); struct tlv_hdr *find_wrapper_tlv_by_id(struct packet_wrapper *wrapper, int id); -int add_wrapper_tlv(struct packet_wrapper *wrapper, int id, int len, char *value); +int add_wrapper_tlv(struct packet_wrapper *wrapper, int id, size_t len, char *value); -int add_tlv(struct tlv_hdr *tlv, int id, int len, char *value); +int add_tlv(struct tlv_hdr *tlv, int id, size_t len, char *value); #endif /* _INDIGO_PACKET_ */ diff --git a/main.c b/main.c index 4ef5ff1..0d1e1d8 100755 --- a/main.c +++ b/main.c @@ -86,7 +86,7 @@ static void control_receive_message(int sock, void *eloop_ctx, void *sock_ctx) { int ret; // return code int fromlen, len; // structure size and received length struct sockaddr_storage from; // source address of the message - unsigned char buffer[BUFFER_LEN]; // buffer to receive the message + char buffer[BUFFER_LEN]; // buffer to receive the message struct packet_wrapper req, resp; // packet wrapper for the received message and response struct indigo_api *api = NULL; // used for API search, validation and handler call diff --git a/utils.c b/utils.c index 691011a..2ee27de 100644 --- a/utils.c +++ b/utils.c @@ -297,10 +297,10 @@ int loopback_socket = 0; static void loopback_server_receive_message(int sock, void *eloop_ctx, void *sock_ctx) { struct sockaddr_storage from; unsigned char buffer[BUFFER_LEN]; - int fromlen, len; + ssize_t fromlen, len; fromlen = sizeof(from); - len = recvfrom(sock, buffer, BUFFER_LEN, 0, (struct sockaddr *) &from, &fromlen); + len = recvfrom(sock, buffer, BUFFER_LEN, 0, (struct sockaddr *) &from, (socklen_t *)&fromlen); if (len < 0) { indigo_logger(LOG_LEVEL_ERROR, "Loopback server recvfrom[server] error"); return ; @@ -515,7 +515,8 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet int s = 0, i = 0; struct sockaddr_in addr; int pkt_sent = 0, pkt_rcv = 0; - char message[1600], server_reply[1600], ifname[32]; + char message[1600], server_reply[1600]; + char ifname[32]; ssize_t recv_len = 0, send_len = 0; struct timeval timeout; @@ -569,7 +570,7 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet loopback.rate = rate; loopback.pkt_sent = loopback.pkt_rcv = 0; memset(loopback.message, 0, sizeof(loopback.message)); - for (i = 0; (i < packet_size) && (i < sizeof(loopback.message)); i++) + for (i = 0; (i < packet_size) && (i < (int)sizeof(loopback.message)); i++) loopback.message[i] = 0x0A; eloop_register_timeout(0, 0, send_continuous_loopback_packet, &loopback, NULL); indigo_logger(LOG_LEVEL_INFO, "Send continuous loopback data to ip %s port %u", @@ -578,7 +579,7 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet } memset(message, 0, sizeof(message)); - for (i = 0; (i < packet_size) && (i < sizeof(message)); i++) + for (i = 0; (i < packet_size) && (i < (int)sizeof(message)); i++) message[i] = 0x0A; for (pkt_sent = 1; pkt_sent <= packet_count; pkt_sent++) { @@ -612,8 +613,10 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet int send_icmp_data(char *target_ip, int packet_count, int packet_size, double rate) { - int n, sock, i; - char buf[1600], server_reply[1600], ifname[32]; + int n, sock; + size_t i; + unsigned char buf[1600], server_reply[1600]; + char ifname[32]; struct sockaddr_in addr; struct in_addr insaddr; struct icmphdr *icmphdr, *recv_icmphdr; @@ -660,7 +663,7 @@ int send_icmp_data(char *target_ip, int packet_count, int packet_size, double ra loopback.rate = rate; loopback.pkt_size = packet_size; snprintf(loopback.target_ip, sizeof(loopback.target_ip), "%s", target_ip); - for (i = sizeof(struct icmphdr); (i < packet_size) && (i < sizeof(loopback.message)); i++) + for (i = sizeof(struct icmphdr); (i < (size_t)packet_size) && (i < sizeof(loopback.message)); i++) loopback.message[i] = 0x0A; eloop_register_timeout(0, 0, send_continuous_loopback_packet, &loopback, NULL); indigo_logger(LOG_LEVEL_INFO, "Send continuous loopback data to ip %s", loopback.target_ip); @@ -669,7 +672,7 @@ int send_icmp_data(char *target_ip, int packet_count, int packet_size, double ra icmphdr = (struct icmphdr *)&buf; memset(&buf, 0, sizeof(buf)); - for (i = sizeof(struct icmphdr); (i < packet_size) && (i < sizeof(buf)); i++) + for (i = sizeof(struct icmphdr); (i < (size_t)packet_size) && (i < sizeof(buf)); i++) buf[i] = 0x0A; for (pkt_sent = 1; pkt_sent <= packet_count; pkt_sent++) { From a0f18e55d8d55585d36db4e85cfd960600879a59 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:29 +0530 Subject: [PATCH 06/20] Fix unused variables warning Signed-off-by: Chaitanya Tata --- eloop.c | 1 + indigo_api_callback_dut.c | 37 ++++++++++++++----------------------- main.c | 5 +++++ utils.c | 23 +++++++++++++++++++++++ vendor_specific_dut.c | 18 +++++++++++++++--- wpa_ctrl.c | 4 ++++ 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/eloop.c b/eloop.c index 8c23d3c..2416b91 100644 --- a/eloop.c +++ b/eloop.c @@ -207,6 +207,7 @@ int eloop_cancel_timeout(void (*handler)(void *eloop_ctx, void *sock_ctx), #ifndef CONFIG_NATIVE_WINDOWS static void eloop_handle_alarm(int sig) { + (void) sig; fprintf(stderr, "eloop: could not process SIGINT or SIGTERM in two " "seconds. Looks like there\n" "is a bug that ends up in a busy loop that " diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index f3cf513..e74de0c 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -111,7 +111,7 @@ static int get_control_app_handler(struct packet_wrapper *req, struct packet_wra } static int reset_device_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - int len, status = TLV_VALUE_STATUS_NOT_OK; + int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_RESET_NOT_OK; char buffer[TLV_VALUE_SIZE]; char role[TLV_VALUE_SIZE], log_level[TLV_VALUE_SIZE], band[TLV_VALUE_SIZE]; @@ -315,6 +315,8 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ int hs20_icons_attached = 0; int is_multiple_bssid = 0; + (void) output_size; + #if HOSTAPD_SUPPORT_MBSSID 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); @@ -875,7 +877,6 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r char *message = TLV_VALUE_HOSTAPD_START_OK; char buffer[S_BUFFER_LEN]; int len; - int status = TLV_VALUE_STATUS_OK; int swap_hostapd = 0; #ifdef _WTS_OPENWRT_ @@ -1096,7 +1097,6 @@ static int configure_ap_wsc_handler(struct packet_wrapper *req, struct packet_wr /* deprecated */ static int create_bridge_network_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int err = 0; - char cmd[S_BUFFER_LEN]; char static_ip[S_BUFFER_LEN]; struct tlv_hdr *tlv; char *message = TLV_VALUE_CREATE_BRIDGE_OK; @@ -1355,7 +1355,6 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe } static int start_loopback_server(struct packet_wrapper *req, struct packet_wrapper *resp) { - struct tlv_hdr *tlv; char local_ip[256]; int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_LOOPBACK_SVR_START_NOT_OK; @@ -1767,7 +1766,6 @@ static int get_ip_addr_handler(struct packet_wrapper *req, struct packet_wrapper message = TLV_VALUE_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); @@ -1865,15 +1863,15 @@ static void append_wpas_network_default_config(struct packet_wrapper *wrapper) { #endif /* _RESERVED_ */ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wrapper *wrapper) { - size_t i, j; + size_t i; char value[S_BUFFER_LEN], cfg_item[2*S_BUFFER_LEN], buf[S_BUFFER_LEN]; int ieee80211w_configured = 0; 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; - int len = 0, conf_methods = 0, count = 0; + + (void) buffer_size; sprintf(buffer, "ctrl_interface=%s\nap_scan=1\npmf=1\n", WPAS_CTRL_PATH_DEFAULT); @@ -1961,14 +1959,12 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra strcat(buffer, "}\n"); -done: return strlen(buffer); } static int configure_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len; char buffer[L_BUFFER_LEN]; - struct tlv_hdr *tlv; char *message = "DUT configured as STA : Configuration file created"; memset(buffer, 0, sizeof(buffer)); @@ -2014,7 +2010,6 @@ static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapp 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); @@ -2025,7 +2020,7 @@ static int send_sta_disconnect_handler(struct packet_wrapper *req, struct packet struct wpa_ctrl *w = NULL; char *message = TLV_VALUE_WPA_S_DISCONNECT_NOT_OK; char buffer[256], response[1024]; - int status, i; + int status; size_t resp_len; /* Open WPA supplicant UDS socket */ @@ -2063,7 +2058,7 @@ static int send_sta_reconnect_handler(struct packet_wrapper *req, struct packet_ struct wpa_ctrl *w = NULL; char *message = TLV_VALUE_WPA_S_RECONNECT_NOT_OK; char buffer[256], response[1024]; - int len, status, i; + int status; size_t resp_len; /* Open WPA supplicant UDS socket */ @@ -2369,7 +2364,6 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe 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); @@ -2905,7 +2899,7 @@ static int run_hs20_osu_client(const char *params) 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; + int len; char buffer[L_BUFFER_LEN], ppsmo_file[S_BUFFER_LEN]; struct tlv_hdr *tlv; char *fqdn = NULL; @@ -2999,7 +2993,7 @@ static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct pack 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]; + char pin_code[64]; char method[16], mac[32], type[16]; size_t resp_len; int status = TLV_VALUE_STATUS_NOT_OK; @@ -3151,7 +3145,6 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper 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]; @@ -3267,7 +3260,6 @@ static int get_p2p_intent_value_handler(struct packet_wrapper *req, struct packe 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); @@ -3280,7 +3272,7 @@ static int get_p2p_intent_value_handler(struct packet_wrapper *req, struct packe 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]; + char pin_code[64]; size_t resp_len; int status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_AP_START_WPS_NOT_OK; @@ -3296,7 +3288,7 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe * identify the invalid PIN code and DONOT start wps. * */ #define WPS_PIN_VALIDATION_FILE "/tmp/pin_checksum.sh" - int len = 0, is_valid = 0; + int len = 0; char pipebuf[S_BUFFER_LEN]; char *parameter[] = {"sh", WPS_PIN_VALIDATION_FILE, pin_code, NULL}; memset(pipebuf, 0, sizeof(pipebuf)); @@ -3424,7 +3416,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe 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; + int i, len, count = 0, role = 0; struct tlv_hdr *tlv = NULL; struct _cfg_cred *p_cfg = NULL; @@ -3709,7 +3701,7 @@ static int set_p2p_ext_listen_handler(struct packet_wrapper *req, struct packet_ 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]; + 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; @@ -3781,7 +3773,6 @@ static int enable_wsc_sta_handler(struct packet_wrapper *req, struct packet_wrap 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); diff --git a/main.c b/main.c index 0d1e1d8..bdb8fee 100755 --- a/main.c +++ b/main.c @@ -90,6 +90,9 @@ static void control_receive_message(int sock, void *eloop_ctx, void *sock_ctx) { struct packet_wrapper req, resp; // packet wrapper for the received message and response struct indigo_api *api = NULL; // used for API search, validation and handler call + (void) eloop_ctx; + (void) sock_ctx; + /* Receive request */ fromlen = sizeof(from); len = recvfrom(sock, buffer, BUFFER_LEN, 0, (struct sockaddr *) &from, (socklen_t*)&fromlen); @@ -265,6 +268,8 @@ static int parse_parameters(int argc, char *argv[]) { static void handle_term(int sig, void *eloop_ctx, void *signal_ctx) { indigo_logger(LOG_LEVEL_INFO, "Signal %d received - terminating\n", sig); + (void) eloop_ctx; + (void) signal_ctx; eloop_terminate(); vendor_deinit(); } diff --git a/utils.c b/utils.c index 2ee27de..b7f07b6 100644 --- a/utils.c +++ b/utils.c @@ -38,6 +38,7 @@ #include #include #include +#include typedef uint8_t u_int8_t; typedef uint16_t u_int16_t; typedef uint32_t u_int32_t; @@ -299,6 +300,9 @@ static void loopback_server_receive_message(int sock, void *eloop_ctx, void *soc unsigned char buffer[BUFFER_LEN]; ssize_t fromlen, len; + (void)eloop_ctx; + (void)sock_ctx; + fromlen = sizeof(from); len = recvfrom(sock, buffer, BUFFER_LEN, 0, (struct sockaddr *) &from, (socklen_t *)&fromlen); if (len < 0) { @@ -315,6 +319,9 @@ static void loopback_server_receive_message(int sock, void *eloop_ctx, void *soc static void loopback_server_timeout(void *eloop_ctx, void *timeout_ctx) { int s = (intptr_t)eloop_ctx; + + (void)timeout_ctx; + eloop_unregister_read_sock(s); close(s); loopback_socket = 0; @@ -489,6 +496,9 @@ void send_one_loopback_udp_packet(struct loopback_info *info) { void send_continuous_loopback_packet(void *eloop_ctx, void *sock_ctx) { struct loopback_info *info = (struct loopback_info *)eloop_ctx; + (void)eloop_ctx; + (void)sock_ctx; + if (info->pkt_type == DATA_TYPE_ICMP) { send_one_loopback_icmp_packet(info); } else { @@ -749,6 +759,8 @@ int find_interface_ip(char *ipaddr, int ipaddr_len, char *name) { struct sockaddr_in *sa; char *addr = NULL; + (void) ipaddr_len; + getifaddrs(&ifap); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET && strcmp(ifa->ifa_name, name) == 0) { @@ -768,6 +780,8 @@ int get_mac_address(char *buffer, int size, char *interface) { struct ifreq s; int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + (void) size; + if (fd <= 0) { goto done; } @@ -1183,6 +1197,9 @@ char* get_wpas_debug_arguments() { } int add_wireless_interface_info(int band, int bssid, char *name) { + + (void) bssid; + interfaces[interface_count].band = band; interfaces[interface_count].bssid = -1; interfaces[interface_count].identifier = UNUSED_IDENTIFIER; @@ -1722,10 +1739,12 @@ int http_file_post(char *host, int port, char *path, char *file_name) { body = http_body_multipart(boundary, "wpasLogFile", file_name); else { indigo_logger(LOG_LEVEL_ERROR, "Tool doesn't support %s ?", path); + retval = -ENOTSUP; goto done; } /* Return if body is NULL */ if (body == NULL) { + retval = -EINVAL; goto done; } @@ -1734,11 +1753,13 @@ int http_file_post(char *host, int port, char *path, char *file_name) { socketfd = http_socket(host, port); if (send(socketfd, header, strlen(header), 0) == -1){ indigo_logger(LOG_LEVEL_ERROR, "Failed to open HTTP socket"); + retval = -EIO; goto done; } if (send(socketfd, body, strlen(body), 0) == -1){ indigo_logger(LOG_LEVEL_ERROR, "Failed to upload file"); + retval = -EIO; goto done; } @@ -1758,6 +1779,8 @@ int http_file_post(char *host, int port, char *path, char *file_name) { if (socketfd) { close(socketfd); } + + return retval; } int file_exists(const char *fname) diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index f859063..45df64b 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -237,6 +237,11 @@ char buffer[S_BUFFER_LEN], wifi_name[16]; } system("uci commit"); +#else + (void) band; + (void) country; + (void) channel; + (void) chwidth; #endif } @@ -245,11 +250,11 @@ char buffer[S_BUFFER_LEN], wifi_name[16]; * Called by start_ap_handler() after invoking hostapd */ void start_ap_set_wlan_params(void *if_info) { +#ifdef _WTS_OPENWRT_ char buffer[S_BUFFER_LEN]; struct interface_info *wlan = (struct interface_info *) if_info; memset(buffer, 0, sizeof(buffer)); -#ifdef _WTS_OPENWRT_ /* Workaround: openwrt has IOT issue with intel AX210 AX mode */ sprintf(buffer, "cfg80211tool %s he_ul_ofdma 0", wlan->ifname); system(buffer); @@ -258,8 +263,11 @@ void start_ap_set_wlan_params(void *if_info) { system(buffer); sprintf(buffer, "cfg80211tool %s twt_responder 0", wlan->ifname); system(buffer); -#endif + printf("set_wlan_params: %s\n", buffer); +#else + (void) if_info; +#endif } /* Return addr of P2P-device if there is no GO or client interface */ @@ -400,6 +408,8 @@ void save_wsc_setting(wps_setting *s, char *entry, int len) { char *p = NULL; + (void) len; + p = strchr(entry, '\n'); if (p) p++; @@ -415,6 +425,8 @@ wps_setting* __get_wps_setting(int len, char *buffer, enum wps_device_role role) wps_setting *s = NULL; int i = 0; + (void) len; + if (role == WPS_AP) { memset(customized_wps_settings_ap, 0, sizeof(customized_wps_settings_ap)); p_wps_setting = customized_wps_settings_ap; @@ -442,7 +454,7 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) * */ #define WSC_SETTINGS_FILE_AP "/tmp/wsc_settings_APUT" #define WSC_SETTINGS_FILE_STA "/tmp/wsc_settings_STAUT" - int len = 0, is_valid = 0; + int len = 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}; diff --git a/wpa_ctrl.c b/wpa_ctrl.c index 77fa602..01ae888 100644 --- a/wpa_ctrl.c +++ b/wpa_ctrl.c @@ -165,7 +165,9 @@ int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, int res; fd_set rfds; const char *_cmd; +#ifdef CONFIG_CTRL_IFACE_UDP char *cmd_buf = NULL; +#endif /* CONFIG_CTRL_IFACE_UDP */ size_t _cmd_len; #ifdef CONFIG_CTRL_IFACE_UDP @@ -281,6 +283,8 @@ int wpa_ctrl_pending(struct wpa_ctrl *ctrl) FD_ZERO(&rfds); FD_SET(ctrl->s, &rfds); res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv); + if (res < 0) + return -1; return FD_ISSET(ctrl->s, &rfds); } From dc72aa4ff30bd906604c8b908dfd618c5de35aa7 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:29 +0530 Subject: [PATCH 07/20] Fix unused function warning Signed-off-by: Chaitanya Tata --- indigo_api_callback.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 52f1e24..0b9b480 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -234,8 +234,6 @@ struct tlv_to_config_name* find_generic_tlv_config(int tlv_id, struct tlv_to_con static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int start_loopback_server(struct packet_wrapper *req, struct packet_wrapper *resp); static int stop_loop_back_server_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int send_loopback_data_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int stop_loopback_data_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int create_bridge_network_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrapper *resp); @@ -253,14 +251,12 @@ static int send_ap_disconnect_handler(struct packet_wrapper *req, struct packet_ static int set_ap_parameter_handler(struct packet_wrapper *req, struct packet_wrapper *resp); 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); 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); static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); -static int start_up_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_disconnect_handler(struct packet_wrapper *req, struct packet_wrapper *resp); 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); @@ -270,11 +266,7 @@ static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_w 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); -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); From b9b7ddad16df4f9662837f34edeba4ebbb7589d7 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:30 +0530 Subject: [PATCH 08/20] Fix return value for function Signed-off-by: Chaitanya Tata --- utils.c | 2 ++ vendor_specific_dut.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/utils.c b/utils.c index b7f07b6..8f5f439 100644 --- a/utils.c +++ b/utils.c @@ -1456,6 +1456,8 @@ int get_6g_center_freq_index(int channel, int width) { if (channel >= i && channel < i + chwidth/5) return i + (chwidth - 20)/10; } + + return -1; } int is_ht40plus_chan(int chan) { diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 45df64b..f1701ca 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -493,4 +493,6 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) return NULL; } } + + return NULL; } From e4eb248e49e3ac56b88fe11fd89f69feef18dd3f Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:33 +0530 Subject: [PATCH 09/20] Fix build warning for print arg Signed-off-by: Chaitanya Tata --- utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 8f5f439..aef011c 100644 --- a/utils.c +++ b/utils.c @@ -1073,7 +1073,7 @@ char* get_hapd_ctrl_path_by_id(struct interface_info* wlan) { else { sprintf(hapd_full_ctrl_path, "%s/%s", hapd_ctrl_path, get_default_wireless_interface_info()); } - printf("hapd_full_ctrl_path: %s, wlan %p\n", hapd_full_ctrl_path, wlan); + printf("hapd_full_ctrl_path: %s, wlan %p\n", hapd_full_ctrl_path, (void *)wlan); return hapd_full_ctrl_path; } From ab199e8f5fe781702558c70f72aa081d11d90454 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:34 +0530 Subject: [PATCH 10/20] Fix pedantic build warning Signed-off-by: Chaitanya Tata --- utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.c b/utils.c index aef011c..3615c13 100644 --- a/utils.c +++ b/utils.c @@ -57,7 +57,7 @@ int configured_interface_count = 0; struct interface_info interfaces[16]; int band_mbssid_cnt[16]; struct interface_info* default_interface; -static struct loopback_info loopback = {}; +static struct loopback_info loopback; /* bridge used for wireless interfaces */ char wlans_bridge[32]; From 0b4e9e4e68f411d11d9e68dfad715216ccd803eb Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:35 +0530 Subject: [PATCH 11/20] Fix overlapping memory build warning Signed-off-by: Chaitanya Tata --- utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 3615c13..2804208 100644 --- a/utils.c +++ b/utils.c @@ -981,6 +981,9 @@ struct interface_info* assign_wireless_interface_info(struct bss_identifier_info int i; for (i = 0; i < interface_count; i++) { + char ifname[16]; + + memcpy(ifname, interfaces[i].ifname, sizeof(ifname)); if ((interfaces[i].band == bss->band) && (interfaces[i].identifier == UNUSED_IDENTIFIER)) { configured_interface_count++; @@ -991,7 +994,7 @@ struct interface_info* assign_wireless_interface_info(struct bss_identifier_info 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); + "%s/hostapd_%s.conf", HAPD_CONF_FILE_DEFAULT_PATH, ifname); return &interfaces[i]; } } From 782bda367f85cea9b572866144d02a29a0758353 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:36 +0530 Subject: [PATCH 12/20] Fix set but ununsed build warning Signed-off-by: Chaitanya Tata --- indigo_api_callback_dut.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index e74de0c..f0b9470 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -301,7 +301,10 @@ 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 enable_ac = 0, enable_11h = 0, enable_hs20 = 0; + int enable_ac = 0,enable_hs20 = 0; +#if defined(_OPENWRT_) && !defined(_WTS_OPENWRT_) + int enable_11h = 0; +#endif size_t i; int enable_wps = 0, use_mbss = 0; char buffer[S_BUFFER_LEN], cfg_item[2*BUFFER_LEN]; @@ -553,7 +556,9 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ #ifdef _WTS_OPENWRT_ continue; #endif +#if defined(_OPENWRT_) && !defined(_WTS_OPENWRT_) enable_11h = 1; +#endif } #ifdef _WTS_OPENWRT_ @@ -1984,7 +1989,7 @@ static int configure_sta_handler(struct packet_wrapper *req, struct packet_wrapp static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { char *message = TLV_VALUE_WPA_S_START_UP_NOT_OK; char buffer[256]; - int len, status = TLV_VALUE_STATUS_NOT_OK; + int status = TLV_VALUE_STATUS_NOT_OK; #ifdef _OPENWRT_ #else @@ -2004,7 +2009,7 @@ static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapp get_wpas_conf_file(), get_wpas_debug_arguments(), get_wireless_interface()); - len = system(buffer); + system(buffer); sleep(2); status = TLV_VALUE_STATUS_OK; From 8d6dd547e2e478b600a3c6c972f84876cd316b75 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:37 +0530 Subject: [PATCH 13/20] Fix eloop namespace eloop is used by both hostap and QT-APP, as C doesn't have namespaces, prefix all QT APIs with qt_. This is needed for those embedded build systems that compile both hostap + QT. Signed-off-by: Chaitanya Tata --- eloop.c | 22 ++++++++++---------- eloop.h | 55 +++++++++++++++++++++++++------------------------- main.c | 22 ++++++++++---------- utils.c | 62 ++++++++++++++++++++++++++++----------------------------- 4 files changed, 80 insertions(+), 81 deletions(-) diff --git a/eloop.c b/eloop.c index 2416b91..5bf0054 100644 --- a/eloop.c +++ b/eloop.c @@ -70,14 +70,14 @@ struct eloop_data { static struct eloop_data eloop; -void eloop_init(void *user_data) +void qt_eloop_init(void *user_data) { memset(&eloop, 0, sizeof(eloop)); eloop.user_data = user_data; } -int eloop_register_read_sock(int sock, +int qt_eloop_register_read_sock(int sock, void (*handler)(int sock, void *eloop_ctx, void *sock_ctx), void *eloop_data, void *user_data) @@ -103,7 +103,7 @@ int eloop_register_read_sock(int sock, } -void eloop_unregister_read_sock(int sock) +void qt_eloop_unregister_read_sock(int sock) { int i; @@ -125,7 +125,7 @@ void eloop_unregister_read_sock(int sock) } -int eloop_register_timeout(unsigned int secs, unsigned int usecs, +int qt_eloop_register_timeout(unsigned int secs, unsigned int usecs, void (*handler)(void *eloop_ctx, void *timeout_ctx), void *eloop_data, void *user_data) { @@ -172,7 +172,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs, } -int eloop_cancel_timeout(void (*handler)(void *eloop_ctx, void *sock_ctx), +int qt_eloop_cancel_timeout(void (*handler)(void *eloop_ctx, void *sock_ctx), void *eloop_data, void *user_data) { struct eloop_timeout *timeout, *prev, *next; @@ -269,7 +269,7 @@ static void eloop_process_pending_signals(void) } -int eloop_register_signal(int sig, +int qt_eloop_register_signal(int sig, void (*handler)(int sig, void *eloop_ctx, void *signal_ctx), void *user_data) @@ -295,7 +295,7 @@ int eloop_register_signal(int sig, } -void eloop_run(void) +void qt_eloop_run(void) { fd_set *rfds; int i, res; @@ -303,7 +303,7 @@ void eloop_run(void) rfds = malloc(sizeof(*rfds)); if (rfds == NULL) { - printf("eloop_run - malloc failed\n"); + printf("qt_eloop_run - malloc failed\n"); return; } @@ -365,13 +365,13 @@ void eloop_run(void) } -void eloop_terminate(void) +void qt_eloop_terminate(void) { eloop.terminate = 1; } -void eloop_destroy(void) +void qt_eloop_destroy(void) { struct eloop_timeout *timeout, *prev; @@ -386,7 +386,7 @@ void eloop_destroy(void) } -int eloop_terminated(void) +int qt_eloop_terminated(void) { return eloop.terminate; } diff --git a/eloop.h b/eloop.h index c57e682..c83e888 100644 --- a/eloop.h +++ b/eloop.h @@ -23,21 +23,21 @@ #ifndef ELOOP_H #define ELOOP_H -/* Magic number for eloop_cancel_timeout() */ +/* Magic number for qt_eloop_cancel_timeout() */ #define ELOOP_ALL_CTX (void *) -1 /** - * eloop_init() - Initialize global event loop data + * qt_eloop_init() - Initialize global event loop data * @user_data: Pointer to global data passed as eloop_ctx to signal handlers * * This function must be called before any other eloop_* function. user_data * can be used to configure a global (to the process) pointer that will be * passed as eloop_ctx parameter to signal handlers. */ -void eloop_init(void *user_data); +void qt_eloop_init(void *user_data); /** - * eloop_register_read_sock - Register handler for read events + * qt_eloop_register_read_sock - Register handler for read events * @sock: File descriptor number for the socket * @handler: Callback function to be called when data is available for reading * @eloop_data: Callback context data (eloop_ctx) @@ -48,22 +48,22 @@ void eloop_init(void *user_data); * function will be called whenever data is available for reading from the * socket. */ -int eloop_register_read_sock(int sock, +int qt_eloop_register_read_sock(int sock, void (*handler)(int sock, void *eloop_ctx, void *sock_ctx), void *eloop_data, void *user_data); /** - * eloop_unregister_read_sock - Unregister handler for read events + * qt_eloop_unregister_read_sock - Unregister handler for read events * @sock: File descriptor number for the socket * * Unregister a read socket notifier that was previously registered with - * eloop_register_read_sock(). + * qt_eloop_register_read_sock(). */ -void eloop_unregister_read_sock(int sock); +void qt_eloop_unregister_read_sock(int sock); /** - * eloop_register_timeout - Register timeout + * qt_eloop_register_timeout - Register timeout * @secs: Number of seconds to the timeout * @usecs: Number of microseconds to the timeout * @handler: Callback function to be called when timeout occurs @@ -74,26 +74,26 @@ void eloop_unregister_read_sock(int sock); * Register a timeout that will cause the handler function to be called after * given time. */ -int eloop_register_timeout(unsigned int secs, unsigned int usecs, +int qt_eloop_register_timeout(unsigned int secs, unsigned int usecs, void (*handler)(void *eloop_ctx, void *timeout_ctx), void *eloop_data, void *user_data); /** - * eloop_cancel_timeout - Cancel timeouts + * qt_eloop_cancel_timeout - Cancel timeouts * @handler: Matching callback function * @eloop_data: Matching eloop_data or %ELOOP_ALL_CTX to match all * @user_data: Matching user_data or %ELOOP_ALL_CTX to match all * Returns: Number of cancelled timeouts * * Cancel matching timeouts registered with - * eloop_register_timeout(). ELOOP_ALL_CTX can be used as a wildcard for + * qt_eloop_register_timeout(). ELOOP_ALL_CTX can be used as a wildcard for * cancelling all timeouts regardless of eloop_data/user_data. */ -int eloop_cancel_timeout(void (*handler)(void *eloop_ctx, void *sock_ctx), +int qt_eloop_cancel_timeout(void (*handler)(void *eloop_ctx, void *sock_ctx), void *eloop_data, void *user_data); /** - * eloop_register_signal - Register handler for signals + * qt_eloop_register_signal - Register handler for signals * @sig: Signal number (e.g., SIGHUP) * @handler: Callback function to be called when the signal is received * @user_data: Callback context data (signal_ctx) @@ -106,47 +106,46 @@ int eloop_cancel_timeout(void (*handler)(void *eloop_ctx, void *sock_ctx), * * Signals are 'global' events and there is no local eloop_data pointer like * with other handlers. The global user_data pointer registered with - * eloop_init() will be used as eloop_ctx for signal handlers. + * qt_eloop_init() will be used as eloop_ctx for signal handlers. */ -int eloop_register_signal(int sig, +int qt_eloop_register_signal(int sig, void (*handler)(int sig, void *eloop_ctx, void *signal_ctx), void *user_data); - /** - * eloop_run - Start the event loop + * qt_eloop_run - Start the event loop * * Start the event loop and continue running as long as there are any * registered event handlers. This function is run after event loop has been * initialized with event_init() and one or more events have been registered. */ -void eloop_run(void); +void qt_eloop_run(void); /** - * eloop_terminate - Terminate event loop + * qt_eloop_terminate - Terminate event loop * * Terminate event loop even if there are registered events. This can be used * to request the program to be terminated cleanly. */ -void eloop_terminate(void); +void qt_eloop_terminate(void); /** - * eloop_destroy - Free any resources allocated for the event loop + * qt_eloop_destroy - Free any resources allocated for the event loop * * After calling eloop_destoy(), other eloop_* functions must not be called - * before re-running eloop_init(). + * before re-running qt_eloop_init(). */ -void eloop_destroy(void); +void qt_eloop_destroy(void); /** - * eloop_terminated - Check whether event loop has been terminated + * qt_eloop_terminated - Check whether event loop has been terminated * Returns: 1 = event loop terminate, 0 = event loop still running * - * This function can be used to check whether eloop_terminate() has been called + * This function can be used to check whether qt_eloop_terminate() has been called * to request termination of the event loop. This is normally used to abort - * operations that may still be queued to be run when eloop_terminate() was + * operations that may still be queued to be run when qt_eloop_terminate() was * called. */ -int eloop_terminated(void); +int qt_eloop_terminated(void); #endif /* ELOOP_H */ diff --git a/main.c b/main.c index bdb8fee..d879ba5 100755 --- a/main.c +++ b/main.c @@ -72,7 +72,7 @@ static int control_socket_init(int port) { } /* Register to eloop and ready for the socket event */ - if (eloop_register_read_sock(s, control_receive_message, NULL, NULL)) { + if (qt_eloop_register_read_sock(s, control_receive_message, NULL, NULL)) { indigo_logger(LOG_LEVEL_ERROR, "Failed to initiate ControlAppC"); close(s); return -1; @@ -115,7 +115,7 @@ static void control_receive_message(int sock, void *eloop_ctx, void *sock_ctx) { fill_wrapper_ack(&resp, req.hdr.seq, 0x31, "Unable to parse the packet"); len = assemble_packet(buffer, BUFFER_LEN, &resp); - sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); + sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); goto done; } @@ -127,7 +127,7 @@ static void control_receive_message(int sock, void *eloop_ctx, void *sock_ctx) { indigo_logger(LOG_LEVEL_ERROR, "API Unknown (0x%04x): No registered handler", req.hdr.type); fill_wrapper_ack(&resp, req.hdr.seq, 0x31, "Unable to find the API handler"); len = assemble_packet(buffer, BUFFER_LEN, &resp); - sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); + sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); goto done; } @@ -142,7 +142,7 @@ static void control_receive_message(int sock, void *eloop_ctx, void *sock_ctx) { indigo_logger(LOG_LEVEL_ERROR, "API %s: Failed to verify and return NACK", api->name); fill_wrapper_ack(&resp, req.hdr.seq, 1, "Unable to find the API handler"); len = assemble_packet(buffer, BUFFER_LEN, &resp); - sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); + sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); goto done; } @@ -151,7 +151,7 @@ static void control_receive_message(int sock, void *eloop_ctx, void *sock_ctx) { if (api->handle && api->handle(&req, &resp) == 0) { indigo_logger(LOG_LEVEL_INFO, "API %s: Return execution result", api->name); len = assemble_packet(buffer, BUFFER_LEN, &resp); - sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); + sendto(sock, (const char *)buffer, len, MSG_CONFIRM, (const struct sockaddr *) &from, fromlen); } else { indigo_logger(LOG_LEVEL_DEBUG, "API %s (0x%04x): No handle function", api ? api->name : "Unknown", req.hdr.type); } @@ -270,7 +270,7 @@ static void handle_term(int sig, void *eloop_ctx, void *signal_ctx) { indigo_logger(LOG_LEVEL_INFO, "Signal %d received - terminating\n", sig); (void) eloop_ctx; (void) signal_ctx; - eloop_terminate(); + qt_eloop_terminate(); vendor_deinit(); } @@ -323,22 +323,22 @@ int main(int argc, char* argv[]) { vendor_init(); /* Start eloop */ - eloop_init(NULL); + qt_eloop_init(NULL); /* Register SIGTERM */ - eloop_register_signal(SIGINT, handle_term, NULL); - eloop_register_signal(SIGTERM, handle_term, NULL); + qt_eloop_register_signal(SIGINT, handle_term, NULL); + qt_eloop_register_signal(SIGTERM, handle_term, NULL); /* Bind the service port and register to eloop */ service_socket = control_socket_init(get_service_port()); if (service_socket >= 0) { - eloop_run(); + qt_eloop_run(); } else { indigo_logger(LOG_LEVEL_INFO, "Failed to initiate the UDP socket"); } /* Stop eloop */ - eloop_destroy(); + qt_eloop_destroy(); indigo_logger(LOG_LEVEL_INFO, "ControlAppC stops"); if (service_socket >= 0) { indigo_logger(LOG_LEVEL_INFO, "Close service port: %d", get_service_port()); diff --git a/utils.c b/utils.c index 2804208..eb4c2e1 100644 --- a/utils.c +++ b/utils.c @@ -179,7 +179,7 @@ void open_tc_app_log() { } 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); + indigo_logger(LOG_LEVEL_ERROR, "Failed to open the file %s", APP_LOG_FILE); } #endif } @@ -215,7 +215,7 @@ int pipe_command(char *buffer, int buffer_size, char *cmd, char *parameter[]) { if (pid == 0) { // Replace stdout with the write end of the pipe - dup2(pipefds[1], STDOUT_FILENO); + dup2(pipefds[1], STDOUT_FILENO); // Close read to pipe, in child close(pipefds[0]); execv(cmd, parameter); @@ -322,7 +322,7 @@ static void loopback_server_timeout(void *eloop_ctx, void *timeout_ctx) { (void)timeout_ctx; - eloop_unregister_read_sock(s); + qt_eloop_unregister_read_sock(s); close(s); loopback_socket = 0; indigo_logger(LOG_LEVEL_INFO, "Loopback server stops"); @@ -363,12 +363,12 @@ int loopback_server_start(char *local_ip, char *local_port, int timeout) { } /* Register to eloop and ready for the socket event */ - if (eloop_register_read_sock(s, loopback_server_receive_message, NULL, NULL)) { + if (qt_eloop_register_read_sock(s, loopback_server_receive_message, NULL, NULL)) { indigo_logger(LOG_LEVEL_ERROR, "Failed to initiate ControlAppC"); return -1; } loopback_socket = s; - eloop_register_timeout(timeout, 0, loopback_server_timeout, (void*)(intptr_t)s, NULL); + qt_eloop_register_timeout(timeout, 0, loopback_server_timeout, (void*)(intptr_t)s, NULL); indigo_logger(LOG_LEVEL_INFO, "Loopback Client starts ip %s port %s", local_ip, local_port); return 0; @@ -376,8 +376,8 @@ int loopback_server_start(char *local_ip, char *local_port, int timeout) { int loopback_server_stop() { if (loopback_socket) { - eloop_cancel_timeout(loopback_server_timeout, (void*)(intptr_t)loopback_socket, NULL); - eloop_unregister_read_sock(loopback_socket); + qt_eloop_cancel_timeout(loopback_server_timeout, (void*)(intptr_t)loopback_socket, NULL); + qt_eloop_unregister_read_sock(loopback_socket); close(loopback_socket); loopback_socket = 0; } @@ -403,7 +403,7 @@ unsigned short icmp_checksum(unsigned short *buf, int size) return ~sum; } -void setup_icmphdr(u_int8_t type, u_int8_t code, u_int16_t id, +void setup_icmphdr(u_int8_t type, u_int8_t code, u_int16_t id, u_int16_t seq, struct icmphdr *icmphdr, int packet_size) { memset(icmphdr, 0, sizeof(struct icmphdr)); @@ -458,7 +458,7 @@ void send_one_loopback_icmp_packet(struct loopback_info *info) { } done: - eloop_register_timeout(0, info->rate * 1000000, send_continuous_loopback_packet, info, NULL); + qt_eloop_register_timeout(0, info->rate * 1000000, send_continuous_loopback_packet, info, NULL); } void send_one_loopback_udp_packet(struct loopback_info *info) { @@ -473,7 +473,7 @@ void send_one_loopback_udp_packet(struct loopback_info *info) { indigo_logger(LOG_LEVEL_INFO, "Send failed on packet %d", info->pkt_sent); // In case Tool doesn't send stop or doesn't receive stop if (info->pkt_sent < 1000) - eloop_register_timeout(0, info->rate*1000000, send_continuous_loopback_packet, info, NULL); + qt_eloop_register_timeout(0, info->rate*1000000, send_continuous_loopback_packet, info, NULL); return; } indigo_logger(LOG_LEVEL_INFO, "Packet %d: Send loopback %d bytes data", @@ -484,13 +484,13 @@ void send_one_loopback_udp_packet(struct loopback_info *info) { indigo_logger(LOG_LEVEL_INFO, "recv failed on packet %d", info->pkt_sent); // In case Tool doesn't send stop or doesn't receive stop if (info->pkt_sent < 1000) - eloop_register_timeout(0, info->rate*1000000, send_continuous_loopback_packet, info, NULL); + qt_eloop_register_timeout(0, info->rate*1000000, send_continuous_loopback_packet, info, NULL); return; } info->pkt_rcv++; indigo_logger(LOG_LEVEL_INFO, "Receive echo %d bytes data", recv_len); - eloop_register_timeout(0, info->rate*1000000, send_continuous_loopback_packet, info, NULL); + qt_eloop_register_timeout(0, info->rate*1000000, send_continuous_loopback_packet, info, NULL); } void send_continuous_loopback_packet(void *eloop_ctx, void *sock_ctx) { @@ -512,7 +512,7 @@ int stop_loopback_data(int *pkt_sent) if (loopback.sock <= 0) return 0; - eloop_cancel_timeout(send_continuous_loopback_packet, &loopback, NULL); + qt_eloop_cancel_timeout(send_continuous_loopback_packet, &loopback, NULL); close(loopback.sock); loopback.sock = 0; if (pkt_sent) @@ -582,7 +582,7 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet memset(loopback.message, 0, sizeof(loopback.message)); for (i = 0; (i < packet_size) && (i < (int)sizeof(loopback.message)); i++) loopback.message[i] = 0x0A; - eloop_register_timeout(0, 0, send_continuous_loopback_packet, &loopback, NULL); + qt_eloop_register_timeout(0, 0, send_continuous_loopback_packet, &loopback, NULL); indigo_logger(LOG_LEVEL_INFO, "Send continuous loopback data to ip %s port %u", target_ip, target_port); return 0; @@ -675,7 +675,7 @@ int send_icmp_data(char *target_ip, int packet_count, int packet_size, double ra snprintf(loopback.target_ip, sizeof(loopback.target_ip), "%s", target_ip); for (i = sizeof(struct icmphdr); (i < (size_t)packet_size) && (i < sizeof(loopback.message)); i++) loopback.message[i] = 0x0A; - eloop_register_timeout(0, 0, send_continuous_loopback_packet, &loopback, NULL); + qt_eloop_register_timeout(0, 0, send_continuous_loopback_packet, &loopback, NULL); indigo_logger(LOG_LEVEL_INFO, "Send continuous loopback data to ip %s", loopback.target_ip); return 0; } @@ -787,8 +787,8 @@ int get_mac_address(char *buffer, int size, char *interface) { } strcpy(s.ifr_name, interface); if (0 == ioctl(fd, SIOCGIFHWADDR, &s)) { - sprintf(buffer, "%02x:%02x:%02x:%02x:%02x:%02x", - (char)s.ifr_addr.sa_data[0]&0x00ff, (char)s.ifr_addr.sa_data[1]&0x00ff, (char)s.ifr_addr.sa_data[2]&0x00ff, + sprintf(buffer, "%02x:%02x:%02x:%02x:%02x:%02x", + (char)s.ifr_addr.sa_data[0]&0x00ff, (char)s.ifr_addr.sa_data[1]&0x00ff, (char)s.ifr_addr.sa_data[2]&0x00ff, (char)s.ifr_addr.sa_data[3]&0x00ff, (char)s.ifr_addr.sa_data[4]&0x00ff, (char)s.ifr_addr.sa_data[5]&0x00ff); close(fd); return 0; @@ -867,7 +867,7 @@ int reset_bridge(char *br) { control_interface(br, "down"); sprintf(cmd, "brctl delbr %s", br); system(cmd); - + bridge_created = 0; return 0; @@ -897,7 +897,7 @@ int control_interface(char *ifname, char *op) { /* sprintf(cmd, "ifconfig %s %s", ifname, op); */ sprintf(cmd, "ip link set %s %s", ifname, op); system(cmd); - + return 0; } @@ -908,7 +908,7 @@ int set_interface_ip(char *ifname, char *ip) { /* sprintf(cmd, "ifconfig %s %s", ifname, ip); */ sprintf(cmd, "ip addr add %s dev %s", ip, ifname); system(cmd); - + return 0; } @@ -984,7 +984,7 @@ struct interface_info* assign_wireless_interface_info(struct bss_identifier_info char ifname[16]; memcpy(ifname, interfaces[i].ifname, sizeof(ifname)); - if ((interfaces[i].band == bss->band) && + if ((interfaces[i].band == bss->band) && (interfaces[i].identifier == UNUSED_IDENTIFIER)) { configured_interface_count++; interfaces[i].identifier = bss->identifier; @@ -1006,7 +1006,7 @@ struct interface_info* get_wireless_interface_info(int band, int identifier) { int i; for (i = 0; i < interface_count; i++) { - if ((interfaces[i].band == band) && + if ((interfaces[i].band == band) && ((interfaces[i].identifier != UNUSED_IDENTIFIER) && (interfaces[i].identifier == identifier))) { return &interfaces[i]; @@ -1224,7 +1224,7 @@ int show_wireless_interface_info() { band = "6GHz"; } - indigo_logger(LOG_LEVEL_INFO, "Interface Name: %s, Band: %s, identifier %d", + indigo_logger(LOG_LEVEL_INFO, "Interface Name: %s, Band: %s, identifier %d", interfaces[i].ifname, band, interfaces[i].identifier); } return 0; @@ -1235,7 +1235,7 @@ int parse_wireless_interface_info(char *info) { char *delimit = ","; token = strtok(info, delimit); - + while(token != NULL) { if (strncmp(token, "2:", 2) == 0) { add_wireless_interface_info(BAND_24GHZ, -1, token+2); @@ -1279,7 +1279,7 @@ void set_default_wireless_interface_info(int band) { } void reset_default_wireless_interface_info() { - default_interface = NULL; + default_interface = NULL; } /* Parse BSS IDENTIFIER TLV */ @@ -1389,8 +1389,8 @@ int set_service_port(int port) { /* Channel functions */ struct channel_info band_24[] = { {1, 2412}, {2, 2417}, {3, 2422}, {4, 2427}, {5, 2432}, {6, 2437}, {7, 2442}, {8, 2447}, {9, 2452}, {10, 2457}, {11, 2462} }; -struct channel_info band_5[] = { {36, 5180}, {40, 5200}, {44, 5220}, {48, 5240}, {52, 5260}, {56, 5280}, {60, 5300}, {64, 5320}, {100, 5500}, {104, 5520}, {108, 5540}, - {112, 5560}, {116, 5580}, {120, 5600}, {124, 5620}, {128, 5640}, {132, 5660}, {136, 5680}, {140, 5700}, {144, 5720}, {149, 5745}, +struct channel_info band_5[] = { {36, 5180}, {40, 5200}, {44, 5220}, {48, 5240}, {52, 5260}, {56, 5280}, {60, 5300}, {64, 5320}, {100, 5500}, {104, 5520}, {108, 5540}, + {112, 5560}, {116, 5580}, {120, 5600}, {124, 5620}, {128, 5640}, {132, 5660}, {136, 5680}, {140, 5700}, {144, 5720}, {149, 5745}, {153, 5765}, {157, 5785}, {161, 5805}, {165, 8525} }; int verify_band_from_freq(int freq, int band) { @@ -1574,7 +1574,7 @@ int insert_wpa_network_config(char *config) { char buffer[S_BUFFER_LEN]; f_ptr = fopen(path, "r"); - f_tmp_ptr = fopen(tmp_path, "w"); + f_tmp_ptr = fopen(tmp_path, "w"); if (f_ptr == NULL || f_tmp_ptr == NULL) { indigo_logger(LOG_LEVEL_ERROR, "Failed to open the files"); @@ -1584,7 +1584,7 @@ int insert_wpa_network_config(char *config) { memset(buffer, 0, sizeof(buffer)); while ((fgets(buffer, S_BUFFER_LEN, f_ptr)) != NULL) { if (strstr(buffer, target_str) != NULL) { - indigo_logger(LOG_LEVEL_DEBUG, + indigo_logger(LOG_LEVEL_DEBUG, "insert config: %s into the wpa_supplicant conf.", config); fputs(config, f_tmp_ptr); } @@ -1767,13 +1767,13 @@ int http_file_post(char *host, int port, char *path, char *file_name) { retval = -EIO; goto done; } - + while ((numbytes=recv(socketfd, response, sizeof(response), 0)) > 0) { response[numbytes] = '\0'; indigo_logger(LOG_LEVEL_DEBUG, "Server response: %s", response); } indigo_logger(LOG_LEVEL_INFO, "Upload completes"); - + done: if (header) { free(header); From 9d47e5320615264c91259168401bc0c82a6249e5 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:38 +0530 Subject: [PATCH 14/20] Add P2P feature flag Protects P2P code in case the DUT doesn't support it yet. Signed-off-by: Triveni Danda --- Makefile | 4 + indigo_api_callback.h | 2 + indigo_api_callback_dut.c | 445 ++++++++++++++++++++------------------ indigo_api_callback_tp.c | 16 ++ utils.c | 8 + vendor_specific.h | 2 + vendor_specific_dut.c | 2 + vendor_specific_tp.c | 2 + 8 files changed, 275 insertions(+), 206 deletions(-) diff --git a/Makefile b/Makefile index 598b3e0..eacab80 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,10 @@ CFLAGS += -DCONFIG_CTRL_IFACE_UDP CFLAGS += -D_TEST_PLATFORM_ endif +# Feature flags +# Enable by default +CFLAGS += -DCONFIG_P2P + # Define the package version ifneq ($(VERSION),) CFLAGS += -D_VERSION_='$(VERSION)' diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 0b9b480..cd82bb7 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -268,6 +268,7 @@ 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 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 /* P2P */ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int p2p_find_handler(struct packet_wrapper *req, struct packet_wrapper *resp); @@ -280,4 +281,5 @@ static int get_p2p_intent_value_handler(struct packet_wrapper *req, struct packe 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 /* End Of CONFIG_P2P */ #endif // __INDIGO_API_CALLBACK diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index f0b9470..ef91397 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -76,6 +76,7 @@ void register_apis() { /* TODO: Add the handlers */ register_api(API_STA_SET_CHANNEL_WIDTH, NULL, NULL); register_api(API_STA_POWER_SAVE, NULL, NULL); +#ifdef CONFIG_P2P register_api(API_P2P_START_UP, NULL, start_up_p2p_handler); register_api(API_P2P_FIND, NULL, p2p_find_handler); register_api(API_P2P_LISTEN, NULL, p2p_listen_handler); @@ -87,6 +88,7 @@ void register_apis() { 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); +#endif /*End Of CONFIG_P2P */ register_api(API_STA_ENABLE_WSC, NULL, enable_wsc_sta_handler); } @@ -164,12 +166,14 @@ 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) { +#ifdef CONFIG_P2P /* 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))); } +#endif /* End Of CONFIG_P2P */ } if (strcmp(band, TLV_BAND_24GHZ) == 0) { @@ -1251,6 +1255,7 @@ 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) { +#ifdef CONFIG_P2P /* Get P2P GO/Client or Device MAC */ if (get_p2p_mac_addr(mac_addr, sizeof(mac_addr))) { indigo_logger(LOG_LEVEL_INFO, "Can't find P2P Device MAC. Use wireless IF MAC"); @@ -1259,6 +1264,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; goto done; +#endif /* End Of CONFIG_P2P */ } else { wlan = get_wireless_interface_info(bss_info.band, bss_info.identifier); w = wpa_ctrl_open(get_hapd_ctrl_path_by_id(wlan)); @@ -1364,13 +1370,19 @@ 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]; +#ifdef CONFIG_P2P char if_name[32]; +#endif /* End Of CONFIG_P2P */ /* 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)); +#ifdef CONFIG_P2P 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())) { +#else + if (find_interface_ip(local_ip, sizeof(local_ip), get_wlans_bridge())) { +#endif /* End Of CONFIG_P2P */ 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()); @@ -1747,20 +1759,30 @@ static int get_ip_addr_handler(struct packet_wrapper *req, struct packet_wrapper char *message = NULL; char buffer[64]; struct tlv_hdr *tlv = NULL; - char value[16], if_name[32]; + char value[16]; +#ifdef CONFIG_P2P + char if_name[32]; int role = 0; +#endif /* End Of CONFIG_P2P */ + memset(value, 0, sizeof(value)); tlv = find_wrapper_tlv_by_id(req, TLV_ROLE); if (tlv) { memcpy(value, tlv->value, tlv->len); +#ifdef CONFIG_P2P role = atoi(value); +#endif /* End Of CONFIG_P2P */ } +#ifdef CONFIG_P2P 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())) { +#else + if (find_interface_ip(buffer, sizeof(buffer), get_wlans_bridge())) { +#endif /* End Of CONFIG_P2P */ status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; } else if (find_interface_ip(buffer, sizeof(buffer), get_wireless_interface())) { @@ -2327,6 +2349,7 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet 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; char buffer[S_BUFFER_LEN]; @@ -2646,6 +2669,209 @@ static int p2p_start_wps_handler(struct packet_wrapper *req, struct packet_wrapp return 0; } +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]; + + memset(response, 0, sizeof(response)); + snprintf(response, sizeof(response), "%d", P2P_GO_INTENT); + + 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; +} + +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]; + char freq[16], he[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; + } + + memset(persist, 0, sizeof(persist)); + tlv = find_wrapper_tlv_by_id(req, TLV_PERSISTENT); + if (tlv) { + /* 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 */ + 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 (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); + /* 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 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]; + 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], he[16], persist[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)); + 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); + } 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_IEEE80211_AX); + 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)); + 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%s%s", mac, pin_code, method, type, go_intent, he, persist); + } 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%s%s", mac, method, type, go_intent, he, persist); + } + 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; +} +#endif /* End Of CONFIG_P2P */ + static int sta_scan_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len, status = TLV_VALUE_STATUS_NOT_OK; char *message = TLV_VALUE_WPA_S_SCAN_NOT_OK; @@ -2995,109 +3221,6 @@ static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct pack return 0; } -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]; - 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], he[16], persist[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)); - 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); - } 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_IEEE80211_AX); - 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)); - 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%s%s", mac, pin_code, method, type, go_intent, he, persist); - } 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%s%s", mac, method, type, go_intent, he, persist); - } - 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; @@ -3112,7 +3235,9 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper if (tlv) { memcpy(role, tlv->value, tlv->len); if (atoi(role) == DUT_TYPE_P2PUT) { +#ifdef CONFIG_P2P get_p2p_group_if(if_name, sizeof(if_name)); +#endif /* End Of CONFIG_P2P */ } else { indigo_logger(LOG_LEVEL_ERROR, "DHCP only supports in P2PUT"); goto done; @@ -3152,15 +3277,19 @@ static int stop_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper * char *message = TLV_VALUE_NOT_OK; char role[8]; struct tlv_hdr *tlv = NULL; +#ifdef CONFIG_P2P char if_name[32]; +#endif /* End Of CONFIG_P2P */ 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) { +#ifdef CONFIG_P2P if (!get_p2p_group_if(if_name, sizeof(if_name))) reset_interface_ip(if_name); +#endif /* End Of CONFIG_P2P */ } else { indigo_logger(LOG_LEVEL_ERROR, "DHCP only supports in P2PUT"); goto done; @@ -3220,7 +3349,11 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper message = TLV_VALUE_WPA_S_CTRL_NOT_OK; goto done; } +#ifdef CONFIG_P2P } else if (role == DUT_TYPE_STAUT || role == DUT_TYPE_P2PUT) { +#else + } else if (role == DUT_TYPE_STAUT) { +#endif /* End Of CONFIG_P2P */ sprintf(buffer, "WPS_PIN get"); w = wpa_ctrl_open(get_wpas_ctrl_path()); if (!w) { @@ -3256,24 +3389,6 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper return 0; } -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]; - - memset(response, 0, sizeof(response)); - snprintf(response, sizeof(response), "%d", P2P_GO_INTENT); - - - 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; -} - 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]; @@ -3514,90 +3629,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe return 0; } -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]; - char freq[16], he[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; - } - - memset(persist, 0, sizeof(persist)); - tlv = find_wrapper_tlv_by_id(req, TLV_PERSISTENT); - if (tlv) { - /* 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 */ - 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 (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); - /* 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 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]; @@ -3702,6 +3734,7 @@ static int set_p2p_ext_listen_handler(struct packet_wrapper *req, struct packet_ } return 0; } +#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; diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 2e14d9b..c985a9e 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -68,7 +68,9 @@ 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); +#ifdef CONFIG_P2P register_api(API_P2P_START_UP, NULL, start_up_p2p_handler); +#endif /* End Of CONFIG_P2P */ } static int get_control_app_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -986,11 +988,13 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe if (tlv) { memcpy(role, tlv->value, tlv->len); if (atoi(role) == DUT_TYPE_P2PUT) { +#ifdef CONFIG_P2P /* 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()); } +#endif /* End Of CONFIG_P2P */ } } else { get_mac_address(mac_addr, sizeof(mac_addr), get_wireless_interface()); @@ -1126,13 +1130,19 @@ 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]; +#ifdef CONFIG_P2P char if_name[32]; +#endif /* End Of CONFIG_P2P */ /* 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)); +#ifdef CONFIG_P2P 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())) { +#else + if (find_interface_ip(local_ip, sizeof(local_ip), get_wlans_bridge())) { +#endif /* End Of CONFIG_P2P */ 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()); @@ -1907,6 +1917,7 @@ static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_ 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; char buffer[S_BUFFER_LEN], response[1024], log_level[TLV_VALUE_SIZE], value[TLV_VALUE_SIZE]; @@ -1995,6 +2006,7 @@ static int start_up_p2p_handler(struct packet_wrapper *req, struct packet_wrappe fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); return 0; } +#endif /* End Of CONFIG_P2P */ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -2010,7 +2022,9 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper if (tlv) { memcpy(role, tlv->value, tlv->len); if (atoi(role) == DUT_TYPE_P2PUT) { +#ifdef CONFIG_P2P get_p2p_group_if(if_name, sizeof(if_name)); +#endif /* End Of CONFIG_P2P */ } else { } } else { @@ -2057,8 +2071,10 @@ 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) { +#ifdef CONFIG_P2P if (get_p2p_group_if(if_name, sizeof(if_name))) reset_interface_ip(if_name); +#endif /* End Of CONFIG_P2P */ } else { } } else { diff --git a/utils.c b/utils.c index eb4c2e1..c104f0f 100644 --- a/utils.c +++ b/utils.c @@ -546,8 +546,12 @@ int send_udp_data(char *target_ip, int target_port, int packet_count, int packet } if (is_bridge_created()) { snprintf(ifname, sizeof(ifname), "%s", get_wlans_bridge()); +#ifdef CONFIG_P2P } else if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); +#else + } +#endif /* End Of CONFIG_P2P */ 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); @@ -653,8 +657,12 @@ int send_icmp_data(char *target_ip, int packet_count, int packet_size, double ra if (is_bridge_created()) { snprintf(ifname, sizeof(ifname), "%s", get_wlans_bridge()); +#ifdef CONFIG_P2P } else if (get_p2p_group_if(ifname, sizeof(ifname)) != 0) snprintf(ifname, sizeof(ifname), "%s", get_wireless_interface()); +#else + } +#endif /* End Of CONFIG_P2P */ 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); diff --git a/vendor_specific.h b/vendor_specific.h index e1dd961..c9eec5c 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -171,9 +171,11 @@ 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); +#ifdef CONFIG_P2P 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); +#endif /* End Of CONFIG_P2P */ 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 f1701ca..6d4e309 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -270,6 +270,7 @@ void start_ap_set_wlan_params(void *if_info) { #endif } +#ifdef CONFIG_P2P /* 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; @@ -346,6 +347,7 @@ int get_p2p_dev_if(char *if_name, size_t size) { return 0; } +#endif /* End Of CONFIG_P2P */ /* Append IP range config and start dhcpd */ void start_dhcp_server(char *if_name, char *ip_addr) diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 3d4fdb7..7a738a1 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -493,6 +493,7 @@ const struct sta_driver_ops sta_driver_platform2_ops = { .set_phy_mode = set_phy_mode_platform2, }; +#ifdef CONFIG_P2P /* 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; @@ -562,6 +563,7 @@ int get_p2p_group_if(char *if_name, size_t size) { return error; } +#endif /* End Of CONFIG_P2P */ /* Append IP range config and start dhcpd */ void start_dhcp_server(char *if_name, char *ip_addr) From 19ae2de6b4f2a7eeacb11e138934adb34240a07e Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:42 +0530 Subject: [PATCH 15/20] Add WNM feature flag Protects WNM code in case the DUT doesn't support it yet. Signed-off-by: Triveni Danda --- Makefile | 2 +- indigo_api_callback.h | 4 ++++ indigo_api_callback_dut.c | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index eacab80..b17b7b5 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ endif # Feature flags # Enable by default -CFLAGS += -DCONFIG_P2P +CFLAGS += -DCONFIG_P2P -DCONFIG_WNM # Define the package version ifneq ($(VERSION),) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index cd82bb7..ca53f19 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -249,7 +249,9 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_ap_disconnect_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int set_ap_parameter_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +#ifdef CONFIG_WNM 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 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); @@ -259,7 +261,9 @@ static int configure_sta_handler(struct packet_wrapper *req, struct packet_wrapp static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_disconnect_handler(struct packet_wrapper *req, struct packet_wrapper *resp); static int send_sta_reconnect_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +#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); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index ef91397..2c954e9 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -56,7 +56,9 @@ void register_apis() { register_api(API_AP_TRIGGER_CHANSWITCH, NULL, trigger_ap_channel_switch); register_api(API_AP_SEND_DISCONNECT, NULL, send_ap_disconnect_handler); register_api(API_AP_SET_PARAM , NULL, set_ap_parameter_handler); +#ifdef CONFIG_WNM register_api(API_AP_SEND_BTM_REQ, NULL, send_ap_btm_handler); +#endif /* End Of CONFIG_WNM */ register_api(API_AP_START_WPS, NULL, start_wps_ap_handler); register_api(API_AP_CONFIGURE_WSC, NULL, configure_ap_wsc_handler); /* STA */ @@ -66,7 +68,9 @@ 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); +#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); @@ -1545,6 +1549,7 @@ static int set_ap_parameter_handler(struct packet_wrapper *req, struct packet_wr return 0; } +#ifdef CONFIG_WNM static int send_ap_btm_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_NOT_OK; size_t resp_len; @@ -1677,6 +1682,7 @@ static int send_ap_btm_handler(struct packet_wrapper *req, struct packet_wrapper } return 0; } +#endif /* End Of CONFIG_WNM */ static int trigger_ap_channel_switch(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_NOT_OK; @@ -2172,6 +2178,7 @@ static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_w return 0; } +#ifdef CONFIG_WNM static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_NOT_OK; size_t resp_len; @@ -2231,6 +2238,7 @@ static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_ } return 0; } +#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; From 5ad936c5e659bce454ccd336ba4e1ec01080da16 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:44 +0530 Subject: [PATCH 16/20] Add HotSpot 2.0 feature flag Protects HS2.0 code in case the DUT doesn't support it yet. Signed-off-by: Triveni Danda --- Makefile | 2 +- indigo_api_callback.h | 5 +- indigo_api_callback_dut.c | 240 +++++++++++++++++++------------------- indigo_api_callback_tp.c | 4 + 4 files changed, 131 insertions(+), 120 deletions(-) diff --git a/Makefile b/Makefile index b17b7b5..ed1fdc9 100644 --- a/Makefile +++ b/Makefile @@ -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),) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index ca53f19..305467a 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -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 diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 2c954e9..ef46c2b 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -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); @@ -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; @@ -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; @@ -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) { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index c985a9e..9b9ed0e 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -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); @@ -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; @@ -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 */ From 01a1fded60da53bd48c210aba312f5a1e73ee24c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:47 +0530 Subject: [PATCH 17/20] Add AP support flag Protects AP code in case the DUT doesn't support it yet. Signed-off-by: Triveni Danda --- Makefile | 2 +- indigo_api_callback.h | 5 + indigo_api_callback_dut.c | 284 ++++++++++++++++++++------------------ indigo_api_callback_tp.c | 6 + vendor_specific.h | 2 + vendor_specific_dut.c | 2 + vendor_specific_tp.c | 2 + 7 files changed, 167 insertions(+), 136 deletions(-) diff --git a/Makefile b/Makefile index ed1fdc9..64ac687 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ endif # Feature flags # Enable by default -CFLAGS += -DCONFIG_P2P -DCONFIG_WNM -DCONFIG_HS20 +CFLAGS += -DCONFIG_P2P -DCONFIG_WNM -DCONFIG_HS20 -DCONFIG_AP # Define the package version ifneq ($(VERSION),) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 305467a..300d90d 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -243,6 +243,8 @@ static int start_dhcp_handler(struct packet_wrapper *req, struct packet_wrapper 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 */ 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); @@ -255,6 +257,8 @@ 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 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_AP */ + /* 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); @@ -275,6 +279,7 @@ static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_w #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 /* P2P */ static int start_up_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 ef46c2b..bd1c99f 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -49,6 +49,7 @@ void register_apis() { 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); +#ifdef CONFIG_AP /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); @@ -61,6 +62,7 @@ void register_apis() { #endif /* End Of CONFIG_WNM */ register_api(API_AP_START_WPS, NULL, start_wps_ap_handler); register_api(API_AP_CONFIGURE_WSC, NULL, configure_ap_wsc_handler); +#endif /* End Of CONFIG_AP */ /* STA */ register_api(API_STA_ASSOCIATE, NULL, associate_sta_handler); register_api(API_STA_CONFIGURE, NULL, configure_sta_handler); @@ -159,6 +161,7 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe sta_configured = 0; sta_started = 0; } else if (atoi(role) == DUT_TYPE_APUT) { +#ifdef CONFIG_AP /* stop the hostapd and release IP address */ memset(buffer, 0, sizeof(buffer)); sprintf(buffer, "killall %s 1>/dev/null 2>/dev/null", get_hapd_exec_file()); @@ -171,6 +174,7 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe reset_bridge(get_wlans_bridge()); /* reset interfaces info */ clear_interfaces_resource(); +#endif /* End Of CONFIG_AP */ } else if (atoi(role) == DUT_TYPE_P2PUT) { #ifdef CONFIG_P2P /* If TP is P2P client, GO can't stop before client removes group monitor if */ @@ -208,6 +212,8 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe return 0; } + +#ifdef CONFIG_AP // 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; @@ -1108,6 +1114,141 @@ static int configure_ap_wsc_handler(struct packet_wrapper *req, struct packet_wr return 0; } +#ifdef CONFIG_WNM +static int send_ap_btm_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { + int status = TLV_VALUE_STATUS_NOT_OK; + size_t resp_len; + char *message = NULL; + struct tlv_hdr *tlv = NULL; + struct wpa_ctrl *w = NULL; + char request[4096]; + char response[4096]; + char buffer[1024]; + + char bssid[256]; + char disassoc_imminent[256]; + char disassoc_timer[256]; + char candidate_list[256]; + char reassoc_retry_delay[256]; + char bss_term_bit[256]; + char bss_term_tsf[256]; + char bss_term_duration[256]; + + memset(bssid, 0, sizeof(bssid)); + memset(disassoc_imminent, 0, sizeof(disassoc_imminent)); + memset(disassoc_timer, 0, sizeof(disassoc_timer)); + memset(candidate_list, 0, sizeof(candidate_list)); + memset(reassoc_retry_delay, 0, sizeof(reassoc_retry_delay)); + memset(bss_term_bit, 0, sizeof(bss_term_bit)); + memset(bss_term_tsf, 0, sizeof(bss_term_tsf)); + memset(bss_term_duration, 0, sizeof(bss_term_duration)); + + /* ControlApp on DUT */ + /* TLV: BSSID (required) */ + tlv = find_wrapper_tlv_by_id(req, TLV_BSSID); + if (tlv) { + memcpy(bssid, tlv->value, tlv->len); + } + /* DISASSOC_IMMINENT disassoc_imminent=%s */ + tlv = find_wrapper_tlv_by_id(req, TLV_DISASSOC_IMMINENT); + if (tlv) { + memcpy(disassoc_imminent, tlv->value, tlv->len); + } + /* DISASSOC_TIMER disassoc_timer=%s */ + tlv = find_wrapper_tlv_by_id(req, TLV_DISASSOC_TIMER); + if (tlv) { + memcpy(disassoc_timer, tlv->value, tlv->len); + } + /* REASSOCIAITION_RETRY_DELAY mbo=0:{}:0 */ + tlv = find_wrapper_tlv_by_id(req, TLV_REASSOCIAITION_RETRY_DELAY); + if (tlv) { + memcpy(reassoc_retry_delay, tlv->value, tlv->len); + } + /* CANDIDATE_LIST pref=1 */ + tlv = find_wrapper_tlv_by_id(req, TLV_CANDIDATE_LIST); + if (tlv) { + memcpy(candidate_list, tlv->value, tlv->len); + } + /* BSS_TERMINATION bss_term_bit */ + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_TERMINATION); + if (tlv) { + memcpy(bss_term_bit, tlv->value, tlv->len); + } + /* BSS_TERMINATION_TSF bss_term_tsf */ + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_TERMINATION_TSF); + if (tlv) { + memcpy(bss_term_tsf, tlv->value, tlv->len); + } + /* BSS_TERMINATION_DURATION bss_term_duration */ + tlv = find_wrapper_tlv_by_id(req, TLV_BSS_TERMINATION_DURATION); + if (tlv) { + memcpy(bss_term_duration, tlv->value, tlv->len); + } + + /* Assemble hostapd command for BSS_TM_REQ */ + memset(request, 0, sizeof(request)); + sprintf(request, "BSS_TM_REQ %s", bssid); + /* disassoc_imminent=%s */ + if (strlen(disassoc_imminent)) { + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, " disassoc_imminent=%s", disassoc_imminent); + strcat(request, buffer); + } + /* disassoc_timer=%s */ + if (strlen(disassoc_timer)) { + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, " disassoc_timer=%s", disassoc_timer); + strcat(request, buffer); + } + /* reassoc_retry_delay=%s */ + if (strlen(reassoc_retry_delay)) { + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, " mbo=0:%s:0", reassoc_retry_delay); + strcat(request, buffer); + } + /* if bss_term_bit && bss_term_tsf && bss_term_duration, then bss_term={bss_term_tsf},{bss_term_duration} */ + if (strlen(bss_term_bit) && strlen(bss_term_tsf) && strlen(bss_term_duration) ) { + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, " bss_term=%s,%s", bss_term_tsf, bss_term_duration); + strcat(request, buffer); + } + /* candidate_list */ + if (strlen(candidate_list) && atoi(candidate_list) == 1) { + memset(buffer, 0, sizeof(buffer)); + sprintf(buffer, " pref=1"); + strcat(request, buffer); + } + indigo_logger(LOG_LEVEL_DEBUG, "cmd:%s", request); + + /* 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_HOSTAPD_CTRL_NOT_OK; + goto done; + } + resp_len = sizeof(response) - 1; + wpa_ctrl_request(w, request, strlen(request), 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_HOSTAPD_RESP_NOT_OK; + 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; +} +#endif /* End Of CONFIG_WNM */ +#endif /* End Of CONFIG_AP */ /* deprecated */ static int create_bridge_network_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { @@ -1427,6 +1568,7 @@ static int stop_loop_back_server_handler(struct packet_wrapper *req, struct pack return 0; } +#ifdef CONFIG_AP static int send_ap_disconnect_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len, status = TLV_VALUE_STATUS_NOT_OK; char buffer[S_BUFFER_LEN]; @@ -1551,141 +1693,6 @@ static int set_ap_parameter_handler(struct packet_wrapper *req, struct packet_wr return 0; } -#ifdef CONFIG_WNM -static int send_ap_btm_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { - int status = TLV_VALUE_STATUS_NOT_OK; - size_t resp_len; - char *message = NULL; - struct tlv_hdr *tlv = NULL; - struct wpa_ctrl *w = NULL; - char request[4096]; - char response[4096]; - char buffer[1024]; - - char bssid[256]; - char disassoc_imminent[256]; - char disassoc_timer[256]; - char candidate_list[256]; - char reassoc_retry_delay[256]; - char bss_term_bit[256]; - char bss_term_tsf[256]; - char bss_term_duration[256]; - - memset(bssid, 0, sizeof(bssid)); - memset(disassoc_imminent, 0, sizeof(disassoc_imminent)); - memset(disassoc_timer, 0, sizeof(disassoc_timer)); - memset(candidate_list, 0, sizeof(candidate_list)); - memset(reassoc_retry_delay, 0, sizeof(reassoc_retry_delay)); - memset(bss_term_bit, 0, sizeof(bss_term_bit)); - memset(bss_term_tsf, 0, sizeof(bss_term_tsf)); - memset(bss_term_duration, 0, sizeof(bss_term_duration)); - - /* ControlApp on DUT */ - /* TLV: BSSID (required) */ - tlv = find_wrapper_tlv_by_id(req, TLV_BSSID); - if (tlv) { - memcpy(bssid, tlv->value, tlv->len); - } - /* DISASSOC_IMMINENT disassoc_imminent=%s */ - tlv = find_wrapper_tlv_by_id(req, TLV_DISASSOC_IMMINENT); - if (tlv) { - memcpy(disassoc_imminent, tlv->value, tlv->len); - } - /* DISASSOC_TIMER disassoc_timer=%s */ - tlv = find_wrapper_tlv_by_id(req, TLV_DISASSOC_TIMER); - if (tlv) { - memcpy(disassoc_timer, tlv->value, tlv->len); - } - /* REASSOCIAITION_RETRY_DELAY mbo=0:{}:0 */ - tlv = find_wrapper_tlv_by_id(req, TLV_REASSOCIAITION_RETRY_DELAY); - if (tlv) { - memcpy(reassoc_retry_delay, tlv->value, tlv->len); - } - /* CANDIDATE_LIST pref=1 */ - tlv = find_wrapper_tlv_by_id(req, TLV_CANDIDATE_LIST); - if (tlv) { - memcpy(candidate_list, tlv->value, tlv->len); - } - /* BSS_TERMINATION bss_term_bit */ - tlv = find_wrapper_tlv_by_id(req, TLV_BSS_TERMINATION); - if (tlv) { - memcpy(bss_term_bit, tlv->value, tlv->len); - } - /* BSS_TERMINATION_TSF bss_term_tsf */ - tlv = find_wrapper_tlv_by_id(req, TLV_BSS_TERMINATION_TSF); - if (tlv) { - memcpy(bss_term_tsf, tlv->value, tlv->len); - } - /* BSS_TERMINATION_DURATION bss_term_duration */ - tlv = find_wrapper_tlv_by_id(req, TLV_BSS_TERMINATION_DURATION); - if (tlv) { - memcpy(bss_term_duration, tlv->value, tlv->len); - } - - /* Assemble hostapd command for BSS_TM_REQ */ - memset(request, 0, sizeof(request)); - sprintf(request, "BSS_TM_REQ %s", bssid); - /* disassoc_imminent=%s */ - if (strlen(disassoc_imminent)) { - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, " disassoc_imminent=%s", disassoc_imminent); - strcat(request, buffer); - } - /* disassoc_timer=%s */ - if (strlen(disassoc_timer)) { - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, " disassoc_timer=%s", disassoc_timer); - strcat(request, buffer); - } - /* reassoc_retry_delay=%s */ - if (strlen(reassoc_retry_delay)) { - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, " mbo=0:%s:0", reassoc_retry_delay); - strcat(request, buffer); - } - /* if bss_term_bit && bss_term_tsf && bss_term_duration, then bss_term={bss_term_tsf},{bss_term_duration} */ - if (strlen(bss_term_bit) && strlen(bss_term_tsf) && strlen(bss_term_duration) ) { - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, " bss_term=%s,%s", bss_term_tsf, bss_term_duration); - strcat(request, buffer); - } - /* candidate_list */ - if (strlen(candidate_list) && atoi(candidate_list) == 1) { - memset(buffer, 0, sizeof(buffer)); - sprintf(buffer, " pref=1"); - strcat(request, buffer); - } - indigo_logger(LOG_LEVEL_DEBUG, "cmd:%s", request); - - /* 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_HOSTAPD_CTRL_NOT_OK; - goto done; - } - resp_len = sizeof(response) - 1; - wpa_ctrl_request(w, request, strlen(request), 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_HOSTAPD_RESP_NOT_OK; - 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; -} -#endif /* End Of CONFIG_WNM */ - static int trigger_ap_channel_switch(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_NOT_OK; size_t resp_len; @@ -1761,6 +1768,7 @@ static int trigger_ap_channel_switch(struct packet_wrapper *req, struct packet_w } return 0; } +#endif /* End Of CONFIG_AP */ static int get_ip_addr_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int status = TLV_VALUE_STATUS_NOT_OK; @@ -3352,6 +3360,7 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper } if (role == DUT_TYPE_APUT) { +#ifdef CONFIG_AP // TODO sprintf(buffer, "WPS_AP_PIN get"); w = wpa_ctrl_open(get_hapd_ctrl_path()); @@ -3360,6 +3369,7 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper status = TLV_VALUE_STATUS_NOT_OK; message = TLV_VALUE_WPA_S_CTRL_NOT_OK; goto done; +#endif /* End Of CONFIG_AP */ } #ifdef CONFIG_P2P } else if (role == DUT_TYPE_STAUT || role == DUT_TYPE_P2PUT) { @@ -3401,6 +3411,7 @@ static int get_wsc_pin_handler(struct packet_wrapper *req, struct packet_wrapper return 0; } +#ifdef CONFIG_AP 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]; @@ -3471,6 +3482,7 @@ static int start_wps_ap_handler(struct packet_wrapper *req, struct packet_wrappe } return 0; } +#endif /* End Of CONFIG_AP */ static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { struct wpa_ctrl *w = NULL; @@ -3563,6 +3575,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe } if (role == DUT_TYPE_APUT) { +#ifdef CONFIG_AP // APUT struct _cfg_cred cfg_creds[] = { {"ssid", "ssid=", {0}, TLV_WSC_SSID}, @@ -3586,6 +3599,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", wlan->hapd_conf_file); goto done; } +#endif /* End Of CONFIG_AP */ } else if (role == DUT_TYPE_STAUT) { // STAUT struct _cfg_cred cfg_creds[] = { diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 9b9ed0e..e2f4115 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -57,11 +57,13 @@ void register_apis() { #ifdef CONFIG_HS20 register_api(API_STA_SEND_ICON_REQ, NULL, send_sta_icon_req_handler); #endif /* End Of CONFIG_HS20 */ +#ifdef CONFIG_AP /* AP */ register_api(API_AP_START_UP, NULL, start_ap_handler); register_api(API_AP_STOP, NULL, stop_ap_handler); register_api(API_AP_CONFIGURE, NULL, configure_ap_handler); register_api(API_AP_SEND_ARP_MSGS, NULL, send_ap_arp_handler); +#endif /* End Of CONFIG_AP */ /* STA */ register_api(API_STA_ASSOCIATE, NULL, associate_sta_handler); register_api(API_STA_CONFIGURE, NULL, configure_sta_handler); @@ -120,6 +122,7 @@ void upload_wlan_hapd_conf(void *if_info) { } } +#ifdef CONFIG_AP // 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, id = 0; @@ -902,6 +905,7 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r return 0; } +#endif /* End Of CONFIG_AP */ // Bytes to DUT : 01 50 06 00 ed ff ff 00 55 0c 31 39 32 2e 31 36 38 2e 31 30 2e 33 // RESP :{: '0', : 'Static Ip successfully assigned to wireless interface'} @@ -2129,6 +2133,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe } if (role == DUT_TYPE_APUT) { +#ifdef CONFIG_AP // Test Platform: STA struct _cfg_cred cfg_creds[] = { {"ssid", "ssid=", {0}, TLV_WSC_SSID}, @@ -2142,6 +2147,7 @@ static int get_wsc_cred_handler(struct packet_wrapper *req, struct packet_wrappe indigo_logger(LOG_LEVEL_ERROR, "Fail to read file: %s", get_wpas_conf_file()); goto done; } +#endif /* End Of CONFIG_AP */ } else if (role == DUT_TYPE_STAUT) { // Test Platform: AP struct _cfg_cred cfg_creds[] = { diff --git a/vendor_specific.h b/vendor_specific.h index c9eec5c..0b8905b 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -167,9 +167,11 @@ int detect_third_radio(void); void create_sta_interface(); void delete_sta_interface(); +#ifdef CONFIG_AP 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); +#endif /* End Of CONFIG_AP */ #ifdef CONFIG_P2P int get_p2p_mac_addr(char *mac_addr, size_t size); diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 6d4e309..96d388d 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -184,6 +184,7 @@ void openwrt_apply_radio_config(void) { } #endif +#ifdef CONFIG_AP /* Called by configure_ap_handler() */ void configure_ap_enable_mbssid() { #ifdef _WTS_OPENWRT_ @@ -269,6 +270,7 @@ void start_ap_set_wlan_params(void *if_info) { (void) if_info; #endif } +#endif /* End Of CONFIG_AP*/ #ifdef CONFIG_P2P /* Return addr of P2P-device if there is no GO or client interface */ diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 7a738a1..3872cb2 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -259,6 +259,7 @@ void vendor_deinit() { system(buffer); } +#ifdef CONFIG_AP /* Called by configure_ap_handler() */ void configure_ap_enable_mbssid() { #ifdef _WTS_OPENWRT_ @@ -279,6 +280,7 @@ void configure_ap_enable_mbssid() { #endif #endif } +#endif /* End Of CONFIG_AP */ int set_channel_width() { int ret = -1; From a8a6973b46b7a721e5e0665fbad7fa93a8074648 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:49 +0530 Subject: [PATCH 18/20] Add WPS feature flag Protects WPS code in case the DUT doesn't support it yet. Signed-off-by: Triveni Danda --- Makefile | 2 +- indigo_api_callback.h | 9 +- indigo_api_callback_dut.c | 171 +++++++++++++++++++------------------- indigo_api_callback_tp.c | 10 ++- vendor_specific_dut.c | 2 + vendor_specific_tp.c | 2 + 6 files changed, 107 insertions(+), 89 deletions(-) diff --git a/Makefile b/Makefile index 64ac687..5b88353 100644 --- a/Makefile +++ b/Makefile @@ -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),) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 300d90d..3952722 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -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 */ @@ -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 */ @@ -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 */ diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index bd1c99f..20ef29a 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -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); @@ -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); @@ -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) { @@ -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; @@ -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) { @@ -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; -} diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index e2f4115..28b2a61 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -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() { @@ -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 */ @@ -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; @@ -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); @@ -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; @@ -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) { diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 96d388d..36e6114 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -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]; @@ -500,3 +501,4 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) return NULL; } +#endif /* End Of CONFIG_WPS */ diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index 3872cb2..b6614a3 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -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] = { { /* @@ -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_ */ From b62378902ef852844d4bca6e6969f2bef1a05dd9 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 19:34:51 +0530 Subject: [PATCH 19/20] Fix trailing whitespace Fix only for C files. Signed-off-by: Chaitanya Tata --- indigo_api.c | 2 +- indigo_api.h | 2 +- indigo_api_callback.h | 2 +- indigo_api_callback_dut.c | 62 +++++++++++++++++++-------------------- indigo_api_callback_tp.c | 40 ++++++++++++------------- indigo_packet.c | 4 +-- utils.h | 4 +-- vendor_specific.h | 2 +- vendor_specific_dut.c | 4 +-- vendor_specific_tp.c | 40 ++++++++++++------------- 10 files changed, 81 insertions(+), 81 deletions(-) diff --git a/indigo_api.c b/indigo_api.c index a3a0085..d445217 100644 --- a/indigo_api.c +++ b/indigo_api.c @@ -272,7 +272,7 @@ struct indigo_tlv indigo_tlv_list[] = { { TLV_CAPTURE_OUTFILE, "CAPTURE_OUTFILE" }, { TLV_TP_IP_ADDRESS, "TP_IP_ADDRESS" }, { TLV_WPS_ER_SUPPORT, "WPS_ER_SUPPORT" }, - { TLV_ADDITIONAL_TEST_PLATFORM_ID, "ADDITIONAL_TEST_PLATFORM_ID" }, + { TLV_ADDITIONAL_TEST_PLATFORM_ID, "ADDITIONAL_TEST_PLATFORM_ID" }, }; /* Find the type of the API stucture by the ID from the list */ diff --git a/indigo_api.h b/indigo_api.h index 59fe540..a9e2a9d 100644 --- a/indigo_api.h +++ b/indigo_api.h @@ -232,7 +232,7 @@ struct indigo_api { #define TLV_VENUE_TYPE 0x00ad #define TLV_HESSID 0x00ae #define TLV_OSU_SSID 0x00af -#define TLV_ANQP_3GPP_CELL_NETWORK_INFO 0x00b0 +#define TLV_ANQP_3GPP_CELL_NETWORK_INFO 0x00b0 #define TLV_PROXY_ARP 0x00b1 #define TLV_BSSLOAD_ENABLE 0x00b2 #define TLV_ROAMING_CONSORTIUM 0x00b3 diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 3952722..78046f7 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -132,7 +132,7 @@ struct tlv_to_config_name maps[] = { { TLV_STA_OWE_GROUP, "owe_group", 0 }, { TLV_BSSID, "bssid", 0 }, { TLV_REALM, "realm", 1 }, - { TLV_IMSI, "imsi", 1 }, + { TLV_IMSI, "imsi", 1 }, { TLV_MILENAGE, "milenage", 1 }, { TLV_BSSID_FILTER_LIST, "bssid_filter", 0 }, { TLV_USERNAME, "username", 1 }, diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index 20ef29a..6f7edae 100644 --- a/indigo_api_callback_dut.c +++ b/indigo_api_callback_dut.c @@ -216,7 +216,7 @@ static int reset_device_handler(struct packet_wrapper *req, struct packet_wrappe #ifdef CONFIG_AP -// RESP: {: '0', : 'AP stop completed : Hostapd service is inactive.'} +// 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; char buffer[S_BUFFER_LEN], reset_type[16]; @@ -273,7 +273,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_bytes(resp, TLV_MESSAGE, strlen(message), message); - + return 0; } @@ -331,7 +331,7 @@ 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 is_6g_only = 0, unsol_pr_resp_interval = 0; - struct tlv_to_profile *profile = NULL; + 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; @@ -368,7 +368,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ channel = atoi(value); if (is_multiple_bssid) { /* channel will be configured on the first wlan */ - continue; + continue; } } @@ -385,7 +385,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ continue; } - /* This is used when hostapd will use multiple lines to + /* 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); @@ -394,7 +394,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ 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); @@ -609,7 +609,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (NULL == wlan) { wlan = assign_wireless_interface_info(&bss_info); } - indigo_logger(LOG_LEVEL_DEBUG, "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 +654,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ strcat(output, "ieee80211w=2\n"); } else if (has_wpa) { strcat(output, "ieee80211w=1\n"); - } + } } if (has_sae == 1) { @@ -795,7 +795,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ return strlen(output); } -// RESP: {: '0', : 'DUT configured as AP : Configuration file created'} +// RESP: {: '0', : 'DUT configured as AP : Configuration file created'} static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len = 0; char buffer[L_BUFFER_LEN], ifname[S_BUFFER_LEN]; @@ -826,7 +826,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe band_transmitter[bss_info.band] = wlan; } } - indigo_logger(LOG_LEVEL_DEBUG, "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, @@ -854,7 +854,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe } } if (wlan) { - indigo_logger(LOG_LEVEL_DEBUG, "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" ); @@ -895,7 +895,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe #ifdef HOSTAPD_SUPPORT_MBSSID_WAR extern int use_openwrt_wpad; #endif -// RESP: {: '0', : 'AP is up : Hostapd service is active'} +// RESP: {: '0', : 'AP is up : Hostapd service is active'} static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { char *message = TLV_VALUE_HOSTAPD_START_OK; char buffer[S_BUFFER_LEN]; @@ -912,7 +912,7 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r 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_hostapd_debug_arguments(), get_all_hapd_conf_files(&swap_hostapd)); len = system(buffer); sleep(1); @@ -1286,7 +1286,7 @@ static int create_bridge_network_handler(struct packet_wrapper *req, struct pack } // Bytes to DUT : 01 50 06 00 ed ff ff 00 55 0c 31 39 32 2e 31 36 38 2e 31 30 2e 33 -// RESP :{: '0', : 'Static Ip successfully assigned to wireless interface'} +// RESP :{: '0', : 'Static Ip successfully assigned to wireless interface'} static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len = 0; char buffer[64]; @@ -1302,7 +1302,7 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr message = "Failed."; goto response; } - + if (is_bridge_created()) { ifname = get_wlans_bridge(); } else { @@ -1328,9 +1328,9 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr return 0; } -// Bytes to DUT : 01 50 01 00 ee ff ff -// 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'} +// Bytes to DUT : 01 50 01 00 ee ff ff +// 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) { struct tlv_hdr *tlv; struct wpa_ctrl *w = NULL; @@ -1391,7 +1391,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); - indigo_logger(LOG_LEVEL_DEBUG, "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 @@ -1535,7 +1535,7 @@ static int start_loopback_server(struct packet_wrapper *req, struct packet_wrapp 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__ +// #ifdef __TEST__ } else if (find_interface_ip(local_ip, sizeof(local_ip), "eth0")) { indigo_logger(LOG_LEVEL_DEBUG, "use %s", "eth0"); // #endif /* __TEST__ */ @@ -1557,7 +1557,7 @@ static int start_loopback_server(struct packet_wrapper *req, struct packet_wrapp return 0; } -// RESP: {: '0', : 'Loopback server in idle state'} +// RESP: {: '0', : 'Loopback server in idle state'} static int stop_loop_back_server_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { /* Stop loopback */ if (loopback_server_status()) { @@ -1760,7 +1760,7 @@ static int trigger_ap_channel_switch(struct packet_wrapper *req, struct packet_w goto done; } status = TLV_VALUE_STATUS_OK; - message = TLV_VALUE_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); @@ -1876,7 +1876,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r 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); - + return 0; } @@ -2044,7 +2044,7 @@ static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapp /* Start WPA supplicant */ memset(buffer, 0 ,sizeof(buffer)); - sprintf(buffer, "%s -B -t -c %s %s -i %s -f /var/log/supplicant.log", + 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(), @@ -2088,7 +2088,7 @@ static int send_sta_disconnect_handler(struct packet_wrapper *req, struct packet } status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_WPA_S_DISCONNECT_OK; - + done: fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); @@ -2126,7 +2126,7 @@ static int send_sta_reconnect_handler(struct packet_wrapper *req, struct packet_ } status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_WPA_S_RECONNECT_OK; - + done: fill_wrapper_message_hdr(resp, API_CMD_RESPONSE, req->hdr.seq); fill_wrapper_tlv_byte(resp, TLV_STATUS, status); @@ -2177,7 +2177,7 @@ static int set_sta_parameter_handler(struct packet_wrapper *req, struct packet_w goto done; } } - + status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; done: @@ -2240,7 +2240,7 @@ static int send_sta_btm_query_handler(struct packet_wrapper *req, struct packet_ } 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); @@ -3055,7 +3055,7 @@ static int sta_add_credential_handler(struct packet_wrapper *req, struct packet_ 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", + 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(), @@ -3094,7 +3094,7 @@ static int sta_add_credential_handler(struct packet_wrapper *req, struct packet_ /* 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 { @@ -3159,7 +3159,7 @@ static int set_sta_install_ppsmo_handler(struct packet_wrapper *req, struct pack 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); diff --git a/indigo_api_callback_tp.c b/indigo_api_callback_tp.c index 28b2a61..76fccbc 100644 --- a/indigo_api_callback_tp.c +++ b/indigo_api_callback_tp.c @@ -58,7 +58,7 @@ void register_apis() { #ifdef CONFIG_WPS register_api(API_GET_WSC_CRED, NULL, get_wsc_cred_handler); #endif /* End Of CONFIG_WPS */ -#ifdef CONFIG_HS20 +#ifdef CONFIG_HS20 register_api(API_STA_SEND_ICON_REQ, NULL, send_sta_icon_req_handler); #endif /* End Of CONFIG_HS20 */ #ifdef CONFIG_AP @@ -91,7 +91,7 @@ static int get_control_app_handler(struct packet_wrapper *req, struct packet_wra 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); - fill_wrapper_tlv_bytes(resp, TLV_TEST_PLATFORM_APP_VERSION, + fill_wrapper_tlv_bytes(resp, TLV_TEST_PLATFORM_APP_VERSION, strlen(buffer), buffer); return 0; } @@ -127,7 +127,7 @@ void upload_wlan_hapd_conf(void *if_info) { } #ifdef CONFIG_AP -// RESP: {: '0', : 'AP stop completed : Hostapd service is inactive.'} +// 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, id = 0; char buffer[S_BUFFER_LEN], reset_type[16], log_name[128]; @@ -248,7 +248,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, status); fill_wrapper_tlv_bytes(resp, TLV_MESSAGE, strlen(message), message); - + return 0; } @@ -364,7 +364,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ continue; } - /* This is used when hostapd will use multiple lines to + /* 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); @@ -373,7 +373,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ 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); @@ -576,7 +576,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ if (NULL == wlan) { wlan = assign_wireless_interface_info(&bss_info); } - indigo_logger(LOG_LEVEL_DEBUG, "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" @@ -710,7 +710,7 @@ static int generate_hostapd_config(char *output, int output_size, struct packet_ return strlen(output); } -// RESP: {: '0', : 'DUT configured as AP : Configuration file created'} +// RESP: {: '0', : 'DUT configured as AP : Configuration file created'} static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int band, len; char hw_mode_str[8], op_class[8]; @@ -741,7 +741,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe band_transmitter[bss_info.band] = wlan; } } - indigo_logger(LOG_LEVEL_DEBUG, "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, @@ -774,7 +774,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe } } if (wlan) { - indigo_logger(LOG_LEVEL_DEBUG, "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" ); @@ -819,7 +819,7 @@ static int configure_ap_handler(struct packet_wrapper *req, struct packet_wrappe return 0; } -// RESP: {: '0', : 'AP is up : Hostapd service is active'} +// RESP: {: '0', : 'AP is up : Hostapd service is active'} static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { char *message = TLV_VALUE_HOSTAPD_START_OK; char buffer[S_BUFFER_LEN], g_ctrl_iface[64], log_level[TLV_VALUE_SIZE]; @@ -913,7 +913,7 @@ static int start_ap_handler(struct packet_wrapper *req, struct packet_wrapper *r #endif /* End Of CONFIG_AP */ // Bytes to DUT : 01 50 06 00 ed ff ff 00 55 0c 31 39 32 2e 31 36 38 2e 31 30 2e 33 -// RESP :{: '0', : 'Static Ip successfully assigned to wireless interface'} +// RESP :{: '0', : 'Static Ip successfully assigned to wireless interface'} static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wrapper *resp) { int len = 0; char buffer[64]; @@ -959,9 +959,9 @@ static int assign_static_ip_handler(struct packet_wrapper *req, struct packet_wr return 0; } -// Bytes to DUT : 01 50 01 00 ee ff ff -// 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'} +// Bytes to DUT : 01 50 01 00 ee ff ff +// 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 mac_addr[S_BUFFER_LEN]; struct bss_identifier_info bss_info; @@ -991,7 +991,7 @@ static int get_mac_addr_handler(struct packet_wrapper *req, struct packet_wrappe indigo_logger(LOG_LEVEL_DEBUG, "Get mac_addr %s\n", mac_addr); status = TLV_VALUE_STATUS_OK; message = TLV_VALUE_OK; - } + } } else { /* TLV: TLV_ROLE */ memset(role, 0, sizeof(role)); @@ -1414,7 +1414,7 @@ static int stop_sta_handler(struct packet_wrapper *req, struct packet_wrapper *r 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); - + return 0; } @@ -1515,7 +1515,7 @@ static int generate_wpas_config(char *buffer, int buffer_size, struct packet_wra sprintf(cfg_item, "%s=%s\n", cfg->config_name, value); strcat(buffer, cfg_item); } - } + } } if (ieee80211w_configured == 0) { @@ -1605,7 +1605,7 @@ static int associate_sta_handler(struct packet_wrapper *req, struct packet_wrapp /* 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_full_exec_path(), get_wpas_conf_file(), get_wpas_debug_arguments(), get_wireless_interface(), @@ -1900,7 +1900,7 @@ static int set_sta_power_save_handler(struct packet_wrapper *req, struct packet_ memset(buffer, 0, sizeof(buffer)); sprintf(conf, "%s", !strcmp(param_value, "False") ? "off" : "on"); iface = get_wireless_interface(); - sprintf(buffer, "iw dev %s set power_save %s && iw dev %s get power_save", + sprintf(buffer, "iw dev %s set power_save %s && iw dev %s get power_save", iface, (char *)&conf, iface); indigo_logger(LOG_LEVEL_DEBUG, "cmd: %s", buffer); system(buffer); diff --git a/indigo_packet.c b/indigo_packet.c index cf98d27..1bfebe4 100644 --- a/indigo_packet.c +++ b/indigo_packet.c @@ -173,7 +173,7 @@ int gen_message_hdr(char *message, size_t message_len, struct message_hdr *hdr) message[len++] = (char) (hdr->seq & 0x00ff); message[len++] = hdr->reserved; message[len++] = hdr->reserved2; - + return sizeof(struct message_hdr); } @@ -243,7 +243,7 @@ int gen_tlv(char *packet, size_t packet_size, struct tlv_hdr *t) { packet[len++] = t->len; memcpy(&packet[len], t->value, t->len); len += t->len; - + return len; } diff --git a/utils.h b/utils.h index 9807670..51f933a 100644 --- a/utils.h +++ b/utils.h @@ -36,7 +36,7 @@ /* Log */ enum { - LOG_LEVEL_DEBUG_VERBOSE = 0, + LOG_LEVEL_DEBUG_VERBOSE = 0, LOG_LEVEL_DEBUG = 1, LOG_LEVEL_INFO = 2, LOG_LEVEL_NOTICE = 3, @@ -131,7 +131,7 @@ void indigo_logger(int level, const char *fmt, ...); 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); +int append_file(char *fn, char *buffer, int len); void open_tc_app_log(); void close_tc_app_log(); diff --git a/vendor_specific.h b/vendor_specific.h index 0b8905b..416f583 100644 --- a/vendor_specific.h +++ b/vendor_specific.h @@ -143,7 +143,7 @@ typedef struct _wps_setting { * struct sta_driver_ops - Driver interface API wrapper definition * * This structure defines the API that each driver interface needs to implement - * for indigo c control application. + * for indigo c control application. */ struct sta_driver_ops { const char *name; diff --git a/vendor_specific_dut.c b/vendor_specific_dut.c index 36e6114..adb3215 100644 --- a/vendor_specific_dut.c +++ b/vendor_specific_dut.c @@ -191,9 +191,9 @@ void configure_ap_enable_mbssid() { /* * 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"); diff --git a/vendor_specific_tp.c b/vendor_specific_tp.c index b6614a3..7229d1c 100644 --- a/vendor_specific_tp.c +++ b/vendor_specific_tp.c @@ -38,7 +38,7 @@ const char *desc_platform2 = "Qualcomm Device 1101"; static void check_platform1_default_conf(); /** - * Generic platform dependent API implementation + * Generic platform dependent API implementation */ /* support multiple STA platforms detection */ @@ -82,7 +82,7 @@ void detect_sta_vendor() { } else { /* set to platform 1 by default */ sta_drv_ops = &sta_driver_platform1_ops; - indigo_logger(LOG_LEVEL_INFO, + indigo_logger(LOG_LEVEL_INFO, "Unable to find any supported drivers, hook the default platform handlers"); } @@ -266,9 +266,9 @@ void configure_ap_enable_mbssid() { /* * 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"); @@ -303,7 +303,7 @@ void set_phy_mode() { } else { if (sta_drv_ops && sta_drv_ops->set_phy_mode != NULL) { sta_drv_ops->set_phy_mode(); - } + } } /* reset the flag for phymode */ @@ -311,7 +311,7 @@ void set_phy_mode() { } /** - * Platform-dependent implementation for STA platform 1 + * Platform-dependent implementation for STA platform 1 */ struct he_chwidth_config { @@ -368,7 +368,7 @@ static int set_he_channel_width(int chwidth) { char buffer[S_BUFFER_LEN]; f_ptr = fopen(path, "r"); - f_tmp_ptr = fopen(tmp_path, "w"); + f_tmp_ptr = fopen(tmp_path, "w"); if (f_ptr == NULL || f_tmp_ptr == NULL) { indigo_logger(LOG_LEVEL_ERROR, "Failed to open the files"); @@ -390,9 +390,9 @@ static int set_he_channel_width(int chwidth) { continue; } else { memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "%s%s", - he_ie_str, he_chwidth_config_list[chwidth].config); - indigo_logger(LOG_LEVEL_DEBUG, + snprintf(buffer, sizeof(buffer), "%s%s", + he_ie_str, he_chwidth_config_list[chwidth].config); + indigo_logger(LOG_LEVEL_DEBUG, "replace he_phy_cap setting[%d]:%s\n", chwidth, buffer); } } @@ -402,10 +402,10 @@ static int set_he_channel_width(int chwidth) { if (is_found == 0 && chwidth != CHWIDTH_AUTO) { memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "%s%s", + snprintf(buffer, sizeof(buffer), "%s%s", he_ie_str, he_chwidth_config_list[chwidth].config); - indigo_logger(LOG_LEVEL_DEBUG, - "set he_phy_cap setting:%s\n", buffer); + indigo_logger(LOG_LEVEL_DEBUG, + "set he_phy_cap setting:%s\n", buffer); fputs(buffer, f_tmp_ptr); } @@ -423,8 +423,8 @@ static int set_he_channel_width(int chwidth) { static int set_channel_width_platform1() { int ret = 0; - if ((sta_hw_config.phymode == PHYMODE_11AXA || - sta_hw_config.phymode == PHYMODE_11AXG || + if ((sta_hw_config.phymode == PHYMODE_11AXA || + sta_hw_config.phymode == PHYMODE_11AXG || sta_hw_config.phymode == PHYMODE_AUTO)) { ret = set_he_channel_width(sta_hw_config.chwidth); } else if ((sta_hw_config.chwidth == CHWIDTH_20 && @@ -444,7 +444,7 @@ static void set_phy_mode_platform1() { } else if (sta_hw_config.phymode == PHYMODE_11NA) { insert_wpa_network_config("disable_vht=1\n"); disable_11ax(); - } else if (sta_hw_config.phymode == PHYMODE_11AXG || + } else if (sta_hw_config.phymode == PHYMODE_11AXG || sta_hw_config.phymode == PHYMODE_11AXA || sta_hw_config.phymode == PHYMODE_AUTO) { reload_driver(); } @@ -457,8 +457,8 @@ static void set_phy_mode_platform1() { static int set_channel_width_platform2() { int ret = 0; - if ((sta_hw_config.phymode == PHYMODE_11AXA || - sta_hw_config.phymode == PHYMODE_11AXG || + if ((sta_hw_config.phymode == PHYMODE_11AXA || + sta_hw_config.phymode == PHYMODE_11AXG || sta_hw_config.phymode == PHYMODE_AUTO)) { /* HE channel width setting */ } else if ((sta_hw_config.chwidth == CHWIDTH_20 && @@ -476,7 +476,7 @@ static void set_phy_mode_platform2() { insert_wpa_network_config("disable_ht=1\n"); } else if (sta_hw_config.phymode == PHYMODE_11NA) { insert_wpa_network_config("disable_vht=1\n"); - } else if (sta_hw_config.phymode == PHYMODE_11AXG || + } else if (sta_hw_config.phymode == PHYMODE_11AXG || sta_hw_config.phymode == PHYMODE_11AXA || sta_hw_config.phymode == PHYMODE_AUTO) { /* reset to HE */ } @@ -485,7 +485,7 @@ static void set_phy_mode_platform2() { const struct sta_driver_ops sta_driver_platform1_ops = { .name = "platform1", .set_channel_width = set_channel_width_platform1, - .set_phy_mode = set_phy_mode_platform1, + .set_phy_mode = set_phy_mode_platform1, }; From 370fb8c3b9e4ce787ae3db4a0b4255d6ffaf4c6f Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Aug 2023 20:06:09 +0530 Subject: [PATCH 20/20] Fix build errors for DUT These functions are only applicable for the test platform, so, include them only for it to avoid build errors. Signed-off-by: Chaitanya Tata --- indigo_api_callback.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/indigo_api_callback.h b/indigo_api_callback.h index 78046f7..498ec37 100644 --- a/indigo_api_callback.h +++ b/indigo_api_callback.h @@ -253,7 +253,9 @@ 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); +#ifdef _TEST_PLATFORM_ static int send_ap_arp_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +#endif /* End Of _TEST_PLATFORM_ */ #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); @@ -276,7 +278,9 @@ static int send_sta_anqp_query_handler(struct packet_wrapper *req, struct packet 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); +#ifdef _TEST_PLATFORM_ static int send_sta_icon_req_handler(struct packet_wrapper *req, struct packet_wrapper *resp); +#endif /* End Of _TEST_PLATFORM_ */ #endif /* End Of CONFIG_HS20 */ #ifdef CONFIG_WPS static int start_wps_sta_handler(struct packet_wrapper *req, struct packet_wrapper *resp);