return (i == 6);
}
-
static char *__wfd_print_event(wfd_client_event_e event)
{
switch (event)
return WIFI_DIRECT_DEVICE_STATE_DEACTIVATED;
break;
- case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
- return WIFI_DIRECT_ONLY_LISTEN_STARTED;
- break;
case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
return WIFI_DIRECT_DISCOVERY_STARTED;
break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
+ return WIFI_DIRECT_ONLY_LISTEN_STARTED;
+ break;
case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
return WIFI_DIRECT_DISCOVERY_FINISHED;
break;
case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
return WIFI_DIRECT_CONNECTION_RSP;
break;
- case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
- return WIFI_DIRECT_DISCONNECTION_RSP;
- break;
case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
return WIFI_DIRECT_CONNECTION_WPS_REQ;
break;
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
+ return WIFI_DIRECT_DISCONNECTION_RSP;
+ break;
case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
return WIFI_DIRECT_DISCONNECTION_IND;
break;
}
__WDC_LOG_FUNC_END__;
-
+ return -1;
}
static gboolean __wfd_client_process_event(GIOChannel * source,
}
errno = 0;
- if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 3)
{
WDC_LOGE("Error!!! creating sync socket. Error = [%s].", strerror(errno));
return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
while (retry_count > 0)
{
errno = 0;
- if ((ret = connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
- {
- WDC_LOGD("Launching wfd-server..\n");
- ret = system("dbus-send --system --print-reply --dest=net.netconfig /net/netconfig/wifi net.netconfig.wifi.LaunchDirect");
- if (ret == -1)
- WDC_LOGE("Error!!! sending dbus msg Error = [%s]", strerror(errno));
- retry_count--;
- }
- else
- {
+ ret = connect(sockfd, (struct sockaddr *) &servAddr, len);
+ if (!ret) {
+ WDC_LOGD("Succeeded to connect to server socket");
break;
}
-
+ WDC_LOGD("Launching wfd-server..\n");
+ ret = system("dbus-send --system --print-reply --dest=net.netconfig /net/netconfig/wifi net.netconfig.wifi.LaunchDirect");
+ if (ret == -1)
+ WDC_LOGE("Error!!! sending dbus msg Error = [%s]", strerror(errno));
+ retry_count--;
usleep(100000); /* wait a few seconds before retrying the next socket connection */
}
{
WDC_LOGE("Error!!! connecting to server socket. Error = [%d] %s.\n",
errno, strerror(errno));
- if (sockfd > 0)
+ if (sockfd > 2)
close(sockfd);
__WDC_LOG_FUNC_END__;
{
WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
- if (sockfd > 0)
+ if (sockfd > 2)
close(sockfd);
__WDC_LOG_FUNC_END__;
return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
sizeof(wifi_direct_client_response_s))) <= 0)
{
WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
- if (sockfd > 0)
+ if (sockfd > 2)
close(sockfd);
__WDC_LOG_FUNC_END__;
return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
else
{
WDC_LOGE("Error!!! Client Register = %d\n", resp.result);
- if (sockfd > 0)
+ if (sockfd > 2)
close(sockfd);
__WDC_LOG_FUNC_END__;
return resp.result;
if (async_sockfd == WIFI_DIRECT_ERROR_COMMUNICATION_FAILED)
{
WDC_LOGE("Error!!! creating Async Socket \n");
- if (sockfd > 0)
+ if (sockfd > 2)
close(sockfd);
__wfd_reset_control();
__WDC_LOG_FUNC_END__;
{
WDC_LOGE("Error!!! Invalid Response received from wfd Server. cmd = %d \n",
resp.cmd);
- if (sockfd > 0)
+ if (sockfd > 2)
close(sockfd);
__WDC_LOG_FUNC_END__;
return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
client_info->connection_cb = cb;
client_info->user_data_for_cb_connection = user_data;
+ __WDC_LOG_FUNC_END__;
return WIFI_DIRECT_ERROR_NONE;
}
client_info->connection_cb = NULL;
client_info->user_data_for_cb_connection = NULL;
+ __WDC_LOG_FUNC_END__;
return WIFI_DIRECT_ERROR_NONE;
}
client_info->ip_assigned_cb = cb;
client_info->user_data_for_cb_ip_assigned = user_data;
+ __WDC_LOG_FUNC_END__;
return WIFI_DIRECT_ERROR_NONE;
}
client_info->ip_assigned_cb = NULL;
client_info->user_data_for_cb_ip_assigned = NULL;
+ __WDC_LOG_FUNC_END__;
return WIFI_DIRECT_ERROR_NONE;
}
else
{
WDC_LOGD("wifi_direct_get_wps_pin() SUCCESS");
- strncpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN);
-
- char *temp_pin;
- temp_pin = strdup(la_pin);
-
- *pin = temp_pin;
+ snprintf(la_pin, WIFI_DIRECT_WPS_PIN_LEN+1, rsp.param2);
+ *pin = strdup(la_pin);
}
}
else
}
else
{
- WDC_LOGD(
- "wifi_direct_get_ssid() %s SUCCESS \n",
+ WDC_LOGD("wifi_direct_get_ssid() %s SUCCESS \n",
rsp.param2);
- strncpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN);
-
- char *temp_ssid = NULL;
- temp_ssid = strdup(la_ssid);
- if (NULL == temp_ssid)
- {
- WDC_LOGE("Failed to allocate memory for SSID\n");
- return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
- }
-
- *ssid = temp_ssid;
+ snprintf(la_ssid, WIFI_DIRECT_MAX_SSID_LEN+1, rsp.param2);
+ *ssid = strdup(la_ssid);
}
}
else
{
WDC_LOGD("wifi_direct_get_device_name() %s SUCCESS \n", rsp.param2);
- strncpy(la_device_name, rsp.param2, WIFI_DIRECT_MAX_DEVICE_NAME_LEN);
-
- char *temp_device_name = NULL;
- temp_device_name = strdup(la_device_name);
- if (NULL == temp_device_name)
- {
- WDC_LOGE("Failed to allocate memory for device name\n");
- return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
- }
-
- *device_name = temp_device_name;
+ snprintf(la_device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1, rsp.param2);
+ *device_name = strdup(la_device_name);
}
}
memset(mac_info, 0, sizeof(mac_info));
fd = open(WIFI_DIRECT_MAC_ADDRESS_INFO_FILE, O_RDONLY);
- if (fd == -1)
+ if (fd < 3)
{
WDC_LOGE("[.mac.info] file open failed.");
__WDC_LOG_FUNC_END__;
if (NULL == temp_mac)
{
WDC_LOGE("Failed to allocate memory for MAC address");
- if (fd > 0)
+ if (fd > 2)
close(fd);
return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
}
- //strncpy(temp_mac, mac_info, strlen(mac_info));
snprintf(temp_mac, 18, MACSTR, MAC2STR(la_mac_addr));
*mac_address = temp_mac;
- if (fd > 0)
+ if (fd > 2)
close(fd);
__WDC_LOG_FUNC_END__;
WDC_LOGD("writing msg hdr is success!");
strncpy(persistent_group_info.ssid, ssid, strlen(ssid));
+ persistent_group_info.ssid[WIFI_DIRECT_MAX_SSID_LEN] = '\0';
memset(la_mac_addr, 0, sizeof(la_mac_addr));
macaddr_atoe(mac_address, la_mac_addr);