From 11ec28c164a0f92b3b9a42cd98a3fcb1b8c8b606 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Wed, 9 Dec 2015 14:26:28 +0900 Subject: [PATCH] Apply coding rule Change-Id: I47a6586a8e9538681b240040a4da7e7f49747caf Signed-off-by: hyunuktak --- packaging/capi-network-wifi-direct.spec | 2 +- src/wifi-direct-client-proxy.c | 116 ++- test/test-wifi-direct.c | 1308 +++++++++++++------------------ 3 files changed, 621 insertions(+), 805 deletions(-) mode change 100644 => 100755 test/test-wifi-direct.c diff --git a/packaging/capi-network-wifi-direct.spec b/packaging/capi-network-wifi-direct.spec index ec82b95..3fba812 100644 --- a/packaging/capi-network-wifi-direct.spec +++ b/packaging/capi-network-wifi-direct.spec @@ -1,6 +1,6 @@ Name: capi-network-wifi-direct Summary: Network WiFi-Direct Library -Version: 1.2.40 +Version: 1.2.41 Release: 1 Group: Network & Connectivity/Wireless License: Apache-2.0 diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c index 0149330..0417e1b 100755 --- a/src/wifi-direct-client-proxy.c +++ b/src/wifi-direct-client-proxy.c @@ -21,7 +21,7 @@ /***************************************************************************** - * Standard headers + * Standard headers *****************************************************************************/ #define _GNU_SOURCE #include @@ -45,13 +45,13 @@ #include /***************************************************************************** - * System headers + * System headers *****************************************************************************/ #include #include /***************************************************************************** - * Wi-Fi Direct Service headers + * Wi-Fi Direct Service headers *****************************************************************************/ #include "wifi-direct.h" #include "wifi-direct-internal.h" @@ -59,11 +59,11 @@ #include "wifi-direct-ipc.h" /***************************************************************************** - * Macros and Typedefs + * Macros and Typedefs *****************************************************************************/ /***************************************************************************** - * Global Variables + * Global Variables *****************************************************************************/ wifi_direct_client_info_s g_client_info = { .is_registered = FALSE, @@ -90,7 +90,7 @@ wifi_direct_client_info_s g_client_info = { }; /***************************************************************************** - * Local Functions Definition + * Local Functions Definition *****************************************************************************/ #ifdef __NR_gettid @@ -114,7 +114,7 @@ static void __wfd_reset_control() g_source_remove(g_client_info.g_source_id); g_client_info.g_source_id = -1; - // Protect standard input / output / error + /* Protect standard input / output / error */ if (g_client_info.sync_sockfd > 0) close(g_client_info.sync_sockfd); g_client_info.sync_sockfd = -1; @@ -125,7 +125,7 @@ static void __wfd_reset_control() g_client_info.is_registered = FALSE; - // Initialize callbacks + /* Initialize callbacks */ g_client_info.activation_cb = NULL; g_client_info.discover_cb = NULL; g_client_info.connection_cb = NULL; @@ -140,7 +140,7 @@ static void __wfd_reset_control() #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY g_client_info.service_cb = NULL; - g_client_info.user_data_for_cb_service= NULL; + g_client_info.user_data_for_cb_service = NULL; #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ @@ -162,8 +162,7 @@ static int macaddr_atoe(char *p, unsigned char mac[]) static char *__wfd_print_event(wfd_client_event_e event) { - switch (event) - { + switch (event) { case WIFI_DIRECT_CLI_EVENT_INVALID: return "WIFI_DIRECT_CLI_EVENT_INVALID"; break; @@ -241,8 +240,7 @@ static char *__wfd_print_event(wfd_client_event_e event) static char *__wfd_print_error(wifi_direct_error_e error) { - switch (error) - { + switch (error) { case WIFI_DIRECT_ERROR_NONE: return "WIFI_DIRECT_ERROR_NONE"; case WIFI_DIRECT_ERROR_NOT_PERMITTED: @@ -283,8 +281,7 @@ static int __wfd_convert_client_event(wfd_client_event_e event) { __WDC_LOG_FUNC_START__; - switch (event) - { + switch (event) { case WIFI_DIRECT_CLI_EVENT_ACTIVATION: return WIFI_DIRECT_DEVICE_STATE_ACTIVATED; break; @@ -357,8 +354,7 @@ static int __wfd_convert_client_event(wfd_client_event_e event) char *__wfd_client_print_cmd(wifi_direct_cmd_e cmd) { - switch (cmd) - { + switch (cmd) { case WIFI_DIRECT_CMD_REGISTER: return "WIFI_DIRECT_CMD_REGISTER"; case WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET: @@ -534,7 +530,7 @@ static int __wfd_client_check_socket(int sock, int timeout) WDC_LOGE("Polling error from socket[%d]. [%s]", sock, strerror(errno)); return -1; } else if (res == 0) { - WDC_LOGD( "poll timeout. socket is busy"); + WDC_LOGD("poll timeout. socket is busy"); return 1; } else { if (p_fd.revents & POLLERR) { @@ -607,7 +603,7 @@ static int __wfd_client_read_socket(int sockfd, char *data, int data_len) return WIFI_DIRECT_ERROR_RESOURCE_BUSY; } - while(data_len) { + while (data_len) { rbytes = read(sockfd, data, data_len); if (rbytes <= 0) { WDC_LOGE("Failed to read socket[%d] [%s]", sockfd, strerror(errno)); @@ -688,7 +684,7 @@ static gboolean __wfd_client_process_event(GIOChannel *source, memset(&client_noti, 0, sizeof(wifi_direct_client_noti_s)); - // 1.Read socket + /* 1.Read socket */ res = __wfd_client_read_socket(sockfd, (char*) &client_noti, sizeof(wifi_direct_client_noti_s)); if (res <= 0) { @@ -697,7 +693,7 @@ static gboolean __wfd_client_process_event(GIOChannel *source, __WDC_LOG_FUNC_END__; return false; } - WDC_LOGD( "Received Event is [%d,%s], error[%d]", client_noti.event, + WDC_LOGD("Received Event is [%d,%s], error[%d]", client_noti.event, __wfd_print_event(client_noti.event), client_noti.error); event = client_noti.event; @@ -709,7 +705,7 @@ static gboolean __wfd_client_process_event(GIOChannel *source, memcpy(param2, client_noti.param2, sizeof(client_noti.param2)); - // 2. dispatch event + /* 2. dispatch event */ switch (event) { case WIFI_DIRECT_CLI_EVENT_ACTIVATION: case WIFI_DIRECT_CLI_EVENT_DEACTIVATION: @@ -758,7 +754,7 @@ static gboolean __wfd_client_process_event(GIOChannel *source, param1, client->user_data_for_cb_connection); break; - // ToDo: Handling IP lease event... + /* ToDo: Handling IP lease event... */ case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND: if (!client->ip_assigned_cb) { WDC_LOGE("ip_assigned_cb is NULL!!"); @@ -804,8 +800,7 @@ void __wfd_client_print_entry_list(wfd_discovery_entry_s *list, int num) int i = 0; WDC_LOGD("------------------------------------------"); - for (i = 0; i < num; i++) - { + for (i = 0; i < num; i++) { WDC_LOGD("== Peer index : %d ==", i); WDC_LOGD("is Group Owner ? %s", list[i].is_group_owner ? "YES" : "NO"); WDC_LOGD("device_name : %s", list[i].device_name); @@ -900,12 +895,12 @@ static int __wfd_client_launch_server_dbus(void) GDBusConnection *netconfig_bus = NULL; GError *g_error = NULL; -#if !GLIB_CHECK_VERSION(2,36,0) +#if !GLIB_CHECK_VERSION(2, 36, 0) g_type_init(); #endif netconfig_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_error); if (netconfig_bus == NULL) { - if(g_error != NULL) { + if (g_error != NULL) { WDC_LOGE("Couldn't connect to system bus " "error [%d: %s]", g_error->code, g_error->message); g_error_free(g_error); @@ -925,7 +920,7 @@ static int __wfd_client_launch_server_dbus(void) NULL, &g_error); - if(g_error !=NULL) { + if (g_error != NULL) { WDC_LOGE("g_dbus_connection_call_sync() failed" "error [%d: %s]", g_error->code, g_error->message); g_error_free(g_error); @@ -963,7 +958,7 @@ int wifi_direct_initialize(void) __WDC_LOG_FUNC_END__; return res; } - if(!wifi_direct_enable) { + if (!wifi_direct_enable) { WDC_LOGE("Wi-Fi Direct not supported"); return WIFI_DIRECT_ERROR_NOT_SUPPORTED; } @@ -981,7 +976,7 @@ int wifi_direct_initialize(void) WDC_LOGD("Connecting to server socket to register sync socket [%d]", sockfd); while (retry_count > 0) { res = connect(sockfd, (struct sockaddr*) &saddr, sizeof(saddr)); - if (!res){ + if (!res) { WDC_LOGD("Succeeded to connect to server socket[%s]", strerror(errno)); break; } @@ -1039,7 +1034,7 @@ int wifi_direct_initialize(void) g_client_info.g_source_id = g_source_id; - // Initialize callbacks + /* Initialize callbacks */ g_client_info.activation_cb = NULL; g_client_info.discover_cb = NULL; g_client_info.connection_cb = NULL; @@ -1055,7 +1050,7 @@ int wifi_direct_initialize(void) #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY g_client_info.service_cb = NULL; - g_client_info.user_data_for_cb_service= NULL; + g_client_info.user_data_for_cb_service = NULL; #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ __WDC_LOG_FUNC_END__; @@ -1608,10 +1603,10 @@ static char **get_service_list(char *services, unsigned int *count) pos1 = services; pos2 = g_strdup(services); - pos1 = strtok (pos1,",\n"); + pos1 = strtok(pos1, ",\n"); while (pos1) { cnt++; - pos1 = strtok (NULL, ",\n"); + pos1 = strtok(NULL, ",\n"); } WDC_LOGD("Total Service Count = %d", cnt); @@ -1622,13 +1617,13 @@ static char **get_service_list(char *services, unsigned int *count) g_free(pos2); return NULL; } - pos2 = strtok (pos2,",\n"); + pos2 = strtok(pos2, ",\n"); while (pos2 != NULL) { char *s = strchr(pos2, ' '); if (s) { *s = '\0'; result[i++] = strdup(pos2); - pos2 = strtok (NULL, ",\n"); + pos2 = strtok(NULL, ",\n"); } } } @@ -1642,7 +1637,7 @@ static char **get_service_list(char *services, unsigned int *count) } else { *count = 0; if (result) { - for (j=0; j 0) { - buff = (wfd_discovery_entry_s*) g_try_malloc0_n(num, sizeof (wfd_discovery_entry_s)); + buff = (wfd_discovery_entry_s*) g_try_malloc0_n(num, sizeof(wfd_discovery_entry_s)); if (!buff) { WDC_LOGE("Failed to alloc memory"); pthread_mutex_unlock(&g_client_info.mutex); @@ -1742,7 +1737,7 @@ int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb, num * sizeof(wfd_discovery_entry_s)); if (num_tmp) { WDC_LOGD("Rest data should be read out"); - buff_tmp = (wfd_discovery_entry_s*) g_try_malloc0_n(num_tmp, sizeof (wfd_discovery_entry_s)); + buff_tmp = (wfd_discovery_entry_s*) g_try_malloc0_n(num_tmp, sizeof(wfd_discovery_entry_s)); if (buff_tmp) { __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff_tmp, num_tmp * sizeof(wfd_discovery_entry_s)); @@ -1775,7 +1770,7 @@ int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb, peer_list->is_persistent_group_owner = buff[i].is_persistent_go; peer_list->primary_device_type = buff[i].category; peer_list->secondary_device_type = buff[i].subcategory; - peer_list->supported_wps_types= buff[i].wps_cfg_methods; + peer_list->supported_wps_types = buff[i].wps_cfg_methods; #ifdef TIZEN_FEATURE_WIFI_DISPLAY peer_list->is_miracast_device = buff[i].is_wfd_device; #endif /* TIZEN_FEATURE_WIFI_DISPLAY */ @@ -1847,8 +1842,7 @@ int wifi_direct_cancel_connection(char *mac_address) int res = WIFI_DIRECT_ERROR_NONE; if ((g_client_info.is_registered == false) - || (g_client_info.client_id == WFD_INVALID_ID)) - { + || (g_client_info.client_id == WFD_INVALID_ID)) { WDC_LOGE("Client is NOT registered."); __WDC_LOG_FUNC_END__; return WIFI_DIRECT_ERROR_NOT_INITIALIZED; @@ -2125,7 +2119,7 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb, return WIFI_DIRECT_ERROR_OPERATION_FAILED; } - res= __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, num * sizeof(wfd_connected_peer_info_s)); pthread_mutex_unlock(&g_client_info.mutex); } else if (num < 1) { @@ -2139,7 +2133,7 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb, return WIFI_DIRECT_ERROR_OPERATION_FAILED; } - res= __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, num * sizeof(wfd_connected_peer_info_s)); pthread_mutex_unlock(&g_client_info.mutex); if (res <= 0) { @@ -2157,11 +2151,11 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb, for (i = 0; i < num; i++) { peer_list = (wifi_direct_connected_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_connected_peer_info_s)); peer_list->device_name = g_strdup(buff[i].device_name); - peer_list->ip_address= (char*) g_try_malloc0(IPSTR_LEN); + peer_list->ip_address = (char*) g_try_malloc0(IPSTR_LEN); g_snprintf(peer_list->ip_address, IPSTR_LEN, IPSTR, IP2STR(buff[i].ip_address)); peer_list->mac_address = (char*) calloc(1, MACSTR_LEN); g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address)); - peer_list->interface_address = (char*) g_try_malloc0( MACSTR_LEN); + peer_list->interface_address = (char*) g_try_malloc0(MACSTR_LEN); g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].intf_address)); peer_list->p2p_supported = buff[i].is_p2p; peer_list->primary_device_type = buff[i].category; @@ -3035,7 +3029,7 @@ int wifi_direct_set_device_name(const char *device_name) __WDC_LOG_FUNC_END__; return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; } - WDC_LOGD( "writing msg hdr is success!\n"); + WDC_LOGD("writing msg hdr is success!\n"); status = __wfd_client_write_socket(g_client_info.sync_sockfd, (void*) device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN); @@ -3107,11 +3101,11 @@ int wifi_direct_get_network_interface_name(char **name) get_str = vconf_get_str(VCONFKEY_IFNAME); if (!get_str) { - WDC_LOGD( "vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME); + WDC_LOGD("vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME); __WDC_LOG_FUNC_END__; return WIFI_DIRECT_ERROR_NOT_PERMITTED; } - WDC_LOGD( "VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, get_str); + WDC_LOGD("VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, get_str); *name = g_strdup(get_str); g_free(get_str); @@ -3185,7 +3179,7 @@ int wifi_direct_get_subnet_mask(char **subnet_mask) result = wifi_direct_get_state(&status); WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]", status, result); - if( status < WIFI_DIRECT_STATE_CONNECTED) { + if (status < WIFI_DIRECT_STATE_CONNECTED) { WDC_LOGE("Device is not connected!"); __WDC_LOG_FUNC_END__; return WIFI_DIRECT_ERROR_NOT_PERMITTED; @@ -3230,7 +3224,7 @@ int wifi_direct_get_gateway_address(char **gateway_address) result = wifi_direct_get_state(&status); WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]", status, result); - if(status < WIFI_DIRECT_STATE_CONNECTED) { + if (status < WIFI_DIRECT_STATE_CONNECTED) { WDC_LOGE("Device is not connected!"); __WDC_LOG_FUNC_END__; return WIFI_DIRECT_ERROR_NOT_PERMITTED; @@ -3330,7 +3324,7 @@ int wifi_direct_get_state(wifi_direct_state_e *state) *state = (wifi_direct_state_e) rsp.param1; /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */ - if(*state == WIFI_DIRECT_STATE_GROUP_OWNER) + if (*state == WIFI_DIRECT_STATE_GROUP_OWNER) *state = WIFI_DIRECT_STATE_CONNECTED; __WDC_LOG_FUNC_END__; @@ -3476,7 +3470,7 @@ int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* t *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV; #else /* TIZEN_TV */ WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL); - *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL; // smart phone dual mode (wifi and cellular) + *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL; /* smart phone dual mode (wifi and cellular) */ #endif /* TIZEN_TV */ __WDC_LOG_FUNC_END__; @@ -3730,7 +3724,7 @@ int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb cb, num * sizeof(wfd_persistent_group_info_s)); if (num_tmp) { WDC_LOGD("Rest data should be read out"); - buff_tmp = (wfd_persistent_group_info_s*) calloc(num_tmp, sizeof (wfd_persistent_group_info_s)); + buff_tmp = (wfd_persistent_group_info_s*) calloc(num_tmp, sizeof(wfd_persistent_group_info_s)); if (buff_tmp) { __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff_tmp, num_tmp * sizeof(wfd_persistent_group_info_s)); @@ -3738,7 +3732,7 @@ int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb cb, } } pthread_mutex_unlock(&g_client_info.mutex); - if (res <= 0){ + if (res <= 0) { free(buff); WDC_LOGE("socket read error."); __wfd_reset_control(); @@ -3849,7 +3843,7 @@ int wifi_direct_remove_persistent_group(char *mac_address, const char *ssid) return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; } - if (rsp.cmd !=req.cmd) { + if (rsp.cmd != req.cmd) { WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd); return WIFI_DIRECT_ERROR_OPERATION_FAILED; } @@ -4042,7 +4036,7 @@ int wifi_direct_register_service(wifi_direct_service_type_e type, char *info1, c len = strlen(info1) + strlen(info2) + 2; WDC_LOGD("info [%s|%s], len [%d]", info1, info2, len); - buf= g_try_malloc0(sizeof(wifi_direct_client_request_s) + len); + buf = g_try_malloc0(sizeof(wifi_direct_client_request_s) + len); if (NULL == buf) { WDC_LOGE("Failed to allocate memory for buf"); return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; @@ -4244,7 +4238,7 @@ int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discovered_peer_inf wfd_discovery_entry_s *buff = NULL; - buff = (wfd_discovery_entry_s*) g_try_malloc0(sizeof (wfd_discovery_entry_s)); + buff = (wfd_discovery_entry_s*) g_try_malloc0(sizeof(wfd_discovery_entry_s)); if (!buff) { WDC_LOGE("Failed to alloc memory"); pthread_mutex_unlock(&g_client_info.mutex); @@ -4283,7 +4277,7 @@ int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discovered_peer_inf peer->is_persistent_group_owner = buff->is_persistent_go; peer->primary_device_type = buff->category; peer->secondary_device_type = buff->subcategory; - peer->supported_wps_types= buff->wps_cfg_methods; + peer->supported_wps_types = buff->wps_cfg_methods; #ifdef TIZEN_FEATURE_WIFI_DISPLAY peer->is_miracast_device = buff->is_wfd_device; #endif /* TIZEN_FEATURE_WIFI_DISPLAY */ @@ -4336,7 +4330,7 @@ int wifi_direct_set_passphrase(const char *passphrase) __WDC_LOG_FUNC_END__; return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; } - WDC_LOGD( "writing msg hdr is success!\n"); + WDC_LOGD("writing msg hdr is success!\n"); status = __wfd_client_write_socket(g_client_info.sync_sockfd, (void*) passphrase, req.cmd_data_len); @@ -4393,7 +4387,7 @@ int wifi_direct_get_passphrase(char** passphrase) return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } - if(!passphrase){ + if (!passphrase) { WDC_LOGE("NULL Param [passphrase]!"); __WDC_LOG_FUNC_END__; return WIFI_DIRECT_ERROR_INVALID_PARAMETER; diff --git a/test/test-wifi-direct.c b/test/test-wifi-direct.c old mode 100644 new mode 100755 index 0a63288..9d43801 --- a/test/test-wifi-direct.c +++ b/test/test-wifi-direct.c @@ -11,7 +11,7 @@ #include -// For wifi-direct package internal use only +/* For wifi-direct package internal use only */ #include #define RESET_COLOR "\e[m" @@ -67,8 +67,7 @@ static const char *test_wfd_convert_error_to_string(wifi_direct_error_e err_type return "UNKNOWN"; } -enum -{ +enum { CMD_QUIT, CMD_FULL_MENU, CMD_INITIALIZE, @@ -79,7 +78,7 @@ enum CMD_START_DISCOVER_SPECIFIC_CHANNEL, CMD_CANCEL_DISCOVER, CMD_GET_DISVOCERY_RESULT, - //CMD_SEND_PROVISION_DISCOVER_REQ, + /* CMD_SEND_PROVISION_DISCOVER_REQ, */ CMD_SEND_CONNECTION_REQ, CMD_GET_LINK_STATUS, CMD_CONNECT_PEER, @@ -108,10 +107,10 @@ enum CMD_IS_PERSISTENT_GROUP_ACTIVATED, CMD_GET_PERSISTENT_GROUP_LIST, CMD_REMOVE_PERSISTENT_GROUP, - //CMD_SET_GROUP_OWNER, + /* CMD_SET_GROUP_OWNER, */ CMD_SET_AUTO_CONNECTION, CMD_IS_AUTO_CONNECTION, - //CMD_SET_LISTEN_ONLY, + /* CMD_SET_LISTEN_ONLY, */ CMD_SET_WPS_PIN, CMD_GET_WPS_PIN, CMD_GET_SUPPORTED_WPS_MODE, @@ -170,14 +169,12 @@ enum CMD_INVALID = 255, }; -typedef struct -{ +typedef struct { int cmd; char* menu_str; } menu_str_t; -menu_str_t g_menu_str[] = -{ +menu_str_t g_menu_str[] = { { CMD_QUIT, "CMD_QUIT" }, { CMD_FULL_MENU, "CMD_FULL_MENU" }, { CMD_INITIALIZE, "CMD_INITIALIZE" }, @@ -188,7 +185,7 @@ menu_str_t g_menu_str[] = { CMD_START_DISCOVER_SPECIFIC_CHANNEL, "CMD_START_DISCOVER_SPECIFIC_CHANNEL" }, { CMD_CANCEL_DISCOVER, "CMD_CANCEL_DISCOVER" }, { CMD_GET_DISVOCERY_RESULT, "CMD_GET_DISVOCERY_RESULT" }, - //{ CMD_SEND_PROVISION_DISCOVER_REQ, "CMD_SEND_PROVISION_DISCOVER_REQ" }, + /* { CMD_SEND_PROVISION_DISCOVER_REQ, "CMD_SEND_PROVISION_DISCOVER_REQ" }, */ { CMD_SEND_CONNECTION_REQ, "CMD_SEND_CONNECTION_REQ" }, { CMD_GET_LINK_STATUS, "CMD_GET_LINK_STATUS" }, @@ -219,10 +216,10 @@ menu_str_t g_menu_str[] = { CMD_IS_PERSISTENT_GROUP_ACTIVATED, "CMD_IS_PERSISTENT_GROUP_ACTIVATED" }, { CMD_GET_PERSISTENT_GROUP_LIST, "CMD_GET_PERSISTENT_GROUP_LIST" }, { CMD_REMOVE_PERSISTENT_GROUP, "CMD_REMOVE_PERSISTENT_GROUP" }, - //{ CMD_SET_GROUP_OWNER, "CMD_SET_GROUP_OWNER" }, + /* { CMD_SET_GROUP_OWNER, "CMD_SET_GROUP_OWNER" }, */ { CMD_SET_AUTO_CONNECTION, "CMD_SET_AUTO_CONNECTION" }, { CMD_IS_AUTO_CONNECTION, "CMD_IS_AUTO_CONNECTION" }, - //{ CMD_SET_LISTEN_ONLY, "CMD_SET_LISTEN_ONLY" }, + /* { CMD_SET_LISTEN_ONLY, "CMD_SET_LISTEN_ONLY" }, */ { CMD_SET_WPS_PIN, "CMD_SET_WPS_PIN" }, { CMD_GET_WPS_PIN, "CMD_GET_WPS_PIN" }, { CMD_GET_SUPPORTED_WPS_MODE, "CMD_GET_SUPPORTED_WPS_MODE" }, @@ -253,8 +250,8 @@ menu_str_t g_menu_str[] = { CMD_GET_IP_ADDR, "CMD_GET_IP_ADDR" }, { CMD_REGISTER_SERVICE, "CMD_REGISTER_SERVICE" }, { CMD_DEREGISTER_SERVICE, "CMD_DEREGISTER_SERVICE" }, - { CMD_START_SERVICE_DISCOVERY,"CMD_START_SERVICE_DISCOVERY" }, - { CMD_CANCEL_SERVICE_DISCOVERY,"CMD_CANCEL_SERVICE_DISCOVERY" }, + { CMD_START_SERVICE_DISCOVERY, "CMD_START_SERVICE_DISCOVERY" }, + { CMD_CANCEL_SERVICE_DISCOVERY, "CMD_CANCEL_SERVICE_DISCOVERY" }, { CMD_INCREASE_OEM_LOGLEVEL, "CMD_INCREASE_OEM_LOGLEVEL" }, { CMD_DECREASE_OEM_LOGLEVEL, "CMD_DECREASE_OEM_LOGLEVEL" }, @@ -278,8 +275,7 @@ menu_str_t g_menu_str[] = { -1, NULL }, }; -struct appdata -{ +struct appdata { GMainLoop* main_loop; wifi_direct_discovered_peer_info_s peer_list[MAX_PEER_NUM]; @@ -314,11 +310,9 @@ static int get_param(int argc, char **argv, struct appdata *ad) { printf("Parsing argument...\n"); int opt; - while ((opt = getopt(argc, argv, "t:u:p:a:")) != -1) - { + while ((opt = getopt(argc, argv, "t:u:p:a:")) != -1) { printf("Parsing argument...:%c\n", opt); - switch (opt) - { + switch (opt) { case 't': default: prt_help(argv[0]); @@ -352,19 +346,16 @@ cmd_transform(char*str) if (len == 0) return ""; - // remove "CMD_" - // lower char - // replance "_" to space - for (i = 0, j = 4; i < len; i++, j++) - { + /* remove "CMD_" */ + /* lower char */ + /* replance "_" to space */ + for (i = 0, j = 4; i < len; i++, j++) { if (str[j] >= 'A' && str[j] <= 'Z') static_buffer[i] = str[j] + 'a' - 'A'; else if (str[j] == '_') static_buffer[i] = ' '; else - { static_buffer[i] = str[j]; - } } static_buffer[j] = '\0'; @@ -376,9 +367,8 @@ void usage_full() int i; printf("Call Test Program\n"); - for (i = 0; g_menu_str[i].cmd != -1; i++) - { - if(i%4 == 0) + for (i = 0; g_menu_str[i].cmd != -1; i++) { + if (i % 4 == 0) printf("\n"); printf(" %02d: %-32s ", g_menu_str[i].cmd, cmd_transform(g_menu_str[i].menu_str)); @@ -399,8 +389,7 @@ int is_digit(const char* str) return -1; len = strlen(str); - for (i = 0; i < len; i++) - { + for (i = 0; i < len; i++) { if (str[i] < '0' || str[i] > '9') return -2; } @@ -436,14 +425,13 @@ int select_peer(struct appdata* ad) int target = -1; int i; - if (ad==NULL) + if (ad == NULL) return 0; list = ad->peer_list; - for(i=0; ipeer_count; i++) - { - printf ("index [%d] MAC [%s] Owner=[%s] SSID[%s]\n", + for (i = 0; i < ad->peer_count; i++) { + printf("index [%d] MAC [%s] Owner=[%s] SSID[%s]\n", i, list[i].mac_address, list[i].is_group_owner ? "YES" : "NO", @@ -454,15 +442,11 @@ int select_peer(struct appdata* ad) if (scanf(" %3d", &target) < 1) return -1; - if (target < 0 || target > ad->peer_count) - { + if (target < 0 || target > ad->peer_count) { printf("Wrong contact index [%d]\n", target); return -1; - } - else - { + } else ad->selected_peer_index = target; - } return 1; } @@ -473,25 +457,24 @@ void print_peers_connected(struct appdata* ad) wifi_direct_connected_peer_info_s* list; int i, j; - if (ad==NULL) + if (ad == NULL) return; list = ad->connected_peer_list; - for(i=0; iconnected_peer_count; i++) - { + for (i = 0; i < ad->connected_peer_count; i++) { if (list[i].service_count == 0) { - printf ("index [%d] MAC [%s] SSID[%s] \n", i, list[i].mac_address, list[i].device_name); + printf("index [%d] MAC [%s] SSID[%s] \n", i, list[i].mac_address, list[i].device_name); } else { char services[256] = {0,}; unsigned int len = 0; - printf ("Service Count = [%d][%p]\n" ,list[i].service_count,list[i].service_list); - for (j=0; jpeer_list; - for(i=0; ipeer_count; i++) - { + for (i = 0; i < ad->peer_count; i++) { if (list[i].service_count == 0) { - printf ("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] \n", + printf("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] \n", i, list[i].mac_address, list[i].is_group_owner ? "YES" : "NO", @@ -522,13 +504,13 @@ void print_peers(struct appdata* ad) } else { char services[256] = {0,}; unsigned int len = 0; - printf ("Service Count = [%d][%p]\n" ,list[i].service_count,list[i].service_list); - for (j=0; jpeer_count >= MAX_PEER_NUM ) - return false; // break out of the loop + if (NULL != peer) { + if (ad->peer_count >= MAX_PEER_NUM) + return false; /* break out of the loop */ memcpy(&ad->peer_list[ad->peer_count], peer, sizeof(wifi_direct_discovered_peer_info_s)); ad->peer_count++; } - return true; // continue with the next iteration of the loop + return true; /* continue with the next iteration of the loop */ } bool _cb_connected_peers_impl(wifi_direct_connected_peer_info_s* peer, void* user_data) @@ -594,29 +573,28 @@ bool _cb_connected_peers_impl(wifi_direct_connected_peer_info_s* peer, void* use struct appdata* ad = (struct appdata*) user_data; - if(NULL != peer) - { - if ( ad->connected_peer_count >= MAX_PEER_NUM ) - return false; // break out of the loop + if (NULL != peer) { + if (ad->connected_peer_count >= MAX_PEER_NUM) + return false; /* break out of the loop */ memcpy(&ad->connected_peer_list[ad->connected_peer_count], peer, sizeof(wifi_direct_connected_peer_info_s)); ad->connected_peer_count++; } - return true; // continue with the next iteration of the loop + return true; /* continue with the next iteration of the loop */ } bool _cb_persistent_groups_impl(const char* mac_address, const char* ssid, void* user_data) { __FUNC_ENTER__; - if(NULL != mac_address) + if (NULL != mac_address) printf("mac_address=[%s]\n", mac_address); - if(NULL != ssid) + if (NULL != ssid) printf("ssid=[%s]\n", ssid); - return true; // continue with the next iteration of the loop + return true; /* continue with the next iteration of the loop */ } void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data) @@ -625,83 +603,80 @@ void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state, struct appdata* ad = (struct appdata*) user_data; - switch (discovery_state) - { + switch (discovery_state) { + case WIFI_DIRECT_DISCOVERY_STARTED: + event_printf("event - WIFI_DIRECT_DISCOVERY_STARTED\n"); + break; - case WIFI_DIRECT_DISCOVERY_STARTED: - event_printf("event - WIFI_DIRECT_DISCOVERY_STARTED\n"); - break; + case WIFI_DIRECT_ONLY_LISTEN_STARTED: + event_printf("event - WIFI_DIRECT_ONLY_LISTEN_STARTED\n"); + break; - case WIFI_DIRECT_ONLY_LISTEN_STARTED: - event_printf("event - WIFI_DIRECT_ONLY_LISTEN_STARTED\n"); - break; + case WIFI_DIRECT_DISCOVERY_FINISHED: + event_printf("event - WIFI_DIRECT_DISCOVERY_FINISHED\n"); + break; - case WIFI_DIRECT_DISCOVERY_FINISHED: - event_printf("event - WIFI_DIRECT_DISCOVERY_FINISHED\n"); - break; + case WIFI_DIRECT_DISCOVERY_FOUND: + { + int ret; + event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n"); - case WIFI_DIRECT_DISCOVERY_FOUND: - { - int ret; - event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n"); + memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM); + ad->peer_count = 0; + ad->selected_peer_index = 0; - memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM); - ad->peer_count = 0; - ad ->selected_peer_index = 0; + ret = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad); + printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", ret); + } + break; - ret = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad); - printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", ret); - } + case WIFI_DIRECT_DISCOVERY_LOST: + event_printf("event - WIFI_DIRECT_DISCOVERY_LOST\n"); break; - case WIFI_DIRECT_DISCOVERY_LOST: - event_printf("event - WIFI_DIRECT_DISCOVERY_LOST\n"); - break; - - default: - break; + default: + break; } - // _activate_push_cb((void*)NULL, (Evas_Object*)NULL, (void*)NULL); + /* _activate_push_cb((void*)NULL, (Evas_Object*)NULL, (void*)NULL); */ } -void _cb_peer_found(int error_code, wifi_direct_discovery_state_e discovery_state, const char * mac_address,void *user_data) +void _cb_peer_found(int error_code, wifi_direct_discovery_state_e discovery_state, const char * mac_address, void *user_data) { __FUNC_ENTER__; - switch (discovery_state) + switch (discovery_state) { + case WIFI_DIRECT_DISCOVERY_FOUND: { - case WIFI_DIRECT_DISCOVERY_FOUND: - { - event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n"); - - if(mac_address[0] != '\0') { - printf("Peer Address is %s", mac_address); - wifi_direct_discovered_peer_info_s* peer_info = NULL; - - wifi_direct_get_peer_info((char *)mac_address, &peer_info); - if(peer_info !=NULL) { - printf ("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]", - peer_info->mac_address, - peer_info->is_group_owner ? "YES" : "NO", - peer_info->is_connected, - peer_info->device_name, - peer_info->primary_device_type, - peer_info->secondary_device_type - ); - if(peer_info->mac_address) - free(peer_info->mac_address); - if(peer_info->interface_address) - free(peer_info->interface_address); - if(peer_info) - free(peer_info); - } + event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n"); + + if (mac_address[0] != '\0') { + printf("Peer Address is %s", mac_address); + wifi_direct_discovered_peer_info_s* peer_info = NULL; + + wifi_direct_get_peer_info((char *)mac_address, &peer_info); + if (peer_info != NULL) { + printf("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]", + peer_info->mac_address, + peer_info->is_group_owner ? "YES" : "NO", + peer_info->is_connected, + peer_info->device_name, + peer_info->primary_device_type, + peer_info->secondary_device_type + ); + if (peer_info->mac_address) + free(peer_info->mac_address); + if (peer_info->interface_address) + free(peer_info->interface_address); + if (peer_info) + free(peer_info); } } - break; + } + break; - default: - break; + default: + break; } } @@ -712,41 +687,39 @@ void _cb_service(int error_code, { __FUNC_ENTER__; - switch (discovery_state) - { - - case WIFI_DIRECT_SERVICE_DISCOVERY_STARTED: - event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_STARTED\n"); - break; - - case WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED: - event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED\n"); - break; - - case WIFI_DIRECT_SERVICE_DISCOVERY_FOUND: - { - event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FOUND\n"); - if (mac_address != NULL) - printf("Peer Wi-Fi Direct mac address %s\n", mac_address); - if (response_data != NULL) - printf("Peer service response %s\n", (char *)response_data); - if (service_type == WIFI_DIRECT_SERVICE_TYPE_ALL) - printf("Service type = WIFI_DIRECT_SERVICE_TYPE_ALL\n"); - else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BONJOUR) - printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n"); - else if (service_type == WIFI_DIRECT_SERVICE_TYPE_UPNP) - printf("Service type = WIFI_DIRECT_SERVICE_TYPE_UPNP\n"); - else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BT_ADDR) - printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n"); - else if (service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) - printf("service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO"); - else - printf("Requested Service !!! NOT FOUND !!!\n"); - } + switch (discovery_state) { + case WIFI_DIRECT_SERVICE_DISCOVERY_STARTED: + event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_STARTED\n"); break; - default: + case WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED: + event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED\n"); break; + + case WIFI_DIRECT_SERVICE_DISCOVERY_FOUND: + { + event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FOUND\n"); + if (mac_address != NULL) + printf("Peer Wi-Fi Direct mac address %s\n", mac_address); + if (response_data != NULL) + printf("Peer service response %s\n", (char *)response_data); + if (service_type == WIFI_DIRECT_SERVICE_TYPE_ALL) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BONJOUR) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_UPNP) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_UPNP\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BT_ADDR) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) + printf("service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO"); + else + printf("Requested Service !!! NOT FOUND !!!\n"); + } + break; + + default: + break; } __FUNC_EXIT__; } @@ -757,21 +730,19 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st char *ip_addr = NULL; bool owner; - switch (connection_state) - { + switch (connection_state) { case WIFI_DIRECT_CONNECTION_IN_PROGRESS: { event_printf("event - WIFI_DIRECT_CONNECTION_IN_PROGRESS\n"); - if ( error_code == WIFI_DIRECT_ERROR_NONE ) - { - char _peer_mac[18]={0,}; + if (error_code == WIFI_DIRECT_ERROR_NONE) { + char _peer_mac[18] = {0, }; - if(NULL != mac_address) + if (NULL != mac_address) strncpy(_peer_mac, mac_address, strlen(mac_address)); - printf ("Connection start with [%s] \n", _peer_mac); + printf("Connection start with [%s] \n", _peer_mac); event_printf("Error None\n"); } } @@ -781,45 +752,37 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st { event_printf("event - WIFI_DIRECT_CONNECTION_RSP\n"); - if ( error_code == WIFI_DIRECT_ERROR_NONE ) - { - char incomming_peer_mac[18]={0,}; + if (error_code == WIFI_DIRECT_ERROR_NONE) { + char incomming_peer_mac[18] = {0, }; char status[100] = {0,}; - if(NULL != mac_address) + if (NULL != mac_address) strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); - printf ("Connection response with [%s] \n", incomming_peer_mac); + printf("Connection response with [%s] \n", incomming_peer_mac); event_printf("Error None\n"); wifi_direct_is_group_owner(&owner); - if (owner) - { + if (owner) { wifi_direct_get_ip_address(&ip_addr); - if(NULL!=ip_addr) - { + if (NULL != ip_addr) { sprintf(status, "GO - IP : %s", ip_addr); free(ip_addr); } - } - else - { + } else { wifi_direct_get_ip_address(&ip_addr); - if(NULL!=ip_addr) - { + if (NULL != ip_addr) { sprintf(status, "STA - IP : %s", ip_addr); free(ip_addr); } } - } - else - { - if ( error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT ) + } else { + if (error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT) event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT\n"); - else if ( error_code == WIFI_DIRECT_ERROR_AUTH_FAILED ) + else if (error_code == WIFI_DIRECT_ERROR_AUTH_FAILED) event_printf("Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n"); - else if ( error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED ) + else if (error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED) event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED\n"); } @@ -836,18 +799,15 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st result = wifi_direct_get_local_wps_type(&wps_mode); printf("wifi_direct_get__local_wps_type() result=[%d]\n", result); - //BCMP2P_DISCOVER_ENTRY notification_data; - //memcpy(¬ification_data, pNotificationData, sizeof(notification_data)); - if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) - { + /* BCMP2P_DISCOVER_ENTRY notification_data; */ + /* memcpy(¬ification_data, pNotificationData, sizeof(notification_data)); */ + if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) { printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n"); - } - else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) - { + } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) { printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n"); - char pin[9]= { 0, }; + char pin[9] = { 0, }; int result; struct appdata *ad = (struct appdata *) user_data; @@ -860,42 +820,33 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st if (scanf(" %8s", pin) < 1) break; - if( strlen(pin) > 0 ) + if (strlen(pin) > 0) result = wifi_direct_set_wps_pin(pin); else printf("Invalid PIN number\n"); - if ( result == WIFI_DIRECT_ERROR_NONE ) - { + if (result == WIFI_DIRECT_ERROR_NONE) { int i = ad->selected_peer_index; wifi_direct_discovered_peer_info_s* list = ad->peer_list; result = wifi_direct_accept_connection(list[i].mac_address); printf("wifi_direct_accept_connection() result=[%d]\n", result); - } - else + } else printf("wifi_direct_set_wps_pin Error [%d]\n", result); - } - else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD ) - { + } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) { printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n"); char *pin = NULL; result = wifi_direct_get_wps_pin(&pin); printf("wifi_direct_get_wps_pin() result=[%d]\n", result); - if ( NULL != pin ) - { + if (NULL != pin) { printf("WPS_PIN [%s]\n", pin); free(pin); - } - else + } else printf("WPS_PIN is NULL !! \n"); - } - else - { + } else printf("wps_config is unknown!\n"); - } } break; @@ -910,10 +861,10 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st memset(incomming_peer_mac, 0, sizeof(incomming_peer_mac)); - if(NULL != mac_address) + if (NULL != mac_address) strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); - printf ("Connection Request from [%s] \n", incomming_peer_mac); + printf("Connection Request from [%s] \n", incomming_peer_mac); result = wifi_direct_get_local_wps_type(&wps_mode); printf("wifi_direct_get_local_wps_type() result=[%d]\n", result); @@ -921,15 +872,11 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st result = wifi_direct_is_autoconnection_mode(&auto_connection_mode); printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result); - if(auto_connection_mode == TRUE) - { + if (auto_connection_mode == TRUE) { result = wifi_direct_accept_connection(incomming_peer_mac); printf("wifi_direct_accept_connection() result=[%d]\n", result); - } - else - { - if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) - { + } else { + if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) { char pushbutton; printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n"); printf("************\n"); @@ -939,22 +886,17 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st if (scanf(" %c", &pushbutton) < 1) break; - if( (pushbutton == 'Y') || (pushbutton == 'y') ) - { + if ((pushbutton == 'Y') || (pushbutton == 'y')) { result = wifi_direct_accept_connection(incomming_peer_mac); printf("wifi_direct_accept_connection() result=[%d]\n", result); - } - else - { + } else { result = wifi_direct_reject_connection(incomming_peer_mac); printf("wifi_direct_reject_connection() result=[%d]\n", result); } - } - else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD ) - { + } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) { printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n"); - char pin[9]= { 0, }; + char pin[9] = { 0, }; memset(pin, 0x00, sizeof(pin)); printf("*********************\n"); @@ -963,25 +905,20 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st if (scanf(" %8s", pin) < 1) break; - if( strlen(pin) > 0 ) + if (strlen(pin) > 0) result = wifi_direct_set_wps_pin(pin); else printf("Invalid PIN number\n"); - if ( result == WIFI_DIRECT_ERROR_NONE ) - { + if (result == WIFI_DIRECT_ERROR_NONE) { result = wifi_direct_accept_connection(incomming_peer_mac); printf("wifi_direct_accept_connection() result=[%d]\n", result); - } - else + } else printf("wifi_direct_set_wps_pin Error [%d]\n", result); - } - else - { + } else printf("wps_config is unknown!\n"); - } } } break; @@ -990,14 +927,13 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st { event_printf("event - WIFI_DIRECT_DISCONNECTION_IND\n"); - if ( error_code == WIFI_DIRECT_ERROR_NONE ) - { - char incomming_peer_mac[18]={0,}; + if (error_code == WIFI_DIRECT_ERROR_NONE) { + char incomming_peer_mac[18] = {0, }; - if(NULL != mac_address) + if (NULL != mac_address) strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); - printf ("Disconnection IND from [%s] \n", incomming_peer_mac); + printf("Disconnection IND from [%s] \n", incomming_peer_mac); event_printf("Error None\n"); } @@ -1009,14 +945,13 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st { event_printf("event - WIFI_DIRECT_DISCONNECTION_RSP\n"); - if ( error_code == WIFI_DIRECT_ERROR_NONE ) - { - char incomming_peer_mac[18]={0,}; + if (error_code == WIFI_DIRECT_ERROR_NONE) { + char incomming_peer_mac[18] = {0, }; - if(NULL != mac_address) + if (NULL != mac_address) strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); - printf ("Disconnection RSP with [%s] \n", incomming_peer_mac); + printf("Disconnection RSP with [%s] \n", incomming_peer_mac); event_printf("Error None\n"); } @@ -1028,14 +963,13 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st { event_printf("event - WIFI_DIRECT_DISASSOCIATION_IND\n"); - if ( error_code == WIFI_DIRECT_ERROR_NONE ) - { - char incomming_peer_mac[18]={0,}; + if (error_code == WIFI_DIRECT_ERROR_NONE) { + char incomming_peer_mac[18] = {0, }; - if(NULL != mac_address) + if (NULL != mac_address) strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); - printf ("Disassociation IND from [%s] \n", incomming_peer_mac); + printf("Disassociation IND from [%s] \n", incomming_peer_mac); event_printf("Error None\n"); } @@ -1067,20 +1001,20 @@ void _cb_ip_assigned(const char* mac_address, const char* ip_address, const char { __FUNC_ENTER__; - if(NULL != mac_address) - printf ("mac_address [%s] \n", mac_address); + if (NULL != mac_address) + printf("mac_address [%s] \n", mac_address); else - printf ("mac_address is NULL !!\n"); + printf("mac_address is NULL !!\n"); - if(NULL != ip_address) - printf ("ip_address [%s] \n", ip_address); + if (NULL != ip_address) + printf("ip_address [%s] \n", ip_address); else - printf ("ip_address is NULL !!\n"); + printf("ip_address is NULL !!\n"); - if(NULL != interface_address) - printf ("interface_address [%s] \n", interface_address); + if (NULL != interface_address) + printf("interface_address [%s] \n", interface_address); else - printf ("interface_address is NULL !!\n"); + printf("interface_address is NULL !!\n"); __FUNC_EXIT__; @@ -1090,23 +1024,22 @@ bool _cb_foreach_supported_wps_impl(wifi_direct_wps_type_e type, void* user_data { __FUNC_ENTER__; - switch (type) - { - case WIFI_DIRECT_WPS_TYPE_PBC: - printf("type=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); - break; - case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY: - printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); - break; - case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD: - printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); - break; - default: - printf("ERROR : type=[%d]\n", type); - break; + switch (type) { + case WIFI_DIRECT_WPS_TYPE_PBC: + printf("type=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY: + printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD: + printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); + break; + default: + printf("ERROR : type=[%d]\n", type); + break; } - return true; // continue with the next iteration of the loop + return true; /* continue with the next iteration of the loop */ } int init_wfd_client(struct appdata *ad) @@ -1149,131 +1082,125 @@ void process_input(const char *input, gpointer user_data) printf("cmd=[%d]\n", cmd); - switch (cmd) + switch (cmd) { + case CMD_INITIALIZE: { - case CMD_INITIALIZE: - { - result = init_wfd_client(ad); - printf("init_wfd_client() result=[%d]\n", result); - } - break; + result = init_wfd_client(ad); + printf("init_wfd_client() result=[%d]\n", result); + } + break; - case CMD_SET_ACTIVATION_CB: - { - result = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad); - printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", result); - } - break; + case CMD_SET_ACTIVATION_CB: + { + result = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad); + printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", result); + } + break; - case CMD_UNSET_ACTIVATION_CB: - { - result = wifi_direct_unset_device_state_changed_cb(); - printf("wifi_direct_unset_device_state_changed_cb() result=[%d]\n", result); - } - break; + case CMD_UNSET_ACTIVATION_CB: + { + result = wifi_direct_unset_device_state_changed_cb(); + printf("wifi_direct_unset_device_state_changed_cb() result=[%d]\n", result); + } + break; - case CMD_SET_DISCOVER_CB: - { - result = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad); - printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", result); - } - break; + case CMD_SET_DISCOVER_CB: + { + result = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad); + printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", result); + } + break; - case CMD_UNSET_DISCOVER_CB: - { - result = wifi_direct_unset_discovery_state_changed_cb(); - printf("wifi_direct_unset_discovery_state_changed_cb() result=[%d]\n", result); - } - break; + case CMD_UNSET_DISCOVER_CB: + { + result = wifi_direct_unset_discovery_state_changed_cb(); + printf("wifi_direct_unset_discovery_state_changed_cb() result=[%d]\n", result); + } + break; - case CMD_SET_CONNECTION_CB: - { - result = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad); - printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", result); - } - break; + case CMD_SET_CONNECTION_CB: + { + result = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad); + printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", result); + } + break; - case CMD_UNSET_CONNECTION_CB: - { - result = wifi_direct_unset_connection_state_changed_cb(); - printf("wifi_direct_unset_connection_state_changed_cb() result=[%d]\n", result); - } - break; + case CMD_UNSET_CONNECTION_CB: + { + result = wifi_direct_unset_connection_state_changed_cb(); + printf("wifi_direct_unset_connection_state_changed_cb() result=[%d]\n", result); + } + break; - case CMD_SET_SERVICE_CB: - { - result = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad); - printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", result); - } - break; + case CMD_SET_SERVICE_CB: + { + result = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad); + printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", result); + } + break; - case CMD_UNSET_SERVICE_CB: - { - result = wifi_direct_unset_service_state_changed_cb(); - printf("wifi_direct_unset_service_changed_cb() result=[%d]\n", result); - } - break; + case CMD_UNSET_SERVICE_CB: + { + result = wifi_direct_unset_service_state_changed_cb(); + printf("wifi_direct_unset_service_changed_cb() result=[%d]\n", result); + } + break; - case CMD_SET_PEER_FOUND_CB: - { - result = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad); - printf("wifi_direct_set_peer_found_cb() result=[%d]\n", result); - } - break; + case CMD_SET_PEER_FOUND_CB: + { + result = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad); + printf("wifi_direct_set_peer_found_cb() result=[%d]\n", result); + } + break; - case CMD_UNSET_PEER_FOUND_CB: - { - result = wifi_direct_unset_peer_found_cb(); - printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result); - } - break; + case CMD_UNSET_PEER_FOUND_CB: + { + result = wifi_direct_unset_peer_found_cb(); + printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result); + } + break; case CMD_DEINITIALIZE: result = wifi_direct_deinitialize(); printf("wifi_direct_deinitialize() result=[%d]\n", result); break; case CMD_ACTIVATE_WIFI_DIRECT: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_activate(); printf("wifi_direct_activate() result=[%d]\n", result); - if ( result == WIFI_DIRECT_ERROR_WIFI_USED ) + if (result == WIFI_DIRECT_ERROR_WIFI_USED) printf(" ERROR : WIFI_DIRECT_ERROR_WIFI_USED \n"); - else if ( result == WIFI_DIRECT_ERROR_MOBILE_AP_USED ) + else if (result == WIFI_DIRECT_ERROR_MOBILE_AP_USED) printf(" ERROR : WIFI_DIRECT_ERROR_MOBILE_AP_USED \n"); } break; case CMD_DEACTIVATE_WIFI_DIRECT: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_deactivate(); printf("wifi_direct_deactivate() result=[%d]\n", result); } break; case CMD_START_DISCOVER_WITH_LISTEN_ONLY: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_start_discovery(TRUE, 15); printf("wifi_direct_start_discovery() listen_only=[true] result=[%d]\n", result); } break; case CMD_START_DISCOVER: - if (ad != NULL) - { - //result = wifi_direct_start_discovery(FALSE, 15); + if (ad != NULL) { + /* result = wifi_direct_start_discovery(FALSE, 15); */ result = wifi_direct_start_discovery(FALSE, 0); printf("wifi_direct_start_discovery() listen_only=[false] result=[%d]\n", result); } break; case CMD_START_DISCOVER_SPECIFIC_CHANNEL: - if (ad != NULL) - { + if (ad != NULL) { int input; printf("Select Discovery Channel :\n"); printf("1. WIFI_DIRECT_DISCOVERY_FULL_SCAN\n"); @@ -1284,59 +1211,56 @@ void process_input(const char *input, gpointer user_data) if (scanf(" %1d", &input) < 1) break; - switch(input) + switch (input) { + case 1: { - case 1 : - { - result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_FULL_SCAN); - printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_FULL_SCAN, result); - } - break; - case 2 : - { - result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL); - printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL, result); - } - break; - case 3 : - { - result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL1); - printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL1, result); - } - break; - case 4 : - { - result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL6); - printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL6, result); - } - break; - case 5 : - { - result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL11); - printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL11, result); - } - break; - default : - printf("ERROR : Invalid Channel !!!\n"); - break; + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_FULL_SCAN); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_FULL_SCAN, result); + } + break; + case 2: + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL, result); + } + break; + case 3: + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL1); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL1, result); + } + break; + case 4: + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL6); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL6, result); + } + break; + case 5: + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL11); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL11, result); + } + break; + default: + printf("ERROR : Invalid Channel !!!\n"); + break; } } break; case CMD_CANCEL_DISCOVER: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_cancel_discovery(); printf("wifi_direct_cancel_discovery() result=[%d]\n", result); } break; case CMD_GET_DISVOCERY_RESULT: - if (ad != NULL) - { + if (ad != NULL) { memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM); ad->peer_count = 0; - ad ->selected_peer_index = 0; + ad->selected_peer_index = 0; result = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad); printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", result); @@ -1346,16 +1270,14 @@ void process_input(const char *input, gpointer user_data) break; case CMD_SEND_CONNECTION_REQ: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; wifi_direct_discovered_peer_info_s* list = ad->peer_list; result = wifi_direct_accept_connection(list[i].mac_address); - printf ("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n", + printf("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n", i, list[i].mac_address, list[i].is_group_owner ? "YES" : "NO", @@ -1367,24 +1289,21 @@ void process_input(const char *input, gpointer user_data) break; case CMD_DISCONNECT_ALL: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_disconnect_all(); printf("wifi_direct_disconnect_all() result=[%d]\n", result); } break; case CMD_DISCONNECT: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; wifi_direct_discovered_peer_info_s* list = ad->peer_list; result = wifi_direct_disconnect(list[i].mac_address); - printf ("Disconnecting... peer-index[%d] MAC [%s] SSID[%s]\n", + printf("Disconnecting... peer-index[%d] MAC [%s] SSID[%s]\n", i, list[i].mac_address, list[i].device_name); @@ -1396,8 +1315,7 @@ void process_input(const char *input, gpointer user_data) case CMD_GET_LINK_STATUS: - if (ad != NULL) - { + if (ad != NULL) { wifi_direct_state_e status = 0; result = wifi_direct_get_state(&status); printf("wifi_direct_get_state() state=[%s(%d)], result=[%d]\n", print_link_state(status), status, result); @@ -1405,26 +1323,22 @@ void process_input(const char *input, gpointer user_data) break; case CMD_CONNECT_PEER: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { wifi_direct_wps_type_e wps_mode; result = wifi_direct_get_local_wps_type(&wps_mode); printf("wifi_direct_get_local_wps_type() result=[%d]\n", result); - if( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD ) - { + if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) printf("wifi_direct_generate_wps_pin() result=[%d]\n", result); - } int i = ad->selected_peer_index; wifi_direct_discovered_peer_info_s* list = ad->peer_list; result = wifi_direct_connect(list[i].mac_address); - printf ("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n", + printf("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n", i, list[i].mac_address, list[i].is_group_owner ? "YES" : "NO", @@ -1437,10 +1351,8 @@ void process_input(const char *input, gpointer user_data) break; case CMD_CANCEL_CONNECTION: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; wifi_direct_discovered_peer_info_s* list = ad->peer_list; @@ -1451,56 +1363,49 @@ void process_input(const char *input, gpointer user_data) break; case CMD_ENABLE_PUSH_BUTTON: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_activate_pushbutton(); printf("wifi_direct_activate_pushbutton() result=[%d]\n", result); } break; case CMD_CREATE_GROUP: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_create_group(); printf("wifi_direct_create_group() result=[%d]\n", result); } break; case CMD_CANCEL_GROUP: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_destroy_group(); printf("wifi_direct_destroy_group() result=[%d]\n", result); } break; case CMD_IS_GROUP_OWNER: - if (ad != NULL) - { + if (ad != NULL) { bool is_group_owner; result = wifi_direct_is_group_owner(&is_group_owner); printf("wifi_direct_is_group_owner() is GO[%d] result=[%d]\n", is_group_owner, result); } break; case CMD_REJECT: - if (ad != NULL) - { - //result = wifi_direct_client_reject(); + if (ad != NULL) { + /* result = wifi_direct_client_reject(); */ printf("Under construction...\n"); } break; case CMD_INVITE: - if (ad != NULL) - { - //result = wifi_direct_client_invite(); + if (ad != NULL) { + /* result = wifi_direct_client_invite(); */ printf("Under construction...\n"); } break; case CMD_SET_DEVICE_NAME: { - if (ad != NULL) - { + if (ad != NULL) { char *device_name = NULL; printf("Input device name :\n"); @@ -1512,8 +1417,7 @@ void process_input(const char *input, gpointer user_data) else printf("device_name: [%s]\n", device_name); - if ((strlen(device_name) > 0)) - { + if ((strlen(device_name) > 0)) { result = wifi_direct_set_device_name(device_name); printf("wifi_direct_set_device_name() ret=[%d]\n", result); } @@ -1525,15 +1429,13 @@ void process_input(const char *input, gpointer user_data) case CMD_GET_DEVICE_NAME: { - if (ad != NULL) - { + if (ad != NULL) { char* device_name = NULL; result = wifi_direct_get_device_name(&device_name); printf("wifi_direct_get_device_name() result=[%d]\n", result); - if (NULL != device_name) - { + if (NULL != device_name) { printf("ssid: [%s]\n", device_name); free(device_name); } @@ -1544,15 +1446,13 @@ void process_input(const char *input, gpointer user_data) case CMD_GET_SSID: { - if (ad != NULL) - { + if (ad != NULL) { char* ssid = NULL; result = wifi_direct_get_ssid(&ssid); printf("wifi_direct_get_ssid() result=[%d]\n", result); - if (NULL != ssid) - { + if (NULL != ssid) { printf("ssid: [%s]\n", ssid); free(ssid); } @@ -1566,8 +1466,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_SET_MAX_CLIENT: - if (ad != NULL) - { + if (ad != NULL) { int max_client; wifi_direct_get_max_clients(&max_client); @@ -1584,8 +1483,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_MAX_CLIENT: - if (ad != NULL) - { + if (ad != NULL) { int max_client; result = wifi_direct_get_max_clients(&max_client); @@ -1597,11 +1495,10 @@ void process_input(const char *input, gpointer user_data) break; case CMD_ACTIVATE_PERSISTENT_GROUP: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_set_persistent_group_enabled(true); - if(result != WIFI_DIRECT_ERROR_NONE) + if (result != WIFI_DIRECT_ERROR_NONE) printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); else printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); @@ -1609,11 +1506,10 @@ void process_input(const char *input, gpointer user_data) break; case CMD_DEACTIVATE_PERSISTENT_GROUP: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_set_persistent_group_enabled(false); - if(result != WIFI_DIRECT_ERROR_NONE) + if (result != WIFI_DIRECT_ERROR_NONE) printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); else printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); @@ -1621,13 +1517,12 @@ void process_input(const char *input, gpointer user_data) break; case CMD_IS_PERSISTENT_GROUP_ACTIVATED: - if (ad != NULL) - { + if (ad != NULL) { bool enabled; result = wifi_direct_is_persistent_group_enabled(&enabled); printf("wifi_direct_is_persistent_group_enabled() result=[%d]\n", result); - if ( enabled == TRUE ) + if (enabled == TRUE) printf("Persistent Group mode!! \n"); else printf("NOT Persistent group mode!! \n"); @@ -1636,16 +1531,14 @@ void process_input(const char *input, gpointer user_data) case CMD_GET_PERSISTENT_GROUP_LIST: - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_foreach_persistent_groups(_cb_persistent_groups_impl, (void*)ad); printf("wifi_direct_foreach_persistent_groups() ret=[%d]\n", result); } break; case CMD_REMOVE_PERSISTENT_GROUP: - if (ad != NULL) - { + if (ad != NULL) { char *mac = NULL; char *ssid = NULL; @@ -1669,8 +1562,7 @@ void process_input(const char *input, gpointer user_data) else printf("ssid: [%s]\n", ssid); - if ((strlen(mac) > 0) && (strlen(ssid) > 0)) - { + if ((strlen(mac) > 0) && (strlen(ssid) > 0)) { result = wifi_direct_remove_persistent_group(mac, ssid); printf("wifi_direct_remove_persistent_group() ret=[%d]\n", result); } @@ -1681,8 +1573,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_SET_AUTO_CONNECTION: - if (ad != NULL) - { + if (ad != NULL) { int autoconnection_mode; printf("Input Auto connection: \n"); @@ -1704,13 +1595,12 @@ void process_input(const char *input, gpointer user_data) break; case CMD_IS_AUTO_CONNECTION: - if (ad != NULL) - { + if (ad != NULL) { bool auto_connection = false; result = wifi_direct_is_autoconnection_mode(&auto_connection); printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result); - if ( auto_connection == TRUE ) + if (auto_connection == TRUE) printf("Auto connection mode !! \n"); else printf("NOT Auto connection mode !! \n"); @@ -1719,9 +1609,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_SET_WPS_PIN: - if (ad != NULL) - { - + if (ad != NULL) { char *pin = NULL; printf("Input PIN number :\n"); @@ -1740,57 +1628,50 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_WPS_PIN: - if (ad != NULL) - { + if (ad != NULL) { char *pin = NULL; result = wifi_direct_get_wps_pin(&pin); printf("wifi_direct_get_wps_pin() result=[%d]\n", result); - if ( NULL != pin ) - { + if (NULL != pin) { printf("WPS_PIN [%s]\n", pin); free(pin); - } - else + } else printf("WPS_PIN is NULL !! \n"); } break; case CMD_GET_SUPPORTED_WPS_MODE: - if (ad != NULL) - { + if (ad != NULL) { int supported_wps_mode = 0; result = wifi_direct_foreach_supported_wps_types(_cb_foreach_supported_wps_impl, NULL); printf("wifi_direct_foreach_supported_wps_types() result=[%d]\n", result); - result = wifi_direct_get_supported_wps_mode (&supported_wps_mode); + result = wifi_direct_get_supported_wps_mode(&supported_wps_mode); printf("wifi_direct_foreach_supported_wps_types() supported=[%d] result=[%d]\n", supported_wps_mode, result); } break; case CMD_SET_CURRENT_WPS_MODE: - if (ad != NULL) - { - + if (ad != NULL) { wifi_direct_wps_type_e wps_mode; int input; result = wifi_direct_get_req_wps_type(&wps_mode); - switch(wps_mode) - { - case WIFI_DIRECT_WPS_TYPE_PBC : - printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); - break; - case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY : - printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); - break; - case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD : - printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); - break; - default : - printf("ERROR : wps_mode=[%d]\n", wps_mode); - break; + switch (wps_mode) { + case WIFI_DIRECT_WPS_TYPE_PBC: + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY: + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD: + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); + break; + default: + printf("ERROR : wps_mode=[%d]\n", wps_mode); + break; } printf("Input new wps mode:\n"); @@ -1800,20 +1681,19 @@ void process_input(const char *input, gpointer user_data) if (scanf(" %1d", &input) < 1) break; - switch(input) - { - case 1 : - wps_mode = WIFI_DIRECT_WPS_TYPE_PBC; - break; - case 2 : - wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY; - break; - case 3 : - wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD; - break; - default : - printf("ERROR : Invalid input wps_mode!!!\n"); - break; + switch (input) { + case 1: + wps_mode = WIFI_DIRECT_WPS_TYPE_PBC; + break; + case 2: + wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY; + break; + case 3: + wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD; + break; + default: + printf("ERROR : Invalid input wps_mode!!!\n"); + break; } result = wifi_direct_set_req_wps_type(wps_mode); @@ -1822,33 +1702,30 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_CURRENT_WPS_MODE: - if (ad != NULL) - { + if (ad != NULL) { wifi_direct_wps_type_e wps_mode; result = wifi_direct_get_req_wps_type(&wps_mode); printf("wifi_direct_get_wps_type() wps_mode=[%d], result=[%d]\n", wps_mode, result); - switch(wps_mode) - { - case WIFI_DIRECT_WPS_TYPE_PBC : - printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); - break; - case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY : - printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); - break; - case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD : - printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); - break; - default : - printf("ERROR : wps_mode=[%d]\n", wps_mode); - break; + switch (wps_mode) { + case WIFI_DIRECT_WPS_TYPE_PBC: + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY: + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD: + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); + break; + default: + printf("ERROR : wps_mode=[%d]\n", wps_mode); + break; } } break; case CMD_GET_CONNECTED_PEERS_INFO: - if (ad != NULL) - { + if (ad != NULL) { memset(ad->connected_peer_list, 0x00, sizeof(wifi_direct_connected_peer_info_s)*MAX_PEER_NUM); ad->connected_peer_count = 0; @@ -1859,8 +1736,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_GO_INTENT: - if (ad != NULL) - { + if (ad != NULL) { int go_intent; result = wifi_direct_get_group_owner_intent(&go_intent); @@ -1869,8 +1745,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_SET_GO_INTENT: - if (ad != NULL) - { + if (ad != NULL) { int go_intent; wifi_direct_get_group_owner_intent(&go_intent); @@ -1887,27 +1762,25 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_DEVICE_MAC: - if (ad != NULL) - { + if (ad != NULL) { char *device_mac = NULL; result = wifi_direct_get_mac_address(&device_mac); printf("wifi_direct_get_mac_addr() result=[%d]\n", result); - if ( NULL != device_mac ) - printf ("MAC [%s] \n", device_mac); + if (NULL != device_mac) + printf("MAC [%s] \n", device_mac); else printf("device_mac is NULL !! \n"); } break; case CMD_IS_AUTONOMOUS_GROUP: - if (ad != NULL) - { + if (ad != NULL) { bool autonomous_group; result = wifi_direct_is_autonomous_group(&autonomous_group); printf("wifi_direct_is_autonomous_group() result=[%d]\n", result); - if ( autonomous_group == TRUE ) + if (autonomous_group == TRUE) printf("Autonomous Group !! \n"); else printf("NOT Autonomous group !! \n"); @@ -1916,15 +1789,13 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_NETWORK_IF_NAME: - if (ad != NULL) - { + if (ad != NULL) { char* name = NULL; result = wifi_direct_get_network_interface_name(&name); printf("wifi_direct_get_network_interface_name() result=[%d]\n", result); - if (NULL != name) - { + if (NULL != name) { printf("name: [%s]\n", name); free(name); } @@ -1933,15 +1804,13 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_SUBNET_MASK: - if (ad != NULL) - { + if (ad != NULL) { char* subnet_mask = NULL; result = wifi_direct_get_subnet_mask(&subnet_mask); printf("wifi_direct_get_subnet_mask() result=[%d]\n", result); - if (NULL != subnet_mask) - { + if (NULL != subnet_mask) { printf("subnet_mask: [%s]\n", subnet_mask); free(subnet_mask); } @@ -1951,15 +1820,13 @@ void process_input(const char *input, gpointer user_data) case CMD_GET_GATEWAY_ADDR: - if (ad != NULL) - { + if (ad != NULL) { char* gateway_address = NULL; result = wifi_direct_get_gateway_address(&gateway_address); printf("wifi_direct_get_gateway_address() result=[%d]\n", result); - if (NULL != gateway_address) - { + if (NULL != gateway_address) { printf("gateway_address: [%s]\n", gateway_address); free(gateway_address); } @@ -1968,13 +1835,12 @@ void process_input(const char *input, gpointer user_data) break; case CMD_IS_DISCOVERABLE: - if (ad != NULL) - { + if (ad != NULL) { bool discoverable = false; result = wifi_direct_is_discoverable(&discoverable); printf("wifi_direct_is_discoverable() result=[%d]\n", result); - if ( discoverable == TRUE ) + if (discoverable == TRUE) printf("Discoverable state !! \n"); else printf("NOT Discoverable state !! \n"); @@ -1983,13 +1849,12 @@ void process_input(const char *input, gpointer user_data) break; case CMD_IS_LISTEN_ONLY: - if (ad != NULL) - { + if (ad != NULL) { bool listen_only = false; result = wifi_direct_is_listening_only(&listen_only); printf("wifi_direct_is_listening_only() result=[%d]\n", result); - if ( listen_only == TRUE ) + if (listen_only == TRUE) printf("Listen only state !! \n"); else printf("NOT Listen only state !! \n"); @@ -1998,8 +1863,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_PRIMARY_DEVICE_TYPE: - if (ad != NULL) - { + if (ad != NULL) { wifi_direct_primary_device_type_e type; result = wifi_direct_get_primary_device_type(&type); @@ -2011,8 +1875,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_SECONDARY_DEVICE_TYPE: - if (ad != NULL) - { + if (ad != NULL) { wifi_direct_secondary_device_type_e type; result = wifi_direct_get_secondary_device_type(&type); @@ -2023,8 +1886,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_OPERATING_CHANNEL: - if (ad != NULL) - { + if (ad != NULL) { int operating_channel; result = wifi_direct_get_operating_channel(&operating_channel); @@ -2037,19 +1899,15 @@ void process_input(const char *input, gpointer user_data) case CMD_GET_IP_ADDR: { - if (ad != NULL) - { + if (ad != NULL) { char* ip_addr = NULL; result = wifi_direct_get_ip_address(&ip_addr); printf("wifi_direct_get_ip_address() result=[%d]\n", result); - if(NULL != ip_addr) - { + if (NULL != ip_addr) { printf("IP [%s]\n", ip_addr); free(ip_addr); - } - else - { + } else { printf("IP is NULL\n"); } } @@ -2065,8 +1923,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_REGISTER_SERVICE: - if (ad != NULL) - { + if (ad != NULL) { wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; unsigned int input; char *info1 = NULL; @@ -2081,47 +1938,46 @@ void process_input(const char *input, gpointer user_data) printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n"); if (scanf(" %1u", &input) < 1) break; - printf("input = %u\n",input); + printf("input = %u\n", input); - switch(input) - { - case 1 : - service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; - break; - case 2 : - service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; - printf("Enter info 1\n"); - if (scanf(" %50ms", &info1) < 1) - break; + switch (input) { + case 1: + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2: + service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; + printf("Enter info 1\n"); + if (scanf(" %50ms", &info1) < 1) + break; - printf("Enter info 2\n"); - if (scanf(" %50ms", &info2) < 1) - free(info1); + printf("Enter info 2\n"); + if (scanf(" %50ms", &info2) < 1) + free(info1); - break; - case 3 : - service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; - printf("Enter info 1\n"); - if (scanf(" %50ms", &info1) < 1) - break; + break; + case 3: + service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; + printf("Enter info 1\n"); + if (scanf(" %50ms", &info1) < 1) + break; - printf("Enter info 2\n"); - if (scanf(" %50ms", &info2) < 1) - free(info1); + printf("Enter info 2\n"); + if (scanf(" %50ms", &info2) < 1) + free(info1); - break; - case 4 : - service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; - break; - case 5 : - service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; - printf("Enter contact info\n"); - if (scanf(" %50ms", &str) < 1) - break; - break; - default : - printf("ERROR : Invalid input service_type!!!\n"); - break; + break; + case 4: + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 5: + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + printf("Enter contact info\n"); + if (scanf(" %50ms", &str) < 1) + break; + break; + default: + printf("ERROR : Invalid input service_type!!!\n"); + break; } result = wifi_direct_register_service(service_type, info1, info2, &input); @@ -2132,8 +1988,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_DEREGISTER_SERVICE: - if (ad != NULL) - { + if (ad != NULL) { int input; printf("Enter service id:\n"); @@ -2146,8 +2001,7 @@ void process_input(const char *input, gpointer user_data) } break; case CMD_START_SERVICE_DISCOVERY: - if (ad != NULL) - { + if (ad != NULL) { int input; wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; @@ -2159,37 +2013,35 @@ void process_input(const char *input, gpointer user_data) printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n"); if (scanf(" %1d", &input) < 1) break; - printf("input = %d\n",input); + printf("input = %d\n", input); - switch(input) - { - case 1 : - service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; - break; - case 2 : - service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; - break; - case 3 : - service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; - break; - case 4 : - service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; - break; - case 5 : - service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; - break; - default : - printf("ERROR : Invalid input service_type!!!\n"); - break; + switch (input) { + case 1: + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2: + service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; + break; + case 3: + service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; + break; + case 4: + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 5: + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + break; + default: + printf("ERROR : Invalid input service_type!!!\n"); + break; } - if (select_peer(ad)) - { + if (select_peer(ad)) { result = wifi_direct_start_service_discovery( NULL, service_type); - printf ("Service Discovery... broadcast service type[%d]\n", + printf("Service Discovery... broadcast service type[%d]\n", service_type); } else { int i = ad->selected_peer_index; @@ -2198,8 +2050,8 @@ void process_input(const char *input, gpointer user_data) result = wifi_direct_start_service_discovery( list[i].mac_address, service_type); - printf ("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n", - i,list[i].mac_address, service_type); + printf("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n", + i, list[i].mac_address, service_type); } printf("wifi_direct_start_service_discovery() result=[%d]\n", result); @@ -2208,8 +2060,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_CANCEL_SERVICE_DISCOVERY: - if (ad != NULL) - { + if (ad != NULL) { int input; wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; @@ -2217,36 +2068,34 @@ void process_input(const char *input, gpointer user_data) if (scanf(" %1d", &input) < 1) break; - printf("input = %d\n",input); + printf("input = %d\n", input); - switch(input) - { - case 1 : - service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; - break; - case 2 : - service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; - break; - case 3 : - service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; - break; - case 4 : - service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; - break; - case 5 : - service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; - break; - default : - printf("ERROR : Invalid input service_type!!!\n"); - break; + switch (input) { + case 1: + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2: + service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; + break; + case 3: + service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; + break; + case 4: + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 5: + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + break; + default: + printf("ERROR : Invalid input service_type!!!\n"); + break; } - if (select_peer(ad)) - { + if (select_peer(ad)) { result = wifi_direct_cancel_service_discovery( NULL, service_type); - printf ("Service Discovery... broadcast service type[%d]\n", + printf("Service Discovery... broadcast service type[%d]\n", service_type); } else { int i = ad->selected_peer_index; @@ -2255,16 +2104,15 @@ void process_input(const char *input, gpointer user_data) result = wifi_direct_cancel_service_discovery( list[i].mac_address, service_type); - printf ("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n", - i,list[i].mac_address, service_type); + printf("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n", + i, list[i].mac_address, service_type); } printf("wifi_direct_cancel_service_discovery() result=[%d]\n", result); } break; case CMD_INIT_MIRACAST: - if (ad != NULL) - { + if (ad != NULL) { int miracast_enable; printf("Input miracast enable: \n"); @@ -2287,15 +2135,14 @@ void process_input(const char *input, gpointer user_data) case CMD_GET_PEER_INFO: if (ad != NULL) - if (select_peer(ad)) - { + if (select_peer(ad)) { int i = ad->selected_peer_index; wifi_direct_discovered_peer_info_s* list = ad->peer_list; wifi_direct_discovered_peer_info_s* peer_info = NULL; result = wifi_direct_get_peer_info(list[i].mac_address, &peer_info); - if(peer_info !=NULL) { - printf ("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]", + if (peer_info != NULL) { + printf("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]", peer_info->mac_address, peer_info->is_group_owner ? "YES" : "NO", peer_info->is_connected, @@ -2303,11 +2150,11 @@ void process_input(const char *input, gpointer user_data) peer_info->primary_device_type, peer_info->secondary_device_type ); - if(peer_info->mac_address) + if (peer_info->mac_address) free(peer_info->mac_address); - if(peer_info->interface_address) + if (peer_info->interface_address) free(peer_info->interface_address); - if(peer_info) + if (peer_info) free(peer_info); } @@ -2316,8 +2163,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_SET_PASSPHRASE: { - if (ad != NULL) - { + if (ad != NULL) { char passphrase[64] = {0, }; printf("Input passphrase :\n"); @@ -2335,15 +2181,13 @@ void process_input(const char *input, gpointer user_data) break; case CMD_GET_PASSPHRASE: { - if (ad != NULL) - { + if (ad != NULL) { char* passphrase = NULL; result = wifi_direct_get_passphrase(&passphrase); printf("wifi_direct_get_passphrase() result=[%d]\n", result); - if (NULL != passphrase) - { + if (NULL != passphrase) { printf("passphrase: [%s]\n", passphrase); free(passphrase); } @@ -2352,8 +2196,7 @@ void process_input(const char *input, gpointer user_data) } break; case CMD_SET_AUTOCONNECTION_PEER: - if (ad != NULL) - { + if (ad != NULL) { char * mac_address = NULL; printf("\nEnter Mac_address: "); if (scanf(" %18ms", &mac_address) < 1) @@ -2365,10 +2208,9 @@ void process_input(const char *input, gpointer user_data) } else { int rv = wifi_direct_set_autoconnection_peer(mac_address); - if (rv == WIFI_DIRECT_ERROR_NONE) - { + if (rv == WIFI_DIRECT_ERROR_NONE) { free(mac_address); - printf(MAKE_GREEN"SUCCESS %s"RESET_COLOR"\n",__func__); + printf(MAKE_GREEN"SUCCESS %s"RESET_COLOR"\n", __func__); break; } printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv)); @@ -2379,8 +2221,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_INIT_DISPLAY: { - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_init_display(); printf("wifi_direct_init_display() result=[%d]\n", result); } @@ -2388,8 +2229,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_DEINIT_DISPLAY: { - if (ad != NULL) - { + if (ad != NULL) { result = wifi_direct_deinit_display(); printf("wifi_direct_deinit_display() result=[%d]\n", result); } @@ -2397,8 +2237,7 @@ void process_input(const char *input, gpointer user_data) break; case CMD_SET_DISPLAY: { - if (ad != NULL) - { + if (ad != NULL) { int rv = WIFI_DIRECT_ERROR_NONE; int use_default = 0; @@ -2406,7 +2245,7 @@ void process_input(const char *input, gpointer user_data) if (scanf(" %1d", &use_default) < 1) break; - if(use_default == 0) { + if (use_default == 0) { rv = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_SOURCE, 7236, 1); } else { int display_type = 0; @@ -2433,20 +2272,19 @@ void process_input(const char *input, gpointer user_data) rv = wifi_direct_set_display(display_type, port_number, hdcp); } - if(rv == WIFI_DIRECT_ERROR_NONE) { - printf(MAKE_GREEN"Success %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv)); + if (rv == WIFI_DIRECT_ERROR_NONE) { + printf(MAKE_GREEN"Success %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv)); break; } - printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv)); + printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv)); break; } } break; case CMD_SET_DISPLAY_AVAILABILITY: { - if (ad != NULL) - { + if (ad != NULL) { int availability = 0; printf("Enter Wi-Fi Display availability : "); @@ -2454,22 +2292,19 @@ void process_input(const char *input, gpointer user_data) break; int rv = wifi_direct_set_display_availability(availability); - if (WIFI_DIRECT_ERROR_NONE == rv) - { + if (WIFI_DIRECT_ERROR_NONE == rv) { printf(MAKE_GREEN"Set Wi-Fi Display availability Successful"RESET_COLOR"\n"); break; } - printf(MAKE_RED"Set Wi-Fi Display availability : %s ",test_wfd_convert_error_to_string(rv)); + printf(MAKE_RED"Set Wi-Fi Display availability : %s ", test_wfd_convert_error_to_string(rv)); printf(RESET_COLOR"\n"); break; } } break; case CMD_GET_PEER_DISPLAY_TYPE: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; wifi_direct_display_type_e type = WIFI_DIRECT_DISPLAY_TYPE_DUAL; wifi_direct_discovered_peer_info_s* list = ad->peer_list; @@ -2481,10 +2316,8 @@ void process_input(const char *input, gpointer user_data) } break; case CMD_GET_PEER_DISPLAY_AVAILABILITY: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; bool availability = false; wifi_direct_discovered_peer_info_s* list = ad->peer_list; @@ -2496,10 +2329,8 @@ void process_input(const char *input, gpointer user_data) } break; case CMD_GET_PEER_DISPLAY_HDCP: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; int hdcp; wifi_direct_discovered_peer_info_s* list = ad->peer_list; @@ -2511,10 +2342,8 @@ void process_input(const char *input, gpointer user_data) } break; case CMD_GET_PEER_DISPLAY_PORT: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; int port; wifi_direct_discovered_peer_info_s* list = ad->peer_list; @@ -2526,10 +2355,8 @@ void process_input(const char *input, gpointer user_data) } break; case CMD_GET_PEER_DISPLAY_THROUGHPUT: - if (ad != NULL) - { - if (select_peer(ad)) - { + if (ad != NULL) { + if (select_peer(ad)) { int i = ad->selected_peer_index; int tput; wifi_direct_discovered_peer_info_s* list = ad->peer_list; @@ -2567,20 +2394,15 @@ static gboolean test_terminal_read_std_input(GIOChannel * source, errno = 0; n = read(fd, buf, 1024); - buf[n - 1] = '\0'; // remove new line... - if (n == 0) - { + buf[n - 1] = '\0'; /* remove new line... */ + if (n == 0) { printf("Error: read() from stdin returns 0.\n"); - } - else if (n < 0) - { + } else if (n < 0) { printf("input: read, err=%s\n", strerror(errno)); - } - else - { + } else { printf("\n\n"); - //printf("Read [%d]bytes data: [%s]\n", n, buf); - //printf("Processing it ---------------------\n", n, buf); + /* printf("Read [%d]bytes data: [%s]\n", n, buf); */ + /* printf("Processing it ---------------------\n", n, buf); */ } process_input(buf, user_data); @@ -2593,7 +2415,7 @@ int main(int argc, char **argv) GMainLoop *main_loop; struct appdata *ad = NULL; -#if !GLIB_CHECK_VERSION(2,36,0) +#if !GLIB_CHECK_VERSION(2, 36, 0) g_type_init(); #endif -- 2.7.4