From 1c4304379e8e9b81fbf4f9260946f9964c4bd5b5 Mon Sep 17 00:00:00 2001 From: Vinay Krishna Eranna Date: Tue, 1 Oct 2013 19:37:51 +0530 Subject: [PATCH] Fix: SIGPIPE issue while querying softap enabled status Before downloading commands to driver through softap SDK we are checking if SoftAP is enabled are not by running ps in popen. This sometime throws SIGPIPE error (signal) which is not handled, due to this we were facing application crash. To fix this we modify to check the operation mode of the driver through ioctl. Change-Id: Ia0703ff343d401801655d3b666ade66107a4789e CRs-Fixed: 535340 --- softap/sdk/qsap.c | 24 +++++++++----------- softap/sdk/qsap_api.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/softap/sdk/qsap.c b/softap/sdk/qsap.c index 676b1a8..6f2ff87 100755 --- a/softap/sdk/qsap.c +++ b/softap/sdk/qsap.c @@ -434,26 +434,22 @@ s32 wifi_qsap_stop_bss(void) s32 is_softap_enabled(void) { - FILE *fp; - char buf[1024]; + s32 mode = 0; + int ret; - fp = popen("ps", "r"); - if (fp == NULL) { - ALOGE("Failed to open file"); + ret = qsap_get_mode(&mode); + if (eSUCCESS != ret) { + ALOGD("Failed to get the mode of operation\n"); return eERR_UNKNOWN; } - while (fgets(buf, sizeof(buf)-1, fp) != NULL) { - if(NULL !=(strstr(buf,"hostapd"))) - { - pclose(fp); - ALOGD("HOSTAPD enabled\n"); - return ENABLE; - } + if (mode == IW_MODE_MASTER) { + ALOGD("HOSTAPD Enabled\n"); + return ENABLE; } - ALOGD("HOSTAPD disabled\n"); - pclose(fp); + ALOGD("HOSTAPD Disabled\n"); + return DISABLE; } diff --git a/softap/sdk/qsap_api.c b/softap/sdk/qsap_api.c index 958c4e5..a38e065 100755 --- a/softap/sdk/qsap_api.c +++ b/softap/sdk/qsap_api.c @@ -1256,6 +1256,57 @@ error: return eERR_GET_AUTO_CHAN; } + +/** + * Get the mode of operation. + */ +int qsap_get_mode(s32 *pmode) +{ + int sock; + struct iwreq wrq; + s8 interface[MAX_CONF_LINE_LEN]; + u32 len = MAX_CONF_LINE_LEN; + s8 *pif; + int ret; + sap_auto_channel_info sap_autochan_info; + s32 *pchan; + + *pmode = -1; + if(NULL == (pif = qsap_get_config_value(pconffile, + &qsap_str[STR_INTERFACE], interface, &len))) { + ALOGD("%s :interface error \n", __func__); + goto error; + } + + interface[len] = '\0'; + + sock = socket(AF_INET, SOCK_DGRAM, 0); + if(sock < 0) { + ALOGD("%s :socket error \n", __func__); + goto error; + } + + memset(&wrq, 0, sizeof(wrq)); + strlcpy(wrq.ifr_name, pif, sizeof(wrq.ifr_name)); + + ret = ioctl(sock, SIOCGIWMODE, &wrq); + if(ret < 0) { + ALOGE("%s: ioctl failure \n",__func__); + close(sock); + goto error; + } + + *pmode = *(s32 *)(&wrq.u.mode); + ALOGE("%s: ioctl Get Mode = %d \n",__func__, *pmode); + close(sock); + return eSUCCESS; + +error: + *pmode = -1; + ALOGE("%s: (Failure) ioctl Get Mode = %d \n",__func__, *pmode); + return eERR_UNKNOWN; +} + /** * Set the channel Range for soft AP. */