Compare commits

..

9 Commits

Author SHA1 Message Date
Steve Kondik
c54aba9422 qsap: Kill more logspam
Change-Id: I0a32abbf783ffb1534051fd89708d2a49014c6c3
2014-05-13 01:27:12 -07:00
Steve Kondik
b980ab07f5 qsap: Put files in a sane location
* And set their perms

Change-Id: Ifc61a3504433f6b7e1602432ecea70c37785c895
2014-05-11 04:01:05 -07:00
Steve Kondik
6cf22dc84c qsap: Don't log sensitive information
Change-Id: I3ab6d73051d4647941de6eee41c2b5507c5eddc6
2014-05-11 01:36:32 -07:00
Hanumantha Reddy Pothula
f510e31bcd Updated string banned functions strncpy and memcpy
Banned call strncpy has been updated
with strlcpy

Change-Id: I992c2d3580dce24981a4ec9fd9d50ecca109c044
CRs-Fixed: 554334
2014-03-22 04:43:12 +01:00
Mahesh A Saptasagar
b30ed9569f SAP: Make QSAP SDK compatible w.r.t Android framework.
SAP parameter ignore_broadcast_ssid always set to
"broadcast" due to improper handling of SAP parameters
at SAP SDK.

To mitigate this issue update the ignore_broadcast_ssid
parameter based on the value configured in the framework.

Change-Id: Ia1a35a38464710088921b94269b624d8b1910abc
CRs-Fixed: 588560
2014-01-02 21:32:41 +00:00
Mingcheng Zhu
70700a0773 qcom: softap: Fix potential string null termination and buffer overflow
Fix potential string null termination and buffer overflow

Change-Id: I05e28b30a4e3134625d20fb5591b239ea4b9f3a4
CRs-fixed: 554078
2014-01-02 21:32:20 +00:00
Shake M Subhani
5d5650caf1 softap: sscanf sanity check for SoftAP service
The sscanf return value is verified whether the three channel
variables, i.e. start channel, end channel and channel band,
are properly updated. If malformed input is given to sscanf, then
these variables may not properly updated. To provide validation
of input,  verifying that sscanf returned a correct value of 3.

Change-Id: Ibd185e7a0ffcf5803927990531fc33f0e8977cc9
CRs-fixed: 554349
2013-12-06 14:35:34 +01:00
Vinay Krishna Eranna
52fd77178b 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
2013-11-27 01:43:15 +00:00
Mahesh A Saptasagar
fe07ff9ee2 wlan: make qsap compatible w.r.t ndc implementation.
changes to make qsap compatible w.r.t ndc implementation by
correcting argument mismatch.

Change-Id: I6722ce3fdcf2b4bc45c44d82d56f2c5a14435d7c
CRs-Fixed: 436332
2013-11-25 17:48:14 +01:00
7 changed files with 101 additions and 613 deletions

View File

@@ -11,10 +11,10 @@ LOCAL_MODULE := libQWiFiSoftApCfg
LOCAL_MODULE_TAGS := optional LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include \ LOCAL_C_INCLUDES := $(KERNEL_HEADERS) \
$(JNI_H_INCLUDE) $(JNI_H_INCLUDE)
LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr LOCAL_SHARED_LIBRARIES := libsysutils libcutils libnetutils libcrypto
LOCAL_SHARED_LIBRARIES := libsysutils libcutils libnetutils libcrypto liblog
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)

View File

@@ -319,7 +319,7 @@ JNIEXPORT jstring JNICALL
char code[32] = {0}; char code[32] = {0};
int connect_retry; int connect_retry;
strlcpy(cmd, "softap qccmd ", sizeof(cmd)); strncpy(cmd, "softap qccmd ", sizeof(cmd));
pcmd = (char *) ((*env)->GetStringUTFChars(env, jcmd, NULL)); pcmd = (char *) ((*env)->GetStringUTFChars(env, jcmd, NULL));
@@ -330,12 +330,12 @@ JNIEXPORT jstring JNICALL
ALOGD("Received Command: %s\n", pcmd); ALOGD("Received Command: %s\n", pcmd);
if ((strlen(cmd) + strlen(pcmd)) >= sizeof(cmd)) { if ((strlen(cmd) + strlen(pcmd)) > sizeof(cmd)) {
UPDATE_ERROR_CODE("Command length is larger than MAX_CMD_SIZE", ""); UPDATE_ERROR_CODE("Command length is larger than MAX_CMD_SIZE", "");
goto end; goto end;
} }
strlcat(cmd, pcmd, sizeof(cmd)); strcat(cmd, pcmd);
connect_retry = 0; connect_retry = 0;

8
softap/sdk/Android.mk Executable file → Normal file
View File

@@ -4,7 +4,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(TOP)/hardware/libhardware_legacy/wifi $(TOP)/external/libnl/include $(TOP)/external/wpa_supplicant_8/wpa_supplicant/src/drivers LOCAL_C_INCLUDES :=
LOCAL_MODULE:= libqsap_sdk LOCAL_MODULE:= libqsap_sdk
@@ -12,10 +12,6 @@ LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -DSDK_VERSION=\"0.0.1.0\" LOCAL_CFLAGS += -DSDK_VERSION=\"0.0.1.0\"
LOCAL_COPY_HEADERS_TO := sdk/softap/include
LOCAL_COPY_HEADERS := qsap_api.h
LOCAL_COPY_HEADERS += qsap.h
ifdef WIFI_DRIVER_MODULE_PATH ifdef WIFI_DRIVER_MODULE_PATH
LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_PATH=\"$(WIFI_DRIVER_MODULE_PATH)\" LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_PATH=\"$(WIFI_DRIVER_MODULE_PATH)\"
endif endif
@@ -61,7 +57,7 @@ LOCAL_SRC_FILES := qsap_api.c \
LOCAL_PRELINK_MODULE := false LOCAL_PRELINK_MODULE := false
LOCAL_SHARED_LIBRARIES := libnetutils libutils libbinder libcutils libhardware_legacy libnl liblog LOCAL_SHARED_LIBRARIES := libnetutils libutils libbinder libcutils
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)

112
softap/sdk/qsap.c Normal file → Executable file
View File

@@ -54,6 +54,7 @@
#include "qsap_api.h" #include "qsap_api.h"
#include "qsap.h" #include "qsap.h"
#include "libwpa_client/wpa_ctrl.h"
#include <sys/system_properties.h> #include <sys/system_properties.h>
@@ -584,114 +585,3 @@ s32 wifi_qsap_reload_softap()
return eSUCCESS; return eSUCCESS;
} }
static pid_t wigigSoftApPid = 0;
static const char WIGIG_ENTROPY_FILE[] = "/data/misc/wifi/wigig_entropy.bin";
static unsigned char dummy_key[21] = { 0x02, 0x11, 0xbe, 0x33, 0x43, 0x35,
0x68, 0x47, 0x84, 0x99, 0xa9, 0x2b,
0x1c, 0xd3, 0xee, 0xff, 0xf1, 0xe2,
0xf3, 0xf4, 0xf5 };
static const char HOSTAPD_BIN_FILE[] = "/system/bin/hostapd";
static const char WIGIG_HOSTAPD_CONF_FILE[] = "/data/misc/wifi/wigig_hostapd.conf";
#define AP_BSS_START_DELAY 200000
#define AP_BSS_STOP_DELAY 500000
int wigig_ensure_entropy_file_exists()
{
int ret;
int destfd;
ret = access(WIGIG_ENTROPY_FILE, R_OK|W_OK);
if ((ret == 0) || (errno == EACCES)) {
if ((ret != 0) &&
(chmod(WIGIG_ENTROPY_FILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) {
ALOGE("Cannot set RW to \"%s\": %s", WIGIG_ENTROPY_FILE, strerror(errno));
return -1;
}
return 0;
}
destfd = TEMP_FAILURE_RETRY(open(WIGIG_ENTROPY_FILE, O_CREAT|O_RDWR, 0660));
if (destfd < 0) {
ALOGE("Cannot create \"%s\": %s", WIGIG_ENTROPY_FILE, strerror(errno));
return -1;
}
if (TEMP_FAILURE_RETRY(write(destfd, dummy_key, sizeof(dummy_key))) != sizeof(dummy_key)) {
ALOGE("Error writing \"%s\": %s", WIGIG_ENTROPY_FILE, strerror(errno));
close(destfd);
return -1;
}
close(destfd);
/* chmod is needed because open() didn't set permisions properly */
if (chmod(WIGIG_ENTROPY_FILE, 0660) < 0) {
ALOGE("Error changing permissions of %s to 0660: %s",
WIGIG_ENTROPY_FILE, strerror(errno));
unlink(WIGIG_ENTROPY_FILE);
return -1;
}
if (chown(WIGIG_ENTROPY_FILE, AID_SYSTEM, AID_WIFI) < 0) {
ALOGE("Error changing group ownership of %s to %d: %s",
WIGIG_ENTROPY_FILE, AID_WIFI, strerror(errno));
unlink(WIGIG_ENTROPY_FILE);
return -1;
}
return 0;
}
s32 wifi_qsap_start_wigig_softap(void)
{
pid_t pid = 1;
ALOGD("%s", __func__);
if (wigigSoftApPid) {
ALOGE("Wigig SoftAP is already running");
return eERR_START_SAP;
}
if (wigig_ensure_entropy_file_exists() < 0) {
ALOGE("Wigig entropy file was not created");
}
if ((pid = fork()) < 0) {
ALOGE("fork failed (%s)", strerror(errno));
return eERR_START_SAP;
}
if (!pid) {
if (execl(HOSTAPD_BIN_FILE, HOSTAPD_BIN_FILE,
"-e", WIGIG_ENTROPY_FILE, "-dd",
WIGIG_HOSTAPD_CONF_FILE, (char *) NULL)) {
ALOGE("execl failed (%s)", strerror(errno));
}
ALOGE("Wigig SoftAP failed to start. Exiting child process...");
exit(-1);
}
wigigSoftApPid = pid;
ALOGD("Wigig SoftAP started successfully");
usleep(AP_BSS_START_DELAY);
return eSUCCESS;
}
s32 wifi_qsap_stop_wigig_softap(void)
{
ALOGD("%s", __func__);
if (wigigSoftApPid == 0) {
ALOGE("Wigig SoftAP is not running");
return eSUCCESS;
}
ALOGD("Stopping the Wigig SoftAP...");
kill(wigigSoftApPid, SIGTERM);
waitpid(wigigSoftApPid, NULL, 0);
wigigSoftApPid = 0;
ALOGD("Wigig SoftAP stopped successfully");
usleep(AP_BSS_STOP_DELAY);
return eSUCCESS;
}

View File

@@ -44,8 +44,6 @@ s32 commit(void);
s32 is_softap_enabled(void); s32 is_softap_enabled(void);
s32 wifi_qsap_start_softap(void); s32 wifi_qsap_start_softap(void);
s32 wifi_qsap_stop_softap(void); s32 wifi_qsap_stop_softap(void);
s32 wifi_qsap_start_wigig_softap(void);
s32 wifi_qsap_stop_wigig_softap(void);
s32 wifi_qsap_reload_softap(void); s32 wifi_qsap_reload_softap(void);
s32 wifi_qsap_unload_wifi_sta_driver(void); s32 wifi_qsap_unload_wifi_sta_driver(void);

537
softap/sdk/qsap_api.c Executable file → Normal file
View File

@@ -44,13 +44,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <private/android_filesystem_config.h> #include <private/android_filesystem_config.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include "nl80211_copy.h"
#include "qsap_api.h" #include "qsap_api.h"
#include "qsap.h" #include "qsap.h"
@@ -65,7 +58,7 @@
#define QCSAP_PARAM_GET_AUTO_CHANNEL 9 #define QCSAP_PARAM_GET_AUTO_CHANNEL 9
#define WE_SET_SAP_CHANNELS 3 #define WE_SET_SAP_CHANNELS 3
#define LOG_TAG "QCSDK" //#define LOG_TAG "QCSDK-"
#include "cutils/properties.h" #include "cutils/properties.h"
#include "cutils/log.h" #include "cutils/log.h"
@@ -85,15 +78,6 @@ s8 *Cmd_req[eCMD_REQ_LAST] = {
"set" "set"
}; };
/** Supported config file requests.
* WANRING: The enum eConf_req in the file qsap_api.h should be
* updated if Conf_req[], us updated
*/
s8 *Conf_req[CONF_REQ_LAST] = {
"dual2g",
"dual5g"
};
/* /*
* WARNING: On updating the cmd_list, the enum esap_cmd in file * WARNING: On updating the cmd_list, the enum esap_cmd in file
* qsap_api.h must be updates to reflect the changes * qsap_api.h must be updates to reflect the changes
@@ -168,18 +152,6 @@ static struct Command cmd_list[eCMD_LAST] = {
{ "setchannelrange", NULL }, { "setchannelrange", NULL },
{ "autochannel", NULL }, { "autochannel", NULL },
{ "ieee80211w", NULL }, { "ieee80211w", NULL },
{ "wpa_key_mgmt", NULL },
{ "max_num_sta", "8" },
{ "ieee80211ac", NULL },
{ "vht_oper_chwidth", NULL },
{ "chanlist", NULL },
{ "ht_capab", NULL },
{ "ieee80211h", NULL },
{ "enable_wigig_softap", NULL },
{ "interface", NULL },
{ "ssid2", NULL },
{ "bridge", NULL },
{ "ctrl_interface", NULL },
}; };
struct Command qsap_str[eSTR_LAST] = { struct Command qsap_str[eSTR_LAST] = {
@@ -332,7 +304,7 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
s8 buf[MAX_CONF_LINE_LEN+1]; s8 buf[MAX_CONF_LINE_LEN+1];
s16 len, result = FALSE; s16 len, result = FALSE;
ALOGD("cmd=%s, Val:%s, INI:%ld \n", pcmd->name, pVal, inifile); ALOGV("cmd=%s, Val:%s, INI:%ld \n", pcmd->name, pVal, inifile);
/** Open the configuration file */ /** Open the configuration file */
fcfg = fopen(pfile, "r"); fcfg = fopen(pfile, "r");
@@ -367,7 +339,7 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
if(pline[len] == '=') { if(pline[len] == '=') {
qsap_scnprintf(buf, sizeof(buf), "%s=%s\n", pcmd->name, pVal); qsap_scnprintf(buf, sizeof(buf), "%s=%s\n", pcmd->name, pVal);
result = TRUE; result = TRUE;
ALOGD("Updated:%s\n", buf); ALOGV("Updated:%s\n", buf);
} }
} }
@@ -382,7 +354,7 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
/* Add the new line at the end of file */ /* Add the new line at the end of file */
qsap_scnprintf(buf, sizeof(buf), "%s=%s\n", pcmd->name, pVal); qsap_scnprintf(buf, sizeof(buf), "%s=%s\n", pcmd->name, pVal);
fprintf(ftmp, "%s", buf); fprintf(ftmp, "%s", buf);
ALOGD("Adding a new line in %s file: [%s] \n", inifile ? "inifile" : "hostapd.conf", buf); ALOGV("Adding a new line in %s file: [%s] \n", inifile ? "inifile" : "hostapd.conf", buf);
} }
if(inifile) { if(inifile) {
@@ -412,6 +384,14 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
unlink(pfile); unlink(pfile);
return -1; return -1;
} }
if (chown(pfile, AID_SYSTEM, AID_WIFI) < 0) {
ALOGE("Error changing group ownership of %s to %d: %s",
pfile, AID_WIFI, strerror(errno));
unlink(pfile);
return -1;
}
if(result == eERR_UNKNOWN) if(result == eERR_UNKNOWN)
return eERR_FEATURE_NOT_ENABLED; return eERR_FEATURE_NOT_ENABLED;
@@ -557,6 +537,14 @@ static s32 qsap_change_cfg(s8 *pfile, struct Command * pcmd, u32 status)
unlink(pfile); unlink(pfile);
return -1; return -1;
} }
if (chown(pfile, AID_SYSTEM, AID_WIFI) < 0) {
ALOGE("Error changing group ownership of %s to %d: %s",
pfile, AID_WIFI, strerror(errno));
unlink(pfile);
return -1;
}
return 0; return 0;
} }
@@ -709,46 +697,13 @@ end:
static s8 *qsap_get_allow_deny_file_name(s8 *pcfgfile, struct Command * pcmd, s8 *pfile, u32 *plen) static s8 *qsap_get_allow_deny_file_name(s8 *pcfgfile, struct Command * pcmd, s8 *pfile, u32 *plen)
{ {
if(eSUCCESS == qsap_read_cfg(pcfgfile, pcmd, pfile, plen, NULL, GET_ENABLED_ONLY)) { if(eSUCCESS == qsap_read_cfg(pcfgfile, pcmd, pfile, plen, NULL, GET_ENABLED_ONLY)) {
pfile[*plen] = '\0';
return strchr(pfile, '=') + 1; return strchr(pfile, '=') + 1;
} }
return NULL; return NULL;
} }
int qsap_hostd_exec(int argc, char ** argv) {
#define MAX_CMD_SIZE 256
char qcCmdBuf[MAX_CMD_SIZE], *pCmdBuf;
u32 len = MAX_CMD_SIZE;
int i = 2, ret;
if ( argc < 4 ) {
ALOGD("failure: invalid arguments");
return -1;
}
argc -= 2;
pCmdBuf = qcCmdBuf;
while (argc--) {
ret = snprintf(pCmdBuf, len, " %s", argv[i]);
if ((ret < 0) || (ret >= (int)len)) {
/* Error case */
/* TODO: Command too long send the error message */
*pCmdBuf = '\0';
break;
}
ALOGD("argv[%d] (%s)",i, argv[i]);
pCmdBuf += ret;
len -= ret;
i++;
}
ALOGD("QCCMD data (%s)", pCmdBuf);
len = MAX_CMD_SIZE;
qsap_hostd_exec_cmd(qcCmdBuf, qcCmdBuf, (u32*)&len);
return 0;
}
/** Function to identify a valid MAC address */ /** Function to identify a valid MAC address */
static int isValid_MAC_address(char *pMac) static int isValid_MAC_address(char *pMac)
{ {
@@ -977,7 +932,7 @@ static void qsap_remove_from_file(s8 *pfile, s8 *pVal, s8 *presp, u32 *plen)
*/ */
static void qsap_update_mac_list(s8 *pfile, esap_cmd_t cNum, s8 *pVal, s8 *presp, u32 *plen) static void qsap_update_mac_list(s8 *pfile, esap_cmd_t cNum, s8 *pVal, s8 *presp, u32 *plen)
{ {
ALOGD("%s : Updating file %s \n", __func__, pfile); ALOGV("%s : Updating file %s \n", __func__, pfile);
switch(cNum) { switch(cNum) {
case eCMD_ADD_TO_ALLOW: case eCMD_ADD_TO_ALLOW:
@@ -1132,7 +1087,7 @@ static int qsap_read_mac_address(s8 *presp, u32 *plen)
ptr++; ptr++;
ALOGD("MAC :%s \n", ptr); ALOGV("MAC :%s \n", ptr);
if(TRUE == isValid_MAC_address(ptr)) { if(TRUE == isValid_MAC_address(ptr)) {
nRet = eSUCCESS; nRet = eSUCCESS;
} }
@@ -1168,7 +1123,7 @@ static void qsap_read_wps_state(s8 *presp, u32 *plen)
if(NULL == (pstate = qsap_get_config_value(pconffile, &cmd_list[eCMD_WPS_STATE], presp, &tlen))) { if(NULL == (pstate = qsap_get_config_value(pconffile, &cmd_list[eCMD_WPS_STATE], presp, &tlen))) {
/** unable to read the wps configuration, WPS is disabled !*/ /** unable to read the wps configuration, WPS is disabled !*/
ALOGD("%s :wps_state not in cfg file \n", __func__); ALOGV("%s :wps_state not in cfg file \n", __func__);
status = DISABLE; status = DISABLE;
} }
else { else {
@@ -1223,9 +1178,9 @@ int qsap_get_operating_channel(s32 *pchan)
goto error; goto error;
} }
ALOGE("Recv len :%d \n", wrq.u.data.length); ALOGV("Recv len :%d \n", wrq.u.data.length);
*pchan = *(int *)(&wrq.u.name[0]); *pchan = *(int *)(&wrq.u.name[0]);
ALOGE("Operating channel :%ld \n", *pchan); ALOGV("Operating channel :%ld \n", *pchan);
close(sock); close(sock);
return eSUCCESS; return eSUCCESS;
@@ -1256,7 +1211,7 @@ int qsap_get_sap_auto_channel_selection(s32 *pautochan)
if(NULL == (pif = qsap_get_config_value(pconffile, if(NULL == (pif = qsap_get_config_value(pconffile,
&qsap_str[STR_INTERFACE], interface, &len))) { &qsap_str[STR_INTERFACE], interface, &len))) {
ALOGD("%s :interface error \n", __func__); ALOGV("%s :interface error \n", __func__);
goto error; goto error;
} }
@@ -1264,7 +1219,7 @@ int qsap_get_sap_auto_channel_selection(s32 *pautochan)
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock < 0) { if(sock < 0) {
ALOGD("%s :socket error \n", __func__); ALOGV("%s :socket error \n", __func__);
goto error; goto error;
} }
@@ -1287,9 +1242,9 @@ int qsap_get_sap_auto_channel_selection(s32 *pautochan)
goto error; goto error;
} }
ALOGD("Recv len :%d \n", wrq.u.data.length); ALOGV("Recv len :%d \n", wrq.u.data.length);
*pautochan = *(int *)(&wrq.u.name[0]); *pautochan = *(int *)(&wrq.u.name[0]);
ALOGD("Sap auto channel selection pautochan=%ld \n", *pautochan); ALOGV("Sap auto channel selection pautochan=%ld \n", *pautochan);
close(sock); close(sock);
return eSUCCESS; return eSUCCESS;
@@ -1317,7 +1272,7 @@ int qsap_get_mode(s32 *pmode)
*pmode = -1; *pmode = -1;
if(NULL == (pif = qsap_get_config_value(pconffile, if(NULL == (pif = qsap_get_config_value(pconffile,
&qsap_str[STR_INTERFACE], interface, &len))) { &qsap_str[STR_INTERFACE], interface, &len))) {
ALOGD("%s :interface error \n", __func__); ALOGV("%s :interface error \n", __func__);
goto error; goto error;
} }
@@ -1325,7 +1280,7 @@ int qsap_get_mode(s32 *pmode)
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock < 0) { if(sock < 0) {
ALOGD("%s :socket error \n", __func__); ALOGV("%s :socket error \n", __func__);
goto error; goto error;
} }
@@ -1429,7 +1384,7 @@ int qsap_set_channel_range(s8 *buf)
goto error; goto error;
} }
ALOGE("Recv len :%d\n", wrq.u.data.length); ALOGV("Recv len :%d\n", wrq.u.data.length);
close(sock); close(sock);
return eSUCCESS; return eSUCCESS;
@@ -1447,7 +1402,7 @@ int qsap_read_channel(s8 *pfile, struct Command *pcmd, s8 *presp, u32 *plen, s8
if(eSUCCESS == qsap_get_operating_channel(&chan)) { if(eSUCCESS == qsap_get_operating_channel(&chan)) {
*plen = qsap_scnprintf(presp, len, "%s %s=%lu", SUCCESS, pcmd->name, chan); *plen = qsap_scnprintf(presp, len, "%s %s=%lu", SUCCESS, pcmd->name, chan);
ALOGD("presp :%s\n", presp); ALOGV("presp :%s\n", presp);
} else { } else {
*plen = qsap_scnprintf(presp, len, "%s", ERR_UNKNOWN); *plen = qsap_scnprintf(presp, len, "%s", ERR_UNKNOWN);
} }
@@ -1508,7 +1463,6 @@ void qsap_get_associated_sta_mac(s8 *presp, u32 *plen)
u32 len = MAX_CONF_LINE_LEN; u32 len = MAX_CONF_LINE_LEN;
s8 *pif; s8 *pif;
s8 *pbuf, *pout; s8 *pbuf, *pout;
u32 buflen;
u32 recvLen; u32 recvLen;
u32 tlen; u32 tlen;
@@ -1528,9 +1482,7 @@ void qsap_get_associated_sta_mac(s8 *presp, u32 *plen)
goto error; goto error;
} }
/* response has length field + 6 bytes per STA */ pbuf = (s8 *)malloc((MAX_STA_ALLOWED * 6) + 8);
buflen = sizeof(u32) + (MAX_STA_ALLOWED * 6);
pbuf = (s8 *)malloc(buflen);
if(NULL == pbuf) { if(NULL == pbuf) {
ALOGE("%s :No memory \n", __func__); ALOGE("%s :No memory \n", __func__);
close(sock); close(sock);
@@ -1540,7 +1492,7 @@ void qsap_get_associated_sta_mac(s8 *presp, u32 *plen)
#define SIZE_OF_MAC_INT (6) #define SIZE_OF_MAC_INT (6)
strlcpy(wrq.ifr_name, pif, sizeof(wrq.ifr_name)); strlcpy(wrq.ifr_name, pif, sizeof(wrq.ifr_name));
wrq.u.data.length = buflen; wrq.u.data.length = SIZE_OF_MAC_INT * 8 + 8; /** 8 supported MAC and 7 SPACE separators and a '\0' */
wrq.u.data.pointer = (void *)pbuf; wrq.u.data.pointer = (void *)pbuf;
wrq.u.data.flags = 0; wrq.u.data.flags = 0;
@@ -1552,14 +1504,13 @@ void qsap_get_associated_sta_mac(s8 *presp, u32 *plen)
goto error; goto error;
} }
recvLen = *(u32 *)(wrq.u.data.pointer); recvLen = *(unsigned long int *)(wrq.u.data.pointer);
recvLen -= sizeof(u32);
len = qsap_scnprintf(presp, *plen, "%s %s=", SUCCESS, cmd_list[eCMD_ASSOC_STA_MACS].name); len = qsap_scnprintf(presp, *plen, "%s %s=", SUCCESS, cmd_list[eCMD_ASSOC_STA_MACS].name);
pout = presp + len; pout = presp + len;
tlen = *plen - len; tlen = *plen - len;
qsap_mac_to_macstr(pbuf+sizeof(u32), recvLen, pout, &tlen); qsap_mac_to_macstr(pbuf+sizeof(unsigned long int), recvLen, pout, &tlen);
*plen = len + tlen; *plen = len + tlen;
@@ -1757,10 +1708,15 @@ static void qsap_get_from_config(esap_cmd_t cNum, s8 *presp, u32 *plen)
break; break;
case eCMD_FRAG_THRESHOLD: case eCMD_FRAG_THRESHOLD:
qsap_read_cfg(fIni, &qsap_str[STR_FRAG_THRESHOLD_IN_INI], presp, plen, cmd_list[eCMD_FRAG_THRESHOLD].name, GET_ENABLED_ONLY);
break;
case eCMD_REGULATORY_DOMAIN: case eCMD_REGULATORY_DOMAIN:
qsap_read_cfg(fIni, &qsap_str[STR_802DOT11D_IN_INI], presp, plen, cmd_list[eCMD_REGULATORY_DOMAIN].name, GET_ENABLED_ONLY);
break;
case eCMD_RTS_THRESHOLD: case eCMD_RTS_THRESHOLD:
case eCMD_IEEE80211H: qsap_read_cfg(fIni, &qsap_str[STR_RTS_THRESHOLD_IN_INI], presp, plen, cmd_list[eCMD_RTS_THRESHOLD].name, GET_ENABLED_ONLY);
qsap_read_cfg(pconffile, &cmd_list[cNum], presp, plen, NULL, GET_ENABLED_ONLY);
break; break;
case eCMD_ALLOW_LIST: /* fall through */ case eCMD_ALLOW_LIST: /* fall through */
@@ -1779,7 +1735,7 @@ static void qsap_get_from_config(esap_cmd_t cNum, s8 *presp, u32 *plen)
break; break;
case eCMD_WMM_STATE: case eCMD_WMM_STATE:
qsap_read_cfg(pconffile, &cmd_list[cNum], presp, plen, NULL, GET_ENABLED_ONLY); qsap_read_cfg(fIni, &qsap_str[STR_WMM_IN_INI], presp, plen, cmd_list[eCMD_WMM_STATE].name, GET_ENABLED_ONLY);
break; break;
case eCMD_WPS_STATE: case eCMD_WPS_STATE:
@@ -1928,7 +1884,7 @@ static s16 is_valid_wep_key(s8 *pwep, s8 *pkey, s16 len)
weplen--; weplen--;
while(weplen--) { while(weplen--) {
if(0 == isascii(pwep[weplen])) { if(0 == isascii(pwep[weplen])) {
ALOGD("%c not ascii \n", pwep[weplen]); ALOGV("%c not ascii \n", pwep[weplen]);
return FALSE; return FALSE;
} }
} }
@@ -1987,6 +1943,11 @@ s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault)
if(eERR_UNKNOWN == rename(buf, pcfgfile)) if(eERR_UNKNOWN == rename(buf, pcfgfile))
status = eERR_CONF_FILE; status = eERR_CONF_FILE;
if (chown(pcfgfile, AID_WIFI, AID_WIFI) < 0) {
ALOGE("Error changing group ownership of %s to %d: %s",
pcfgfile, AID_WIFI, strerror(errno));
}
/** Remove the temporary file. Dont care the return value */ /** Remove the temporary file. Dont care the return value */
unlink(buf); unlink(buf);
@@ -2069,7 +2030,7 @@ static int qsap_send_cmd_to_hostapd(s8 *pcmd)
goto error; goto error;
} }
ALOGD("Connect to :%s\n", ptr); ALOGV("Connect to :%s\n", ptr);
sock = socket(PF_UNIX, SOCK_DGRAM, 0); sock = socket(PF_UNIX, SOCK_DGRAM, 0);
if(sock < 0) { if(sock < 0) {
@@ -2089,7 +2050,7 @@ static int qsap_send_cmd_to_hostapd(s8 *pcmd)
ser.sun_family = AF_UNIX; ser.sun_family = AF_UNIX;
qsap_scnprintf(ser.sun_path, sizeof(ser.sun_path), "%s", ptr); qsap_scnprintf(ser.sun_path, sizeof(ser.sun_path), "%s", ptr);
ALOGD("Connect to: %s,(%d)\n", ser.sun_path, sock); ALOGV("Connect to: %s,(%d)\n", ser.sun_path, sock);
ret = connect(sock, (struct sockaddr *)&ser, sizeof(ser)); ret = connect(sock, (struct sockaddr *)&ser, sizeof(ser));
if(ret < 0) { if(ret < 0) {
@@ -2244,7 +2205,7 @@ static void qsap_config_wps_method(s8 *pVal, s8 *presp, u32 *plen)
qsap_scnprintf(buf, sizeof(buf), "WPS_PBC"); qsap_scnprintf(buf, sizeof(buf), "WPS_PBC");
else { else {
if(strlen(ptr) < WPS_KEY_LEN) { if(strlen(ptr) < WPS_KEY_LEN) {
ALOGD("%s :Invalid WPS key length\n", __func__); ALOGV("%s :Invalid WPS key length\n", __func__);
*plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALID_PARAM); *plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALID_PARAM);
return; return;
} }
@@ -2340,7 +2301,7 @@ void qsap_disassociate_sta(s8 *pVal, s8 *presp, u32 *plen)
goto end; goto end;
} }
strlcpy(wrq.ifr_name, pif, sizeof(wrq.ifr_name)); strncpy(wrq.ifr_name, pif, sizeof(wrq.ifr_name));
if (TRUE != qsap_get_mac_in_bytes(pVal, (char *) &wrq.u)) { if (TRUE != qsap_get_mac_in_bytes(pVal, (char *) &wrq.u)) {
ALOGE("%s: Invalid input \n", __func__); ALOGE("%s: Invalid input \n", __func__);
@@ -2436,7 +2397,6 @@ static int qsap_set_operating_mode(s32 mode, s8 *pmode, int pmode_len, s8 *tbuf,
qsap_change_cfg(pcfg, &cmd_list[eCMD_REQUIRE_HT],ENABLE); qsap_change_cfg(pcfg, &cmd_list[eCMD_REQUIRE_HT],ENABLE);
/* fall through */ /* fall through */
case HW_MODE_N: case HW_MODE_N:
case HW_MODE_G:
case HW_MODE_A: case HW_MODE_A:
ulen = *tlen; ulen = *tlen;
qsap_write_cfg(pcfg, &cmd_list[eCMD_IEEE80211N],ieee11n_enable, tbuf, &ulen, HOSTAPD_CONF_QCOM_FILE); qsap_write_cfg(pcfg, &cmd_list[eCMD_IEEE80211N],ieee11n_enable, tbuf, &ulen, HOSTAPD_CONF_QCOM_FILE);
@@ -2526,15 +2486,6 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
SKIP_BLANK_SPACE(pcmd); SKIP_BLANK_SPACE(pcmd);
if(!(strncmp(pcmd, Conf_req[CONF_2g], strlen(Conf_req[CONF_2g])))) {
pcmd += strlen(Conf_req[CONF_2g]);
SKIP_BLANK_SPACE(pcmd);
} else if (!(strncmp(pcmd, Conf_req[CONF_5g], strlen(Conf_req[CONF_5g])))) {
pcmd += strlen(Conf_req[CONF_5g]);
SKIP_BLANK_SPACE(pcmd);
} else {
// DO NOTHING
}
cNum = qsap_get_cmd_num(pcmd); cNum = qsap_get_cmd_num(pcmd);
if(cNum == eCMD_INVALID) { if(cNum == eCMD_INVALID) {
*plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALID_ARG); *plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALID_ARG);
@@ -2648,32 +2599,12 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
} }
*plen = qsap_scnprintf(presp, *plen, "%s", (status==eSUCCESS) ? SUCCESS : "failure Could not enable softap"); *plen = qsap_scnprintf(presp, *plen, "%s", (status==eSUCCESS) ? SUCCESS : "failure Could not enable softap");
return; return;
case eCMD_ENABLE_WIGIG_SOFTAP:
value = atoi(pVal);
if (TRUE != IS_VALID_SOFTAP_ENABLE(value))
goto error;
if ( *pVal == '0' ) {
status = wifi_qsap_stop_wigig_softap();
}
else {
status = wifi_qsap_start_wigig_softap();
}
*plen = qsap_scnprintf(presp, *plen, "%s", (status==eSUCCESS) ? SUCCESS : "failure Could not enable Wigig softap");
return;
case eCMD_SSID: case eCMD_SSID:
value = strlen(pVal); value = strlen(pVal);
if(SSD_MAX_LEN < value) if(SSD_MAX_LEN < value)
goto error; goto error;
/* Disable ssid2 while setting ssid */
qsap_change_cfg(pcfg, &cmd_list[eCMD_SSID2], DISABLE);
break; break;
case eCMD_SET_MAX_CLIENTS:
value = strlen(pVal);
break;
case eCMD_BSSID: case eCMD_BSSID:
value = atoi(pVal); value = atoi(pVal);
if(FALSE == IS_VALID_BSSID(value)) if(FALSE == IS_VALID_BSSID(value))
@@ -2936,6 +2867,8 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
goto error; goto error;
qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value); qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value);
cNum = STR_WMM_IN_INI;
ini = INI_CONF_FILE;
break; break;
case eCMD_WPS_STATE: case eCMD_WPS_STATE:
value = atoi(pVal); value = atoi(pVal);
@@ -2966,6 +2899,9 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
if(TRUE != IS_VALID_FRAG_THRESHOLD(value)) if(TRUE != IS_VALID_FRAG_THRESHOLD(value))
goto error; goto error;
qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value); qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value);
cNum = STR_FRAG_THRESHOLD_IN_INI;
ini = INI_CONF_FILE;
break; break;
case eCMD_REGULATORY_DOMAIN: case eCMD_REGULATORY_DOMAIN:
@@ -2982,6 +2918,8 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
if(TRUE != IS_VALID_RTS_THRESHOLD(value)) if(TRUE != IS_VALID_RTS_THRESHOLD(value))
goto error; goto error;
qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value); qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value);
cNum = STR_RTS_THRESHOLD_IN_INI;
ini = INI_CONF_FILE;
break; break;
case eCMD_GTK_TIMEOUT: case eCMD_GTK_TIMEOUT:
@@ -2995,6 +2933,7 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
value = atoi(pVal); value = atoi(pVal);
if(TRUE != IS_VALID_TX_POWER(value)) if(TRUE != IS_VALID_TX_POWER(value))
goto error; goto error;
qsap_set_ini_filename();
qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value); qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value);
cNum = STR_TX_POWER_IN_INI; cNum = STR_TX_POWER_IN_INI;
ini = INI_CONF_FILE; ini = INI_CONF_FILE;
@@ -3043,32 +2982,19 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
cNum = STR_AP_ENERGY_DETECT_TH; cNum = STR_AP_ENERGY_DETECT_TH;
ini = INI_CONF_FILE; ini = INI_CONF_FILE;
break; break;
case eCMD_IEEE80211H:
value = atoi(pVal);
if(TRUE != IS_VALID_DFS_STATE(value))
goto error;
qsap_scnprintf(pVal, strlen(pVal)+1, "%ld", value);
break;
case eCMD_SET_CHANNEL_RANGE: case eCMD_SET_CHANNEL_RANGE:
ALOGE("eCMD_SET_CHANNEL_RANGE pcmd :%s\n", pcmd); ALOGE("eCMD_SET_CHANNEL_RANGE pcmd :%s\n", pcmd);
value = qsap_set_channel_range(pcmd); value = qsap_set_channel_range(pcmd);
*plen = qsap_scnprintf(presp, *plen, "%s", (value == eSUCCESS) ? SUCCESS : *plen = qsap_scnprintf(presp, *plen, "%s", (value == eSUCCESS) ? SUCCESS :
ERR_UNKNOWN); ERR_UNKNOWN);
return; return;
case eCMD_SSID2:
/* Disable ssid while setting ssid2 */
qsap_change_cfg(pcfg, &cmd_list[eCMD_SSID], DISABLE);
break;
default: ; default: ;
/** Do not goto error, in default case */ /** Do not goto error, in default case */
} }
if(ini == INI_CONF_FILE) { if(ini == INI_CONF_FILE) {
ALOGD("WRITE TO INI FILE :%s\n", qsap_str[cNum].name); ALOGV("WRITE TO INI FILE :%s\n", qsap_str[cNum].name);
qsap_write_cfg(fIni, &qsap_str[cNum], pVal, presp, plen, ini); qsap_write_cfg(fIni, &qsap_str[cNum], pVal, presp, plen, ini);
} }
else { else {
@@ -3097,23 +3023,11 @@ error:
*/ */
void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen) void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen)
{ {
ALOGD("CMD INPUT [%s][%lu]\n", pcmd, *plen); ALOGV("CMD INPUT [%s][%lu]\n", pcmd, *plen);
/* Skip any blank spaces */ /* Skip any blank spaces */
SKIP_BLANK_SPACE(pcmd); SKIP_BLANK_SPACE(pcmd);
if(!(strncmp(pcmd, Cmd_req[eCMD_SET], strlen(Cmd_req[eCMD_SET])))) {
if(!(strncmp(pcmd+4, Conf_req[CONF_2g], strlen(Conf_req[CONF_2g])))) {
pconffile = CONFIG_FILE_2G;
} else if (!(strncmp(pcmd+4, Conf_req[CONF_5g], strlen(Conf_req[CONF_5g])))) {
pconffile = CONFIG_FILE_5G;
} else {
pconffile = CONFIG_FILE;
}
}
check_for_configuration_files(); check_for_configuration_files();
if(fIni == NULL)
qsap_set_ini_filename();
if(!strncmp(pcmd, Cmd_req[eCMD_GET], strlen(Cmd_req[eCMD_GET])) && isblank(pcmd[strlen(Cmd_req[eCMD_GET])])) { if(!strncmp(pcmd, Cmd_req[eCMD_GET], strlen(Cmd_req[eCMD_GET])) && isblank(pcmd[strlen(Cmd_req[eCMD_GET])])) {
qsap_handle_get_request(pcmd, presp, plen); qsap_handle_get_request(pcmd, presp, plen);
@@ -3127,20 +3041,18 @@ void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen)
*plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALIDREQ); *plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALIDREQ);
} }
ALOGD("CMD OUTPUT [%s]\nlen :%lu\n\n", presp, *plen); ALOGV("CMD OUTPUT [%s]\nlen :%lu\n\n", presp, *plen);
return; return;
} }
/* netd and Froyo Native UI specific API */ /* netd and Froyo Native UI specific API */
#define DEFAULT_INTFERACE "wlan0"
#define DEFAULT_SSID "SOFTAP_SSID" #define DEFAULT_SSID "SOFTAP_SSID"
#define DEFAULT_CHANNEL 4 #define DEFAULT_CHANNEL 4
#define DEFAULT_PASSPHRASE "12345678" #define DEFAULT_PASSPHRASE "12345678"
#define DEFAULT_AUTH_ALG 1 #define DEFAULT_AUTH_ALG 1
#define RECV_BUF_LEN 255 #define RECV_BUF_LEN 255
#define CMD_BUF_LEN 255 #define CMD_BUF_LEN 255
#define SET_BUF_LEN 15
/** Command input /** Command input
argv[3] = SSID, argv[3] = SSID,
@@ -3153,52 +3065,23 @@ int qsapsetSoftap(int argc, char *argv[])
{ {
char cmdbuf[CMD_BUF_LEN]; char cmdbuf[CMD_BUF_LEN];
char respbuf[RECV_BUF_LEN]; char respbuf[RECV_BUF_LEN];
u32 rlen = RECV_BUF_LEN; unsigned long int rlen = RECV_BUF_LEN;
int i; int i;
int hidden = 0; int hidden = 0;
int sec = SEC_MODE_NONE; int sec = SEC_MODE_NONE;
char setCmd[SET_BUF_LEN];
int offset = 0;
ALOGD("%s, %s, %s, %d\n", __FUNCTION__, argv[0], argv[1], argc); ALOGV("%s, %s, %s, %d\n", __FUNCTION__, argv[0], argv[1], argc);
for ( i=0; i<argc;i++) { for ( i=0; i<argc;i++) {
ALOGD("ARG: %d - %s\n", i+1, argv[i]); ALOGV("ARG: %d - %s\n", i+1, argv[i]);
} }
// check if 2nd arg is dual2g/dual5g
if (argc > 2) {
// just match 'dual'
if (strncmp(argv[2], Conf_req[CONF_2g], 4) == 0) {
snprintf(setCmd, SET_BUF_LEN, "set %s", argv[2]);
offset = 1;
argc--;
} else {
snprintf(setCmd, SET_BUF_LEN, "set");
offset = 0;
}
}
/* set interface */
if (argc > 2) {
snprintf(cmdbuf, CMD_BUF_LEN, "%s interface=%s", setCmd, argv[2 + offset]);
}
else {
snprintf(cmdbuf, CMD_BUF_LEN, "%s interface=%s", setCmd, DEFAULT_INTFERACE);
}
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
/** set SSID */ /** set SSID */
if(argc > 3) { if(argc > 3) {
// In case of dual2g/5g, Set ssid2 with hex values to accomodate sapce and special characters. qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set ssid=%s",argv[3]);
if (offset)
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s ssid2=%s", setCmd, argv[3 + offset]);
else
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s ssid=%s",setCmd, argv[3]);
} }
else { else {
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s ssid=%s_%d", setCmd, DEFAULT_SSID, rand()); qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set ssid=%s_%d", DEFAULT_SSID, rand());
} }
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen); (void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
@@ -3209,10 +3092,10 @@ int qsapsetSoftap(int argc, char *argv[])
rlen = RECV_BUF_LEN; rlen = RECV_BUF_LEN;
if (argc > 4) { if (argc > 4) {
if (strcmp(argv[4 + offset], "hidden") == 0) { if (strcmp(argv[4], "hidden") == 0) {
hidden = 1; hidden = 1;
} }
snprintf(cmdbuf, CMD_BUF_LEN, "%s ignore_broadcast_ssid=%d", setCmd, hidden); snprintf(cmdbuf, CMD_BUF_LEN, "set ignore_broadcast_ssid=%d", hidden);
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen); (void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
if(strncmp("success", respbuf, rlen) != 0) { if(strncmp("success", respbuf, rlen) != 0) {
ALOGE("Failed to set ignore_broadcast_ssid \n"); ALOGE("Failed to set ignore_broadcast_ssid \n");
@@ -3222,7 +3105,7 @@ int qsapsetSoftap(int argc, char *argv[])
/** channel */ /** channel */
rlen = RECV_BUF_LEN; rlen = RECV_BUF_LEN;
if(argc > 5) { if(argc > 5) {
snprintf(cmdbuf, CMD_BUF_LEN, "%s channel=%d", setCmd, atoi(argv[5 + offset])); snprintf(cmdbuf, CMD_BUF_LEN, "set channel=%d", atoi(argv[5]));
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen); (void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
if(strncmp("success", respbuf, rlen) != 0) { if(strncmp("success", respbuf, rlen) != 0) {
@@ -3236,22 +3119,22 @@ int qsapsetSoftap(int argc, char *argv[])
if(argc > 6) { if(argc > 6) {
/**TODO : need to identify the SEC strings for "wep", "wpa", "wpa2" */ /**TODO : need to identify the SEC strings for "wep", "wpa", "wpa2" */
if(!strcmp(argv[6 + offset], "open")) if(!strcmp(argv[6], "open"))
sec = SEC_MODE_NONE; sec = SEC_MODE_NONE;
else if(!strcmp(argv[6 + offset], "wep")) else if(!strcmp(argv[6], "wep"))
sec = SEC_MODE_WEP; sec = SEC_MODE_WEP;
else if(!strcmp(argv[6 + offset], "wpa-psk")) else if(!strcmp(argv[6], "wpa-psk"))
sec = SEC_MODE_WPA_PSK; sec = SEC_MODE_WPA_PSK;
else if(!strcmp(argv[6 + offset], "wpa2-psk")) else if(!strcmp(argv[6], "wpa2-psk"))
sec = SEC_MODE_WPA2_PSK; sec = SEC_MODE_WPA2_PSK;
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s security_mode=%d",setCmd, sec); qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set security_mode=%d",sec);
} }
else { else {
qsap_scnprintf(cmdbuf, sizeof(cmdbuf) , "%s security_mode=%d", setCmd, DEFAULT_AUTH_ALG); qsap_scnprintf(cmdbuf, sizeof(cmdbuf) , "set security_mode=%d", DEFAULT_AUTH_ALG);
} }
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen); (void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
@@ -3266,11 +3149,11 @@ int qsapsetSoftap(int argc, char *argv[])
if ( (sec == SEC_MODE_WPA_PSK) || (sec == SEC_MODE_WPA2_PSK) ) { if ( (sec == SEC_MODE_WPA_PSK) || (sec == SEC_MODE_WPA2_PSK) ) {
if(argc > 7) { if(argc > 7) {
/* If the input passphrase is more than 63 characters, consider first 63 characters only*/ /* If the input passphrase is more than 63 characters, consider first 63 characters only*/
if ( strlen(argv[7 + offset]) > 63 ) argv[7 + offset][63] = '\0'; if ( strlen(argv[7]) > 63 ) argv[7][63] = '\0';
qsap_scnprintf(cmdbuf, CMD_BUF_LEN, "%s wpa_passphrase=%s",setCmd, argv[7 + offset]); qsap_scnprintf(cmdbuf, CMD_BUF_LEN, "set wpa_passphrase=%s",argv[7]);
} }
else { else {
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s wpa_passphrase=%s", setCmd, DEFAULT_PASSPHRASE); qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set wpa_passphrase=%s", DEFAULT_PASSPHRASE);
} }
} }
@@ -3281,18 +3164,8 @@ int qsapsetSoftap(int argc, char *argv[])
} }
rlen = RECV_BUF_LEN; rlen = RECV_BUF_LEN;
if(argc > 8) {
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s max_num_sta=%d",setCmd, atoi(argv[8 + offset]));
}
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
if(strncmp("success", respbuf, rlen) != 0) { qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set commit");
ALOGE("Failed to set maximun client connections number \n");
return -1;
}
rlen = RECV_BUF_LEN;
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s commit", setCmd);
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen); (void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
@@ -3304,37 +3177,18 @@ int qsapsetSoftap(int argc, char *argv[])
return 0; return 0;
} }
static int check_for_config_file_size(FILE *fp)
{
int length = 0;
if( NULL != fp )
{
fseek(fp, 0L, SEEK_END);
length = ftell(fp);
}
return length;
}
void check_for_configuration_files(void) void check_for_configuration_files(void)
{ {
FILE * fp; FILE * fp;
char *pfile;
/* Check if configuration files are present, if not create the default files */ /* Check if configuration files are present, if not create the default files */
mkdir("/data/hostapd", 0771);
/* If configuration file does not exist copy the default file */ /* If configuration file does not exist copy the default file */
if ( NULL == (fp = fopen(pconffile, "r")) ) { if ( NULL == (fp = fopen(CONFIG_FILE, "r")) ) {
wifi_qsap_reset_to_default(pconffile, DEFAULT_CONFIG_FILE_PATH); wifi_qsap_reset_to_default(CONFIG_FILE, DEFAULT_CONFIG_FILE_PATH);
} }
else { else {
/* The configuration file could be of 0 byte size, replace with default */
if (check_for_config_file_size(fp) <= 0)
wifi_qsap_reset_to_default(pconffile, DEFAULT_CONFIG_FILE_PATH);
fclose(fp); fclose(fp);
} }
@@ -3343,39 +3197,17 @@ void check_for_configuration_files(void)
wifi_qsap_reset_to_default(ACCEPT_LIST_FILE, DEFAULT_ACCEPT_LIST_FILE_PATH); wifi_qsap_reset_to_default(ACCEPT_LIST_FILE, DEFAULT_ACCEPT_LIST_FILE_PATH);
} }
else { else {
/* The configuration file could be of 0 byte size, replace with default */
if (check_for_config_file_size(fp) <= 0)
wifi_qsap_reset_to_default(ACCEPT_LIST_FILE, DEFAULT_ACCEPT_LIST_FILE_PATH);
fclose(fp); fclose(fp);
} }
/* Provide read and write permissions to the owner */
pfile = ACCEPT_LIST_FILE;
if (chmod(pfile, 0660) < 0) {
ALOGE("Error changing permissions of %s to 0660: %s",
pfile, strerror(errno));
}
/* If deny MAC list file does not exist, copy the default file */ /* If deny MAC list file does not exist, copy the default file */
if ( NULL == (fp = fopen(DENY_LIST_FILE, "r")) ) { if ( NULL == (fp = fopen(DENY_LIST_FILE, "r")) ) {
wifi_qsap_reset_to_default(DENY_LIST_FILE, DEFAULT_DENY_LIST_FILE_PATH); wifi_qsap_reset_to_default(DENY_LIST_FILE, DEFAULT_DENY_LIST_FILE_PATH);
} }
else { else {
/* The configuration file could be of 0 byte size, replace with default */
if (check_for_config_file_size(fp) <= 0)
wifi_qsap_reset_to_default(DENY_LIST_FILE, DEFAULT_DENY_LIST_FILE_PATH);
fclose(fp); fclose(fp);
} }
/* Provide read and write permissions to the owner */
pfile = DENY_LIST_FILE;
if (chmod(pfile, 0660) < 0) {
ALOGE("Error changing permissions of %s to 0660: %s",
pfile, strerror(errno));
}
return; return;
} }
@@ -3388,196 +3220,3 @@ void qsap_set_ini_filename(void)
ALOGE("INI FILE PROP NOT PRESENT: Use default path %s\n", fIni); ALOGE("INI FILE PROP NOT PRESENT: Use default path %s\n", fIni);
return; return;
} }
// IOCTL command to create and delete bridge interface //
#ifndef SIOCBRADDBR
#define SIOCBRADDBR 0x89a0
#endif
#ifndef SIOCBRDELBR
#define SIOCBRDELBR 0x89a1
#endif
static int linux_set_iface_flags(int sock, const char *ifname, int dev_up)
{
struct ifreq ifr;
int ret;
if (sock < 0)
return -1;
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) {
ret = errno ? -errno : -999;
ALOGE("Could not read interface %s flags: %s",
ifname, strerror(errno));
return ret;
}
if (dev_up) {
if (ifr.ifr_flags & IFF_UP)
return 0;
ifr.ifr_flags |= IFF_UP;
} else {
if (!(ifr.ifr_flags & IFF_UP))
return 0;
ifr.ifr_flags &= ~IFF_UP;
}
if (ioctl(sock, SIOCSIFFLAGS, &ifr) != 0) {
ret = errno ? -errno : -999;
ALOGE("Could not set interface %s flags (%s): %s",
ifname, dev_up ? "UP" : "DOWN", strerror(errno));
return ret;
}
return 0;
}
int qsap_control_bridge(int argc, char ** argv)
{
int br_socket;
if (argc < 4) {
ALOGE("Command not supported");
return -1;
}
br_socket = socket(PF_INET, SOCK_DGRAM, 0);
if (br_socket < 0) {
ALOGE("socket(PF_INET,SOCK_DGRAM): %s",strerror(errno));
return -1;
}
if (!strncmp(argv[2],"create", 6)) {
if (ioctl(br_socket, SIOCBRADDBR, argv[3]) < 0) {
ALOGE("Could not add bridge %s: %s", argv[3], strerror(errno));
return -1;
}
} else if (!strncmp(argv[2],"remove", 6)) {
if (ioctl(br_socket, SIOCBRDELBR, argv[3]) < 0) {
ALOGE("Could not add remove %s: %s", argv[3], strerror(errno));
return -1;
}
} else if (!strncmp(argv[2],"up", 2)) {
return linux_set_iface_flags(br_socket, argv[3], 1);
} else if (!strncmp(argv[2],"down", 4)) {
return linux_set_iface_flags(br_socket, argv[3], 0);
} else {
ALOGE("Command %s not handled.", argv[2]);
return -1;
}
return 0;
}
int linux_get_ifhwaddr(const char *ifname, char *addr)
{
struct ifreq ifr;
int sock = socket(AF_INET, SOCK_DGRAM, 0);
#ifndef MAC2STR
#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
#endif
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(sock, SIOCGIFHWADDR, &ifr)) {
ALOGE("Could not get interface %s hwaddr: %s", ifname, strerror(errno));
return -1;
}
if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
ALOGE("%s: Invalid HW-addr family 0x%04x", ifname, ifr.ifr_hwaddr.sa_family);
return -1;
}
memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
ALOGE("%s: " MACSTR, ifname, MAC2STR(addr));
return 0;
}
int qsap_add_or_remove_interface(const char *newIface , int createIface)
{
const char *wlanIface = "wlan0";
int retVal = 0;
struct nl_msg *msg = NULL;
struct nl_cb *cb = NULL;
struct nl_cb *s_cb = NULL;
struct nl_sock *nl_sock = NULL;
int nl80211_id;
enum nl80211_iftype type = NL80211_IFTYPE_AP;
/* Allocate a netlink socket */
s_cb = nl_cb_alloc(NL_CB_DEFAULT);
if (!s_cb) {
ALOGE( "Failed to allocate Netlink Socket");
retVal = -ENOMEM;
goto nla_put_failure;
}
nl_sock = nl_socket_alloc_cb(s_cb);
if (!nl_sock) {
ALOGE( "Netlink socket Allocation failure");
retVal = -ENOMEM;
goto nla_put_failure;
}
/* connect to generic netlink socket */
if (genl_connect(nl_sock)) {
ALOGE( "Netlink socket Connection failure");
retVal = -ENOLINK;
goto nla_put_failure;
}
nl80211_id = genl_ctrl_resolve(nl_sock, "nl80211");
if (nl80211_id < 0) {
ALOGE( "nl80211 generic netlink not found");
retVal = -ENOENT;
goto nla_put_failure;
}
msg = nlmsg_alloc();
if(!msg) {
ALOGE( "Failed to allocate netlink message");
retVal = -ENOMEM;
goto nla_put_failure;
}
cb = nl_cb_alloc(NL_CB_DEFAULT);
if (!cb) {
ALOGE( "Failed to allocate netlink callback");
retVal = -ENOMEM;
goto nla_put_failure;
}
if (createIface == 1) {
/* Issue NL80211_CMD_NEW_INTERFACE */
genlmsg_put( msg, 0, 0, nl80211_id, 0, 0, NL80211_CMD_NEW_INTERFACE, 0);
nla_put_u32( msg, NL80211_ATTR_IFINDEX, if_nametoindex( wlanIface ));
NLA_PUT_STRING( msg, NL80211_ATTR_IFNAME, newIface);
nla_put_u32( msg, NL80211_ATTR_IFTYPE, type);
} else {
genlmsg_put( msg, 0, 0, nl80211_id, 0, 0, NL80211_CMD_DEL_INTERFACE, 0);
nla_put_u32( msg, NL80211_ATTR_IFINDEX, if_nametoindex( newIface ));
}
retVal = nl_send_auto_complete(nl_sock, msg );
if (retVal < 0 ) {
goto nla_put_failure;
}
else {
ALOGD("Interface %s is %s - Ok", (createIface == 1 ? "created":"removed") ,newIface);
}
nla_put_failure:
if (nl_sock)
nl_socket_free(nl_sock);
if (s_cb)
nl_cb_put(s_cb);
if (msg)
nlmsg_free(msg);
if (cb)
nl_cb_put(cb);
return retVal;
}

43
softap/sdk/qsap_api.h Executable file → Normal file
View File

@@ -34,13 +34,13 @@
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <android/log.h>
typedef unsigned char u8; typedef unsigned char u8;
typedef char s8; typedef char s8;
typedef unsigned short int u16; typedef unsigned short int u16;
typedef signed short int s16; typedef signed short int s16;
typedef unsigned int u32; typedef unsigned long int u32;
typedef signed int s32; typedef signed long int s32;
/** Success and error messages */ /** Success and error messages */
#define SUCCESS "success" #define SUCCESS "success"
@@ -88,10 +88,6 @@ enum error_val {
#define WIFI_DRIVER_DEF_CONF_FILE NULL #define WIFI_DRIVER_DEF_CONF_FILE NULL
#endif #endif
/** Configuration file name for SAP+SAP*/
#define CONFIG_FILE_2G "/data/vendor/wifi/hostapd_dual2g.conf"
#define CONFIG_FILE_5G "/data/vendor/wifi/hostapd_dual5g.conf"
/** Configuration file name */ /** Configuration file name */
#define CONFIG_FILE "/data/misc/wifi/hostapd.conf" #define CONFIG_FILE "/data/misc/wifi/hostapd.conf"
@@ -211,7 +207,7 @@ enum error_val {
#define MIN_UPC_LEN (1) #define MIN_UPC_LEN (1)
#define MAX_UPC_LEN (128) #define MAX_UPC_LEN (128)
#define GTK_MIN (30) #define GTK_MIN (600)
#define MAX_INT_STR (8) #define MAX_INT_STR (8)
@@ -248,14 +244,6 @@ enum eCmd_req {
eCMD_REQ_LAST eCMD_REQ_LAST
}; };
/** config request index - in the array Conf_req[] */
enum eConf_req {
CONF_2g = 0,
CONF_5g = 1,
CONF_REQ_LAST
};
/** /**
* Command numbers, these numbers form the index into the array of * Command numbers, these numbers form the index into the array of
* command names stored in the 'cmd_list'. * command names stored in the 'cmd_list'.
@@ -335,19 +323,6 @@ typedef enum esap_cmd {
eCMD_SET_CHANNEL_RANGE = 62, eCMD_SET_CHANNEL_RANGE = 62,
eCMD_GET_AUTO_CHANNEL = 63, eCMD_GET_AUTO_CHANNEL = 63,
eCMD_IEEE80211W = 64, eCMD_IEEE80211W = 64,
eCMD_WPA_KEY_MGMT = 65,
eCMD_SET_MAX_CLIENTS = 66,
eCMD_IEEE80211AC = 67,
eCMD_VHT_OPER_CH_WIDTH = 68,
eCMD_ACS_CHAN_LIST = 69,
eCMD_HT_CAPAB = 70,
eCMD_IEEE80211H = 71,
eCMD_ENABLE_WIGIG_SOFTAP = 72,
eCMD_INTERFACE = 73,
eCMD_SSID2 = 74,
eCMD_BRIDGE = 75,
eCMD_CTRL_INTERFACE = 76,
eCMD_LAST /** New command numbers should be added above this */ eCMD_LAST /** New command numbers should be added above this */
} esap_cmd_t; } esap_cmd_t;
@@ -599,15 +574,10 @@ typedef struct sap_auto_channel_info {
/** Validate the AP shutoff time */ /** Validate the AP shutoff time */
#define IS_VALID_ENERGY_DETECT_TH(x) ((((x >= AP_ENERGY_DETECT_TH_MIN) && (x <= AP_ENERGY_DETECT_TH_MAX)) ||( x == 128)) ? TRUE : FALSE) #define IS_VALID_ENERGY_DETECT_TH(x) ((((x >= AP_ENERGY_DETECT_TH_MIN) && (x <= AP_ENERGY_DETECT_TH_MAX)) ||( x == 128)) ? TRUE : FALSE)
/** Validate the 802dot11h state */
#define IS_VALID_DFS_STATE(x) (((x == ENABLE) || (x == DISABLE)) ? TRUE: FALSE)
/** Function declartion */ /** Function declartion */
int qsap_hostd_exec(int argc, char ** argv);
void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen); void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen);
s8 *qsap_get_config_value(s8 *pfile, struct Command *pcmd, s8 *pbuf, u32 *plen); s8 *qsap_get_config_value(s8 *pfile, struct Command *pcmd, s8 *pbuf, u32 *plen);
int qsapsetSoftap(int argc, char *argv[]); int qsapsetSoftap(int argc, char *argv[]);
int qsap_add_or_remove_interface(const char *iface_name, int create_iface);
void qsap_del_ctrl_iface(void); void qsap_del_ctrl_iface(void);
s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault); s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault);
void check_for_configuration_files(void); void check_for_configuration_files(void);
@@ -615,11 +585,6 @@ void qsap_set_ini_filename(void);
int qsap_set_channel_range(s8 * cmd); int qsap_set_channel_range(s8 * cmd);
int qsap_get_sap_auto_channel_slection(s32 *pautochan); int qsap_get_sap_auto_channel_slection(s32 *pautochan);
int qsap_get_mode(s32 *pmode); int qsap_get_mode(s32 *pmode);
int qsap_prepare_softap(void);
int qsap_unprepare_softap(void);
int qsap_is_fst_enabled(void);
int qsap_control_bridge(int argc, char ** argv);
int linux_get_ifhwaddr(const char *ifname, char *addr);
#if __cplusplus #if __cplusplus
}; // extern "C" }; // extern "C"