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 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/hs2_profile.h b/hs2_profile.h index d24d217..b3f7b0d 100644 --- a/hs2_profile.h +++ b/hs2_profile.h @@ -1,4 +1,3 @@ - /* Copyright (c) 2021 Wi-Fi Alliance */ /* Permission to use, copy, modify, and/or distribute this software for any */ @@ -180,7 +179,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,11 +189,11 @@ 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]); } return; } -#endif // _HS2_PROFILE \ No newline at end of file +#endif // _HS2_PROFILE 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..0b9b480 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]; @@ -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); diff --git a/indigo_api_callback_dut.c b/indigo_api_callback_dut.c index b3eda4e..e67f666 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]; @@ -301,7 +301,11 @@ 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_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]; char band[64], value[16]; @@ -314,6 +318,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); @@ -550,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_ @@ -874,7 +882,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_ @@ -1095,7 +1102,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; @@ -1354,7 +1360,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; @@ -1766,7 +1771,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); @@ -1864,15 +1868,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) { - int 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); @@ -1960,14 +1964,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)); @@ -1987,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 @@ -2007,13 +2009,12 @@ 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; 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); @@ -2024,7 +2025,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 = TLV_VALUE_STATUS_NOT_OK; size_t resp_len; /* Open WPA supplicant UDS socket */ @@ -2062,7 +2063,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 */ @@ -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]; @@ -2368,7 +2369,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); @@ -2647,13 +2647,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 +2777,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; @@ -2904,7 +2904,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; @@ -2998,7 +2998,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; @@ -3150,7 +3150,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]; @@ -3266,7 +3265,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); @@ -3279,7 +3277,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; @@ -3295,7 +3293,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)); @@ -3423,7 +3421,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; @@ -3708,8 +3706,9 @@ 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]; - int i, len = 0, status = TLV_VALUE_STATUS_NOT_OK; + 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; @@ -3779,7 +3778,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/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..bdb8fee 100755 --- a/main.c +++ b/main.c @@ -86,10 +86,13 @@ 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 + (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 d152fb4..2804208 100644 --- a/utils.c +++ b/utils.c @@ -18,7 +18,9 @@ #include #include #include +#ifdef _SYSLOG_ #include +#endif #include #include #include @@ -36,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; @@ -54,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]; @@ -91,7 +94,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 +144,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 +168,7 @@ void indigo_logger(int level, const char *fmt, ...) { vsyslog(priority, format, ap); va_end(ap); } +#endif } void open_tc_app_log() { @@ -291,10 +298,13 @@ 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; + + (void)eloop_ctx; + (void)sock_ctx; 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 ; @@ -309,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; @@ -483,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 { @@ -509,7 +525,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; @@ -563,7 +580,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", @@ -572,7 +589,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++) { @@ -606,8 +623,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; @@ -654,7 +673,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); @@ -663,7 +682,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++) { @@ -740,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) { @@ -759,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; } @@ -958,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++; @@ -968,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]; } } @@ -1050,7 +1076,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; } @@ -1174,6 +1200,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; @@ -1183,7 +1212,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++) { @@ -1430,11 +1459,13 @@ 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) { 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 @@ -1443,7 +1474,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 @@ -1713,10 +1744,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; } @@ -1725,11 +1758,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; } @@ -1749,6 +1784,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..f1701ca 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}; @@ -481,4 +493,6 @@ wps_setting* get_vendor_wps_settings(enum wps_device_role role) return NULL; } } + + return 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); }