Compare commits

..

4 Commits

Author SHA1 Message Date
Skrilax_CZ
7bebb68631 Implement wifi_qsap_set_tx_power
Used by radio proprietary binaries from Motorola.

Change-Id: I9fd49cbba6001a4c7ddadf5cb88df06d6146f01a
2016-09-04 02:53:51 -07:00
Steve Kondik
ed3a0c2a26 qsap: Kill more logspam
Change-Id: I0a32abbf783ffb1534051fd89708d2a49014c6c3
2016-09-01 09:59:09 -07:00
Steve Kondik
fc4e0df7b2 qsap: Put files in a sane location
* And set their perms

Change-Id: Ifc61a3504433f6b7e1602432ecea70c37785c895
2016-09-01 09:59:09 -07:00
Steve Kondik
31e1ef0ca4 qsap: Don't log sensitive information
Change-Id: I3ab6d73051d4647941de6eee41c2b5507c5eddc6
2016-09-01 09:59:09 -07:00
6 changed files with 149 additions and 237 deletions

View File

@@ -15,6 +15,6 @@ LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include \
$(JNI_H_INCLUDE)
LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
LOCAL_SHARED_LIBRARIES := libsysutils libcutils libnetutils libcrypto liblog
LOCAL_SHARED_LIBRARIES := libsysutils libcutils libnetutils libcrypto
include $(BUILD_SHARED_LIBRARY)

View File

@@ -12,8 +12,6 @@ LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -DSDK_VERSION=\"0.0.1.0\"
LOCAL_USE_VNDK := true
LOCAL_COPY_HEADERS_TO := sdk/softap/include
LOCAL_COPY_HEADERS := qsap_api.h
LOCAL_COPY_HEADERS += qsap.h
@@ -63,7 +61,7 @@ LOCAL_SRC_FILES := qsap_api.c \
LOCAL_PRELINK_MODULE := false
LOCAL_SHARED_LIBRARIES := libnetutils libutils libbinder libcutils libhardware_legacy libnl liblog
LOCAL_SHARED_LIBRARIES := libnetutils libutils libbinder libcutils libhardware_legacy libnl
include $(BUILD_SHARED_LIBRARY)

View File

@@ -54,6 +54,7 @@
#include "qsap_api.h"
#include "qsap.h"
#include "wifi_fst.h"
#include <sys/system_properties.h>
@@ -695,3 +696,62 @@ s32 wifi_qsap_stop_wigig_softap(void)
usleep(AP_BSS_STOP_DELAY);
return eSUCCESS;
}
int qsap_prepare_softap()
{
ALOGD("Starting fstman\n");
return wifi_start_fstman(TRUE);
}
int qsap_unprepare_softap()
{
ALOGD("Stopping fstman\n");
return wifi_stop_fstman(TRUE);
}
int qsap_is_fst_enabled()
{
return is_fst_enabled();
}
s32 wifi_qsap_set_tx_power(s32 tx_power)
{
#define QCSAP_IOCTL_SET_MAX_TX_POWER (SIOCIWFIRSTPRIV + 22)
s32 sock;
s32 ret = eERR_SET_TX_POWER;
s8 interface[128];
s8 *iface;
s32 len = 128;
struct iwreq wrq;
if(NULL == (iface = qsap_get_config_value(CONFIG_FILE, &qsap_str[STR_INTERFACE], interface, (u32*)&len))) {
ALOGE("%s :interface error \n", __func__);
return ret;
}
/* Issue QCSAP_IOCTL_SET_MAX_TX_POWER ioctl */
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
ALOGE("%s :socket error \n", __func__);
return eERR_SET_TX_POWER;
}
strlcpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
wrq.u.data.length = sizeof(s32);
wrq.u.data.pointer = &tx_power;
wrq.u.data.flags = 0;
ret = ioctl(sock, QCSAP_IOCTL_SET_MAX_TX_POWER, &wrq);
close(sock);
if (ret) {
ALOGE("%s :IOCTL set tx power failed: %ld\n", __func__, ret);
ret = eERR_SET_TX_POWER;
} else {
ALOGD("%s :IOCTL set tx power issued\n", __func__);
ret = eSUCCESS;
}
return ret;
}

View File

@@ -54,6 +54,8 @@ s32 wifi_qsap_start_softap_in_concurrency(void);
s32 wifi_qsap_stop_softap_in_concurrency(void);
#endif
s32 wifi_qsap_set_tx_power(s32);
#if __cplusplus
}; // extern "C"
#endif

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

@@ -45,7 +45,6 @@
#include <unistd.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>
@@ -65,7 +64,7 @@
#define QCSAP_PARAM_GET_AUTO_CHANNEL 9
#define WE_SET_SAP_CHANNELS 3
#define LOG_TAG "QCSDK"
//#define LOG_TAG "QCSDK-"
#include "cutils/properties.h"
#include "cutils/log.h"
@@ -85,15 +84,6 @@ s8 *Cmd_req[eCMD_REQ_LAST] = {
"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
* qsap_api.h must be updates to reflect the changes
@@ -177,9 +167,6 @@ static struct Command cmd_list[eCMD_LAST] = {
{ "ieee80211h", NULL },
{ "enable_wigig_softap", NULL },
{ "interface", NULL },
{ "ssid2", NULL },
{ "bridge", NULL },
{ "ctrl_interface", NULL },
};
struct Command qsap_str[eSTR_LAST] = {
@@ -260,9 +247,6 @@ static s32 qsap_read_cfg(s8 *pfile, struct Command * pcmd, s8 *presp, u32 *plen,
while(NULL != fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
s8 *pline = buf;
if (strlen(buf) == 0)
continue;
/** Skip the commented lines */
if(buf[0] == '#') {
if (ignore_comment) {
@@ -335,7 +319,7 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
s8 buf[MAX_CONF_LINE_LEN+1];
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 */
fcfg = fopen(pfile, "r");
@@ -370,7 +354,7 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
if(pline[len] == '=') {
qsap_scnprintf(buf, sizeof(buf), "%s=%s\n", pcmd->name, pVal);
result = TRUE;
ALOGD("Updated:%s\n", buf);
ALOGV("Updated:%s\n", buf);
}
}
@@ -385,7 +369,7 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
/* Add the new line at the end of file */
qsap_scnprintf(buf, sizeof(buf), "%s=%s\n", pcmd->name, pVal);
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) {
@@ -415,6 +399,14 @@ static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp,
unlink(pfile);
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)
return eERR_FEATURE_NOT_ENABLED;
@@ -560,6 +552,14 @@ static s32 qsap_change_cfg(s8 *pfile, struct Command * pcmd, u32 status)
unlink(pfile);
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;
}
@@ -980,7 +980,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)
{
ALOGD("%s : Updating file %s \n", __func__, pfile);
ALOGV("%s : Updating file %s \n", __func__, pfile);
switch(cNum) {
case eCMD_ADD_TO_ALLOW:
@@ -1135,7 +1135,7 @@ static int qsap_read_mac_address(s8 *presp, u32 *plen)
ptr++;
ALOGD("MAC :%s \n", ptr);
ALOGV("MAC :%s \n", ptr);
if(TRUE == isValid_MAC_address(ptr)) {
nRet = eSUCCESS;
}
@@ -1171,7 +1171,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))) {
/** 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;
}
else {
@@ -1226,9 +1226,9 @@ int qsap_get_operating_channel(s32 *pchan)
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]);
ALOGE("Operating channel :%ld \n", *pchan);
ALOGV("Operating channel :%ld \n", *pchan);
close(sock);
return eSUCCESS;
@@ -1259,7 +1259,7 @@ int qsap_get_sap_auto_channel_selection(s32 *pautochan)
if(NULL == (pif = qsap_get_config_value(pconffile,
&qsap_str[STR_INTERFACE], interface, &len))) {
ALOGD("%s :interface error \n", __func__);
ALOGV("%s :interface error \n", __func__);
goto error;
}
@@ -1267,7 +1267,7 @@ int qsap_get_sap_auto_channel_selection(s32 *pautochan)
sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock < 0) {
ALOGD("%s :socket error \n", __func__);
ALOGV("%s :socket error \n", __func__);
goto error;
}
@@ -1290,9 +1290,9 @@ int qsap_get_sap_auto_channel_selection(s32 *pautochan)
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]);
ALOGD("Sap auto channel selection pautochan=%ld \n", *pautochan);
ALOGV("Sap auto channel selection pautochan=%ld \n", *pautochan);
close(sock);
return eSUCCESS;
@@ -1320,7 +1320,7 @@ int qsap_get_mode(s32 *pmode)
*pmode = -1;
if(NULL == (pif = qsap_get_config_value(pconffile,
&qsap_str[STR_INTERFACE], interface, &len))) {
ALOGD("%s :interface error \n", __func__);
ALOGV("%s :interface error \n", __func__);
goto error;
}
@@ -1328,7 +1328,7 @@ int qsap_get_mode(s32 *pmode)
sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock < 0) {
ALOGD("%s :socket error \n", __func__);
ALOGV("%s :socket error \n", __func__);
goto error;
}
@@ -1432,7 +1432,7 @@ int qsap_set_channel_range(s8 *buf)
goto error;
}
ALOGE("Recv len :%d\n", wrq.u.data.length);
ALOGV("Recv len :%d\n", wrq.u.data.length);
close(sock);
return eSUCCESS;
@@ -1450,7 +1450,7 @@ int qsap_read_channel(s8 *pfile, struct Command *pcmd, s8 *presp, u32 *plen, s8
if(eSUCCESS == qsap_get_operating_channel(&chan)) {
*plen = qsap_scnprintf(presp, len, "%s %s=%lu", SUCCESS, pcmd->name, chan);
ALOGD("presp :%s\n", presp);
ALOGV("presp :%s\n", presp);
} else {
*plen = qsap_scnprintf(presp, len, "%s", ERR_UNKNOWN);
}
@@ -1931,7 +1931,7 @@ static s16 is_valid_wep_key(s8 *pwep, s8 *pkey, s16 len)
weplen--;
while(weplen--) {
if(0 == isascii(pwep[weplen])) {
ALOGD("%c not ascii \n", pwep[weplen]);
ALOGV("%c not ascii \n", pwep[weplen]);
return FALSE;
}
}
@@ -1990,6 +1990,11 @@ s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault)
if(eERR_UNKNOWN == rename(buf, pcfgfile))
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 */
unlink(buf);
@@ -2072,7 +2077,7 @@ static int qsap_send_cmd_to_hostapd(s8 *pcmd)
goto error;
}
ALOGD("Connect to :%s\n", ptr);
ALOGV("Connect to :%s\n", ptr);
sock = socket(PF_UNIX, SOCK_DGRAM, 0);
if(sock < 0) {
@@ -2092,7 +2097,7 @@ static int qsap_send_cmd_to_hostapd(s8 *pcmd)
ser.sun_family = AF_UNIX;
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));
if(ret < 0) {
@@ -2247,7 +2252,7 @@ static void qsap_config_wps_method(s8 *pVal, s8 *presp, u32 *plen)
qsap_scnprintf(buf, sizeof(buf), "WPS_PBC");
else {
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);
return;
}
@@ -2439,7 +2444,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);
/* fall through */
case HW_MODE_N:
case HW_MODE_G:
case HW_MODE_A:
ulen = *tlen;
qsap_write_cfg(pcfg, &cmd_list[eCMD_IEEE80211N],ieee11n_enable, tbuf, &ulen, HOSTAPD_CONF_QCOM_FILE);
@@ -2529,15 +2533,6 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
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);
if(cNum == eCMD_INVALID) {
*plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALID_ARG);
@@ -2547,7 +2542,7 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
pVal = pcmd + strlen(cmd_list[cNum].name);
if( (cNum != eCMD_COMMIT) &&
(cNum != eCMD_RESET_TO_DEFAULT) &&
((*pVal != '=') || (((eCMD_PASSPHRASE != cNum)) && (strlen(pVal) < 2)))) {
((*pVal != '=') || (strlen(pVal) < 2)) ) {
*plen = qsap_scnprintf(presp, *plen, "%s", ERR_INVALID_ARG);
return;
}
@@ -2670,8 +2665,6 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
value = strlen(pVal);
if(SSD_MAX_LEN < value)
goto error;
/* Disable ssid2 while setting ssid */
qsap_change_cfg(pcfg, &cmd_list[eCMD_SSID2], DISABLE);
break;
case eCMD_SET_MAX_CLIENTS:
@@ -3061,17 +3054,13 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen)
*plen = qsap_scnprintf(presp, *plen, "%s", (value == eSUCCESS) ? SUCCESS :
ERR_UNKNOWN);
return;
case eCMD_SSID2:
/* Disable ssid while setting ssid2 */
qsap_change_cfg(pcfg, &cmd_list[eCMD_SSID], DISABLE);
break;
default: ;
/** Do not goto error, in default case */
}
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);
}
else {
@@ -3100,20 +3089,10 @@ error:
*/
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_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();
if(fIni == NULL)
qsap_set_ini_filename();
@@ -3130,7 +3109,7 @@ void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen)
*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;
}
@@ -3143,7 +3122,6 @@ void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen)
#define DEFAULT_AUTH_ALG 1
#define RECV_BUF_LEN 255
#define CMD_BUF_LEN 255
#define SET_BUF_LEN 15
/** Command input
argv[3] = SSID,
@@ -3160,42 +3138,29 @@ int qsapsetSoftap(int argc, char *argv[])
int i;
int hidden = 0;
int sec = SEC_MODE_NONE;
char setCmd[SET_BUF_LEN] = "set";
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++) {
ALOGD("ARG: %d - %s\n", i+1, argv[i]);
}
// check if 2nd arg is dual2g/dual5g
if (argc > 2 && (strncmp(argv[2], Conf_req[CONF_2g], 4) == 0)) {
snprintf(setCmd, SET_BUF_LEN, "set %s", argv[2]);
offset = 1;
argc--;
ALOGV("ARG: %d - %s\n", i+1, argv[i]);
}
/* set interface */
if (argc > 2) {
snprintf(cmdbuf, CMD_BUF_LEN, "%s interface=%s", setCmd, argv[2 + offset]);
snprintf(cmdbuf, CMD_BUF_LEN, "set interface=%s",argv[2]);
}
else {
snprintf(cmdbuf, CMD_BUF_LEN, "%s interface=%s", setCmd, DEFAULT_INTFERACE);
snprintf(cmdbuf, CMD_BUF_LEN, "set interface=%s", DEFAULT_INTFERACE);
}
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
/** set SSID */
if(argc > 3) {
// In case of dual2g/5g, Set ssid2 with hex values to accomodate sapce and special characters.
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]);
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set ssid=%s",argv[3]);
}
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);
@@ -3206,10 +3171,10 @@ int qsapsetSoftap(int argc, char *argv[])
rlen = RECV_BUF_LEN;
if (argc > 4) {
if (strcmp(argv[4 + offset], "hidden") == 0) {
if (strcmp(argv[4], "hidden") == 0) {
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);
if(strncmp("success", respbuf, rlen) != 0) {
ALOGE("Failed to set ignore_broadcast_ssid \n");
@@ -3219,7 +3184,7 @@ int qsapsetSoftap(int argc, char *argv[])
/** channel */
rlen = RECV_BUF_LEN;
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);
if(strncmp("success", respbuf, rlen) != 0) {
@@ -3233,22 +3198,22 @@ int qsapsetSoftap(int argc, char *argv[])
if(argc > 6) {
/**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;
else if(!strcmp(argv[6 + offset], "wep"))
else if(!strcmp(argv[6], "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;
else if(!strcmp(argv[6 + offset], "wpa2-psk"))
else if(!strcmp(argv[6], "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 {
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);
@@ -3263,11 +3228,11 @@ int qsapsetSoftap(int argc, char *argv[])
if ( (sec == SEC_MODE_WPA_PSK) || (sec == SEC_MODE_WPA2_PSK) ) {
if(argc > 7) {
/* 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';
qsap_scnprintf(cmdbuf, CMD_BUF_LEN, "%s wpa_passphrase=%s",setCmd, argv[7 + offset]);
if ( strlen(argv[7]) > 63 ) argv[7][63] = '\0';
qsap_scnprintf(cmdbuf, CMD_BUF_LEN, "set wpa_passphrase=%s",argv[7]);
}
else {
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s wpa_passphrase=%s", setCmd, DEFAULT_PASSPHRASE);
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set wpa_passphrase=%s", DEFAULT_PASSPHRASE);
}
}
@@ -3279,7 +3244,7 @@ int qsapsetSoftap(int argc, char *argv[])
rlen = RECV_BUF_LEN;
if(argc > 8) {
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s max_num_sta=%d",setCmd, atoi(argv[8 + offset]));
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set max_num_sta=%d",atoi(argv[8]));
}
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
@@ -3289,7 +3254,7 @@ int qsapsetSoftap(int argc, char *argv[])
}
rlen = RECV_BUF_LEN;
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "%s commit", setCmd);
qsap_scnprintf(cmdbuf, sizeof(cmdbuf), "set commit");
(void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen);
@@ -3323,14 +3288,14 @@ void check_for_configuration_files(void)
/* Check if configuration files are present, if not create the default files */
/* If configuration file does not exist copy the default file */
if ( NULL == (fp = fopen(pconffile, "r")) ) {
wifi_qsap_reset_to_default(pconffile, DEFAULT_CONFIG_FILE_PATH);
if ( NULL == (fp = fopen(CONFIG_FILE, "r")) ) {
wifi_qsap_reset_to_default(CONFIG_FILE, DEFAULT_CONFIG_FILE_PATH);
}
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);
wifi_qsap_reset_to_default(CONFIG_FILE, DEFAULT_CONFIG_FILE_PATH);
fclose(fp);
}
@@ -3354,6 +3319,12 @@ void check_for_configuration_files(void)
ALOGE("Error changing permissions of %s to 0660: %s",
pfile, strerror(errno));
}
if (chown(pfile, AID_SYSTEM, AID_WIFI) < 0) {
ALOGE("Error changing group ownership of %s to %d: %s",
pfile, AID_WIFI, strerror(errno));
}
/* If deny MAC list file does not exist, copy the default file */
if ( NULL == (fp = fopen(DENY_LIST_FILE, "r")) ) {
wifi_qsap_reset_to_default(DENY_LIST_FILE, DEFAULT_DENY_LIST_FILE_PATH);
@@ -3373,6 +3344,12 @@ void check_for_configuration_files(void)
ALOGE("Error changing permissions of %s to 0660: %s",
pfile, strerror(errno));
}
if (chown(pfile, AID_SYSTEM, AID_WIFI) < 0) {
ALOGE("Error changing group ownership of %s to %d: %s",
pfile, AID_WIFI, strerror(errno));
}
return;
}
@@ -3386,115 +3363,6 @@ void qsap_set_ini_filename(void)
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";

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

@@ -34,7 +34,7 @@
#if __cplusplus
extern "C" {
#endif
#include <android/log.h>
typedef unsigned char u8;
typedef char s8;
typedef unsigned short int u16;
@@ -77,7 +77,8 @@ enum error_val {
eERR_LOAD_FAILED_SDIOIF,
eERR_LOAD_FAILED_SOFTAP,
eERR_SET_CHAN_RANGE,
eERR_GET_AUTO_CHAN
eERR_GET_AUTO_CHAN,
eERR_SET_TX_POWER
};
#ifndef WIFI_DRIVER_CONF_FILE
@@ -88,10 +89,6 @@ enum error_val {
#define WIFI_DRIVER_DEF_CONF_FILE NULL
#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 */
#define CONFIG_FILE "/data/misc/wifi/hostapd.conf"
@@ -248,14 +245,6 @@ enum eCmd_req {
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 names stored in the 'cmd_list'.
@@ -345,9 +334,6 @@ typedef enum esap_cmd {
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 */
} esap_cmd_t;
@@ -509,7 +495,7 @@ typedef struct sap_auto_channel_info {
#define IS_VALID_BSSID(x) (((value == ENABLE) || (value == DISABLE)) ? TRUE: FALSE)
/** Validate the length of the passphrase */
#define IS_VALID_PASSPHRASE_LEN(x) ((((x >= PASSPHRASE_MIN) && (x <= PASSPHRASE_MAX)) || (x == 0)) ? TRUE: FALSE)
#define IS_VALID_PASSPHRASE_LEN(x) (((x >= PASSPHRASE_MIN) && (x <= PASSPHRASE_MAX)) ? TRUE: FALSE)
/** Validate the beacon interval */
#define IS_VALID_BEACON(x) (((x >= BCN_INTERVAL_MIN) && (x <= BCN_INTERVAL_MAX)) ? TRUE: FALSE)
@@ -618,8 +604,6 @@ 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
}; // extern "C"