From ae27f82145e987ccb3f50193273d8bda81b3169b Mon Sep 17 00:00:00 2001 From: Raj Kushwaha Date: Sun, 14 Nov 2010 17:47:11 -0800 Subject: [PATCH] Fixing following issues: Editing config values in Qocm_cfg.ini disables "save settings" option on GUI. After fastboot, when SoftAP turned ON first time beacon shows WMM and Country elements info but SoftAP UI shows these options as disabled After selecting the save-settings button GUI was always sending the command to change the energy_detect_threshold. Code is updated to send it only if energy_detect_threshold is changed Bug fixed to return correct security mode Error happened after saving the SoftAP configuration CRs-Fixed: 260651 261515 261401 Change-Id: Ic9454c35eeaa23ccc8b6e340695b4c41bca28b47 --- softap/jni/QWiFiSoftApCfg.c | 3 +- softap/sdk/Android.mk | 2 + softap/sdk/qsap.c | 15 +- softap/sdk/qsap_api.c | 494 +++++++++++++++++++----------------- softap/sdk/qsap_api.h | 36 ++- 5 files changed, 301 insertions(+), 249 deletions(-) diff --git a/softap/jni/QWiFiSoftApCfg.c b/softap/jni/QWiFiSoftApCfg.c index 87bd3c9..cc41f41 100644 --- a/softap/jni/QWiFiSoftApCfg.c +++ b/softap/jni/QWiFiSoftApCfg.c @@ -348,8 +348,7 @@ JNIEXPORT jstring JNICALL goto end; } - LOGW("netd might have crashed, wait for it to " - "start back\n"); + LOGW("Unable to connect to netd, retrying ...\n"); sleep(1); } else { break; diff --git a/softap/sdk/Android.mk b/softap/sdk/Android.mk index 5373712..57dccec 100644 --- a/softap/sdk/Android.mk +++ b/softap/sdk/Android.mk @@ -8,6 +8,8 @@ LOCAL_C_INCLUDES := LOCAL_MODULE:= libqsap_sdk +LOCAL_CFLAGS += -DSDK_VERSION=\"0.0.1.0\" + ifdef WIFI_DRIVER_MODULE_PATH LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_PATH=\"$(WIFI_DRIVER_MODULE_PATH)\" endif diff --git a/softap/sdk/qsap.c b/softap/sdk/qsap.c index 6c37c22..c5ed607 100644 --- a/softap/sdk/qsap.c +++ b/softap/sdk/qsap.c @@ -87,6 +87,8 @@ extern int init_module(const char *name, u32, const s8 *); extern int delete_module(const char *name, int); +extern struct Command qsap_str[]; + static s32 check_driver_loaded( const s8 * tag) { FILE *proc; @@ -306,7 +308,7 @@ s32 wifi_qsap_stop_bss(void) return ret; } - if(NULL == (iface = qsap_get_config_value(CONFIG_FILE, "interface", interface, (u32*)&len))) { + if(NULL == (iface = qsap_get_config_value(CONFIG_FILE, &qsap_str[STR_INTERFACE], interface, (u32*)&len))) { LOGE("%s :interface error \n", __func__); return ret; } @@ -384,15 +386,24 @@ s32 commit(void) s32 wifi_qsap_start_softap() { s32 retry = 4; + FILE * fp; LOGD("Starting Soft AP...\n"); + /* Check if configuration files are present, if not create the default files */ + check_for_configuration_files(); + /* Delete control interface if it was left over because of previous crash */ if ( !is_softap_enabled() ) { qsap_del_ctrl_iface(); } - while(--retry ) { + while(retry--) { + /* May be the configuration file is corrupted or not available, */ + /* copy the default configuration file */ + if ( retry == 1 ) + wifi_qsap_reset_to_default(CONFIG_FILE, DEFAULT_CONFIG_FILE_PATH); + /** Stop hostapd */ if(0 != property_set("ctl.start", "hostapd")) { LOGE("failed \n"); diff --git a/softap/sdk/qsap_api.c b/softap/sdk/qsap_api.c index 6e998eb..e93fb93 100644 --- a/softap/sdk/qsap_api.c +++ b/softap/sdk/qsap_api.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -74,92 +75,92 @@ s8 *Cmd_req[eCMD_REQ_LAST] = { * WARNING: On updating the cmd_list, the enum esap_cmd in file * qsap_api.h must be updates to reflect the changes */ -static s8 *cmd_list[eCMD_LAST] = { - "ssid", - "ignore_broadcast_ssid", - "channel", - "beacon_int", - "dtim_period", - "hw_mode", - "auth_algs", - "security_mode", - "wep_key0", - "wep_key1", - "wep_key2", - "wep_key3", - "wep_default_key", - "wpa_passphrase", - "wpa_pairwise", - "rsn_pairwise", - "mac_address", - "reset_ap", - "macaddr_acl", - "add_to_allow_list", - "add_to_deny_list", - "remove_from_allow_list", - "remove_from_deny_list", - "allow_list", - "deny_list", - "commit", - "enable_softap", - "disassoc_sta", - "reset_to_default", - "protection_flag", - "data_rate", - "sta_mac_list", - "tx_power", - "sdk_version", - "wmm_enabled", +static struct Command cmd_list[eCMD_LAST] = { + { "ssid", "QualcommSoftAP" }, + { "ignore_broadcast_ssid", "0" }, + { "channel", "1" }, + { "beacon_int", "100" }, + { "dtim_period", "2" }, + { "hw_mode", "n" }, + { "auth_algs", "3" }, + { "security_mode", "0" }, + { "wep_key0", NULL }, + { "wep_key1", NULL }, + { "wep_key2", NULL }, + { "wep_key3", NULL }, + { "wep_default_key", NULL }, + { "wpa_passphrase", NULL }, + { "wpa_pairwise", NULL }, + { "rsn_pairwise", NULL }, + { "mac_address", "00deadbeef04" }, + { "reset_ap", NULL }, + { "macaddr_acl", "0" }, + { "add_to_allow_list", NULL }, + { "add_to_deny_list", NULL }, + { "remove_from_allow_list", NULL }, + { "remove_from_deny_list", NULL }, + { "allow_list", "" }, + { "deny_list", "" }, + { "commit", NULL }, + { "enable_softap", NULL }, + { "disassoc_sta", NULL }, + { "reset_to_default", NULL }, + { "protection_flag", "1" }, + { "data_rate", "0" }, + { "sta_mac_list", NULL }, + { "tx_power", "27" }, + { "sdk_version", SDK_VERSION }, + { "wmm_enabled", "0" }, /** Warning: Do not change the order of the WPS commands */ - "wps_state", - "config_methods", - "uuid", - "device_name", - "manufacturer", - "model_name", - "model_number", - "serial_number", - "device_type", - "os_version", - "friendly_name", - "manufacturer_url", - "model_description", - "model_url", - "upc", + { "wps_state", "0" }, + { "config_methods", NULL }, + { "uuid", NULL }, + { "device_name", NULL }, + { "manufacturer", NULL }, + { "model_name", NULL }, + { "model_number", NULL }, + { "serial_number", NULL }, + { "device_type", NULL }, + { "os_version", NULL }, + { "friendly_name", NULL }, + { "manufacturer_url", NULL }, + { "model_description", NULL }, + { "model_url", NULL }, + { "upc", NULL }, /************ WPS commands end *********/ - "fragm_threshold", - "rts_threshold", - "wpa_group_rekey", - "country_code", - "intra_bss_forward", - "regulatory_domain", - "apstat", - "auto_shut_off_time", - "energy_detect_threshold", + { "fragm_threshold", NULL }, + { "rts_threshold", NULL }, + { "wpa_group_rekey", NULL }, + { "country_code", NULL }, + { "intra_bss_forward", NULL }, + { "regulatory_domain", NULL }, + { "apstat", NULL }, + { "auto_shut_off_time", NULL }, + { "energy_detect_threshold", "128" }, }; -static s8 *qsap_str[eSTR_LAST] = { - "wpa", - "accept_mac_file", - "deny_mac_file", - "gAPMacAddr", /** AP MAC address */ - "gEnableApProt", /** protection flag in ini file */ - "gFixedRate", /** Fixed rate in ini */ - "gTxPowerCap", /** Tx power in ini */ - "gFragmentationThreshold", /** Fragmentation threshold in ini */ - "RTSThreshold", /** RTS threshold in ini */ - "gAPCntryCode", /** Country code in ini */ - "gDisableIntraBssFwd", /** Intra-bss forward in ini */ - "WmmIsEnabled", /** WMM */ - "g11dSupportEnabled", /** 802.11d support */ - "ieee80211n", - "ctrl_interface", - "interface", - "eap_server", - "gAPAutoShutOff", - "gEnablePhyAgcListenMode", +struct Command qsap_str[eSTR_LAST] = { + { "wpa", NULL }, + { "accept_mac_file", NULL }, + { "deny_mac_file", NULL }, + { "gAPMacAddr", "00deadbeef04" },/** AP MAC address */ + { "gEnableApProt", "1" },/** protection flag in ini file */ + { "gFixedRate", "0" },/** Fixed rate in ini */ + { "gTxPowerCap", "27" },/** Tx power in ini */ + { "gFragmentationThreshold", "2346" },/** Fragmentation threshold in ini */ + { "RTSThreshold", "2347" },/** RTS threshold in ini */ + { "gAPCntryCode", "USI" },/** Country code in ini */ + { "gDisableIntraBssFwd", "0" },/** Intra-bss forward in ini */ + { "WmmIsEnabled", "0" },/** WMM */ + { "g11dSupportEnabled", "1" },/** 802.11d support */ + { "ieee80211n", NULL }, + { "ctrl_interface", NULL }, + { "interface", NULL }, + { "eap_server", NULL }, + { "gAPAutoShutOff", "0" }, + { "gEnablePhyAgcListenMode", "128" }, }; /** Supported operating mode */ @@ -175,7 +176,7 @@ char *fIni = INI_FILE; * @brief * For a give configuration parameter, read the configuration value from the file. * @param pfile [IN] configuration file path - * @param pcmd [IN] pointer to the comand string + * @param pcmd [IN] pointer to the comand structure * @param presp [OUT] buffer to store the configuration value * @param plen [IN-OUT] The length of the buffer is provided as input. * The length of the configuration parameter value, stored @@ -183,7 +184,7 @@ char *fIni = INI_FILE; * @param ignore_comment [IN] if set, read the commented value also * @return void */ -static s32 qsap_read_cfg(s8 *pfile, s8 *pcmd, s8 *presp, u32 *plen, s8 *var, s32 ignore_comment) +static s32 qsap_read_cfg(s8 *pfile, struct Command * pcmd, s8 *presp, u32 *plen, s8 *var, s32 ignore_comment) { FILE *fcfg; s8 buf[MAX_CONF_LINE_LEN]; @@ -200,7 +201,7 @@ static s32 qsap_read_cfg(s8 *pfile, s8 *pcmd, s8 *presp, u32 *plen, s8 *var, s32 } /** Read the line from the configuration file */ - len = strlen(pcmd); + len = strlen(pcmd->name); while(NULL != fgets(buf, MAX_CONF_LINE_LEN, fcfg)) { s8 *pline = buf; @@ -213,8 +214,15 @@ static s32 qsap_read_cfg(s8 *pfile, s8 *pcmd, s8 *presp, u32 *plen, s8 *var, s32 } /** Identify the configuration parameter in the configuration file */ - if(!strncmp(pline, pcmd, len) && (pline[len] == '=')) { - buf[strlen(buf)-1] = '\0'; + if(!strncmp(pline, pcmd->name, len) && (pline[len] == '=')) { + int tmp_indx; + + /* Delate all \r \n combinations infront of the config string */ + tmp_indx = strlen(buf)-1; + while( (buf[tmp_indx] == '\r') || (buf[tmp_indx] == '\n') ) tmp_indx--; + + buf[tmp_indx+1] = '\0'; + if ( NULL != var ) { val = strchr(pline, '='); if(NULL == val) @@ -229,9 +237,23 @@ static s32 qsap_read_cfg(s8 *pfile, s8 *pcmd, s8 *presp, u32 *plen, s8 *var, s32 } } +#if 0 /** Configuration parameter is absent in the file */ *plen = snprintf(presp, *plen, "%s", ERR_FEATURE_NOT_ENABLED); - +#else + /** Value not found in the configuration file */ + /** Send the default value, if we are reading from ini file */ + if ( pcmd->default_value ) { + *plen = snprintf(presp, *plen, "%s %s=%s", SUCCESS, var?var:pcmd->name, pcmd->default_value); + fclose(fcfg); + return eSUCCESS; + } + else { + /** Configuration parameter is absent in the file */ + *plen = snprintf(presp, *plen, "%s", ERR_FEATURE_NOT_ENABLED); + } +#endif + fclose(fcfg); return eERR_CONFIG_PARAM_MISSING; @@ -249,13 +271,13 @@ static s32 qsap_read_cfg(s8 *pfile, s8 *pcmd, s8 *presp, u32 *plen, s8 *var, s32 * in the 'presp', is provided as the output * @return void */ -static s32 qsap_write_cfg(s8 *pfile, s8 * pcmd, s8 *pVal, s8 *presp, u32 *plen, s32 inifile) +static s32 qsap_write_cfg(s8 *pfile, struct Command * pcmd, s8 *pVal, s8 *presp, u32 *plen, s32 inifile) { FILE *fcfg, *ftmp; s8 buf[MAX_CONF_LINE_LEN+1]; s16 len, result = FALSE; - LOGD("cmd=%s, Val:%s, INI:%ld \n", pcmd, pVal, inifile); + LOGD("cmd=%s, Val:%s, INI:%ld \n", pcmd->name, pVal, inifile); /** Open the configuration file */ fcfg = fopen(pfile, "r"); @@ -279,7 +301,7 @@ static s32 qsap_write_cfg(s8 *pfile, s8 * pcmd, s8 *pVal, s8 *presp, u32 *plen, } /** Read the values from the configuration file */ - len = strlen(pcmd); + len = strlen(pcmd->name); while(NULL != fgets(buf, MAX_CONF_LINE_LEN, fcfg)) { s8 *pline = buf; @@ -288,9 +310,9 @@ static s32 qsap_write_cfg(s8 *pfile, s8 * pcmd, s8 *pVal, s8 *presp, u32 *plen, pline++; /** Identify the configuration parameter to be updated */ - if((!strncmp(pline, pcmd, len)) && (result == FALSE)) { + if((!strncmp(pline, pcmd->name, len)) && (result == FALSE)) { if(pline[len] == '=') { - snprintf(buf, MAX_CONF_LINE_LEN, "%s=%s\n", pcmd, pVal); + snprintf(buf, MAX_CONF_LINE_LEN, "%s=%s\n", pcmd->name, pVal); result = TRUE; LOGD("Updated:%s\n", buf); } @@ -305,7 +327,7 @@ static s32 qsap_write_cfg(s8 *pfile, s8 * pcmd, s8 *pVal, s8 *presp, u32 *plen, if (result == FALSE) { /* Configuration line not found */ /* Add the new line at the end of file */ - snprintf(buf, MAX_CONF_LINE_LEN, "%s=%s\n", pcmd, pVal); + snprintf(buf, MAX_CONF_LINE_LEN, "%s=%s\n", pcmd->name, pVal); fprintf(ftmp, "%s", buf); LOGD("Adding a new line in %s file: [%s] \n", inifile ? "inifile" : "hostapd.conf", buf); } @@ -353,7 +375,7 @@ static sec_mode_t qsap_read_security_mode(s8 *pfile, s8 *presp, u32 *plen) u32 temp = *plen; /** Read the WEP default key */ - qsap_read_cfg(pfile, cmd_list[eCMD_DEFAULT_KEY], presp, plen, NULL, GET_ENABLED_ONLY); + qsap_read_cfg(pfile, &cmd_list[eCMD_DEFAULT_KEY], presp, plen, NULL, GET_ENABLED_ONLY); if ( !strcmp(presp, ERR_FEATURE_NOT_ENABLED) ) { *plen = temp; @@ -361,7 +383,7 @@ static sec_mode_t qsap_read_security_mode(s8 *pfile, s8 *presp, u32 *plen) /* WEP, is not enabled */ /** Read WPA security status */ - qsap_read_cfg(pfile, qsap_str[STR_WPA], presp, plen, NULL, GET_ENABLED_ONLY); + qsap_read_cfg(pfile, &qsap_str[STR_WPA], presp, plen, NULL, GET_ENABLED_ONLY); if ( !strcmp(presp, ERR_FEATURE_NOT_ENABLED) ) { /** WPA is disabled, No security */ mode = SEC_MODE_NONE; @@ -379,7 +401,7 @@ static sec_mode_t qsap_read_security_mode(s8 *pfile, s8 *presp, u32 *plen) else { /** Verify if, WPA is disabled */ *plen = temp; - qsap_read_cfg(pfile, qsap_str[STR_WPA], presp, plen, NULL, GET_ENABLED_ONLY); + qsap_read_cfg(pfile, &qsap_str[STR_WPA], presp, plen, NULL, GET_ENABLED_ONLY); if ( !strcmp(presp, ERR_FEATURE_NOT_ENABLED) ) { /** WPA is disabled, hence WEP is enabled */ mode = SEC_MODE_WEP; @@ -391,7 +413,7 @@ static sec_mode_t qsap_read_security_mode(s8 *pfile, s8 *presp, u32 *plen) } if(mode != SEC_MODE_INVALID) { - *plen = snprintf(presp, temp,"%s %s=%d", SUCCESS, cmd_list[eCMD_SEC_MODE], mode); + *plen = snprintf(presp, temp,"%s %s=%d", SUCCESS, cmd_list[eCMD_SEC_MODE].name, mode); } else { *plen = snprintf(presp, temp,"%s", ERR_NOT_SUPPORTED); @@ -404,12 +426,12 @@ static sec_mode_t qsap_read_security_mode(s8 *pfile, s8 *presp, u32 *plen) * @brief * Enable or disable a configuration parameter in the configuration file. * @param pfile [IN] configuration file name - * @param pcmd [IN] configuration parameter name + * @param pcmd [IN] configuration command structure * @param status [IN] status to be set. The valid values are 'ENABLE' or 'DISABLE' * @return On success, return 0 * On failure, return -1 */ -static s32 qsap_change_cfg(s8 *pfile, s8 *pcmd, u32 status) +static s32 qsap_change_cfg(s8 *pfile, struct Command * pcmd, u32 status) { FILE *fcfg, *ftmp; s8 buf[MAX_CONF_LINE_LEN+1]; @@ -435,7 +457,7 @@ static s32 qsap_change_cfg(s8 *pfile, s8 *pcmd, u32 status) } /** Read the configuration parameters from the configuration file */ - len = strlen(pcmd); + len = strlen(pcmd->name); while(NULL != fgets(buf+1, MAX_CONF_LINE_LEN, fcfg)) { s8 *p = buf+1; @@ -444,7 +466,7 @@ static s32 qsap_change_cfg(s8 *pfile, s8 *pcmd, u32 status) p++; /** Identify the configuration parameter */ - if(!strncmp(p, pcmd, len)) { + if(!strncmp(p, pcmd->name, len)) { if(p[len] == '=') { if(status == DISABLE) { fprintf(ftmp, "#%s", p); @@ -543,7 +565,7 @@ static void qsap_set_security_mode(s8 *pfile, u32 sec_mode, s8 *presp, u32 *plen } snprintf(sec, MAX_INT_STR, "%u", wpa_val); - qsap_write_cfg(pfile, qsap_str[STR_WPA], sec, presp, plen, HOSTAPD_CONF_FILE); + qsap_write_cfg(pfile, &qsap_str[STR_WPA], sec, presp, plen, HOSTAPD_CONF_FILE); *plen = tmp; } @@ -551,32 +573,32 @@ static void qsap_set_security_mode(s8 *pfile, u32 sec_mode, s8 *presp, u32 *plen * and the configuration parameters for the other security types are * disabled in the configuration file */ - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_DEFAULT_KEY], wep)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_DEFAULT_KEY], wep)) { LOGE("%s: wep_default_key error\n", __func__); goto end; } - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_WEP_KEY0], wep)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_WEP_KEY0], wep)) { LOGE("%s: CMD_WEP_KEY0 \n", __func__); goto end; } - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_WEP_KEY1], wep)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_WEP_KEY1], wep)) { LOGE("%s: CMD_WEP_KEY1 \n", __func__); goto end; } - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_WEP_KEY2], wep)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_WEP_KEY2], wep)) { LOGE("%s: CMD_WEP_KEY2 \n", __func__); goto end; } - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_WEP_KEY3], wep)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_WEP_KEY3], wep)) { LOGE("%s: CMD_WEP_KEY3 \n", __func__); goto end; } - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_PASSPHRASE], wpa)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_PASSPHRASE], wpa)) { LOGE("%s: Passphrase error\n", __func__); goto end; } @@ -586,18 +608,18 @@ static void qsap_set_security_mode(s8 *pfile, u32 sec_mode, s8 *presp, u32 *plen if(sec_mode == SEC_MODE_WPA_WPA2_PSK) state = ENABLE; - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_WPA_PAIRWISE], state)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_WPA_PAIRWISE], state)) { LOGE("%s: WPA Pairwise\n", __func__); goto end; } } - if(eERR_UNKNOWN == qsap_change_cfg(pfile, cmd_list[eCMD_RSN_PAIRWISE], rsn_status)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &cmd_list[eCMD_RSN_PAIRWISE], rsn_status)) { LOGE("%s: WPA2 Pairwise\n", __func__); goto end; } - if(eERR_UNKNOWN == qsap_change_cfg(pfile, qsap_str[STR_WPA], wpa)) { + if(eERR_UNKNOWN == qsap_change_cfg(pfile, &qsap_str[STR_WPA], wpa)) { LOGE("%s: WPA\n", __func__); goto end; } @@ -623,7 +645,7 @@ end: * On success, a pointer to the file name in the buffer 'pfile'. * On failure, NULL is returned */ -static s8 *qsap_get_allow_deny_file_name(s8 *pcfgfile, s8 *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)) { pfile[*plen] = '\0'; @@ -926,7 +948,7 @@ static void qsap_get_mac_list(s8 *fconfile, esap_cmd_t cNum, s8 *presp, u32 *ple /** Get the MAC allow or MAC deny file path */ len_remain = MAX_CONF_LINE_LEN; - if(NULL == (pfile = qsap_get_allow_deny_file_name(fconfile, qsap_str[sNum], buf, &len_remain))) { + if(NULL == (pfile = qsap_get_allow_deny_file_name(fconfile, &qsap_str[sNum], buf, &len_remain))) { LOGE("%s:Unknown error\n", __func__); *plen = snprintf(presp, *plen, "%s", ERR_RES_UNAVAILABLE); return; @@ -942,7 +964,7 @@ static void qsap_get_mac_list(s8 *fconfile, esap_cmd_t cNum, s8 *presp, u32 *ple /* Keep the NULL at the end of the buffer */ presp[*plen-1] = '\0'; - *plen -= snprintf(presp, *plen, "%s %s=", SUCCESS, cmd_list[cNum]); + *plen -= snprintf(presp, *plen, "%s %s=", SUCCESS, cmd_list[cNum].name); /* Reserving the space for last null character in case of over flow */ (u32)(*plen)--; @@ -994,7 +1016,7 @@ static int qsap_read_mac_address(s8 *presp, u32 *plen) len = *plen; - if(eSUCCESS != qsap_read_cfg(fIni, qsap_str[STR_MAC_IN_INI], presp, plen, cmd_list[eCMD_MAC_ADDR], GET_ENABLED_ONLY)) { + if(eSUCCESS != qsap_read_cfg(fIni, &qsap_str[STR_MAC_IN_INI], presp, plen, cmd_list[eCMD_MAC_ADDR].name, GET_ENABLED_ONLY)) { LOGE("%s :MAC addr read failure \n",__func__); goto end; } @@ -1004,7 +1026,7 @@ static int qsap_read_mac_address(s8 *presp, u32 *plen) goto end; strncpy(mac, ptr+1, MAC_ADDR_LEN); - *plen = snprintf(presp, len, "%s %s=", SUCCESS, cmd_list[eCMD_MAC_ADDR]); + *plen = snprintf(presp, len, "%s %s=", SUCCESS, cmd_list[eCMD_MAC_ADDR].name); ptr = presp + strlen(presp); for(i=0; i 11)) { /** Change the operating mode to 'B' */ ulen = *tlen; - if(eSUCCESS != qsap_write_cfg(pcfg, cmd_list[eCMD_HW_MODE], hw_mode[HW_MODE_B], tbuf, &ulen, HOSTAPD_CONF_FILE)) { + if(eSUCCESS != qsap_write_cfg(pcfg, &cmd_list[eCMD_HW_MODE], hw_mode[HW_MODE_B], tbuf, &ulen, HOSTAPD_CONF_FILE)) { LOGE("%s :Unable to update the operating mode \n", __func__); return eERR_UNKNOWN; } ulen = *tlen; snprintf(schan, MAX_INT_STR, "%d", AUTO_DATA_RATE); - if(eSUCCESS != qsap_write_cfg(fIni, qsap_str[STR_DATA_RATE_IN_INI], schan, tbuf, &ulen, HOSTAPD_CONF_FILE)) { + if(eSUCCESS != qsap_write_cfg(fIni, &qsap_str[STR_DATA_RATE_IN_INI], schan, tbuf, &ulen, HOSTAPD_CONF_FILE)) { LOGE("%s :Unable to set to auto data rate \n", __func__); return eERR_UNKNOWN; } @@ -2111,7 +2101,7 @@ static int qsap_set_channel(s32 channel, s8 *tbuf, u32 *tlen) snprintf(schan, MAX_INT_STR, "%ld", channel); - return qsap_write_cfg(pcfg, cmd_list[eCMD_CHAN], schan, tbuf, tlen, HOSTAPD_CONF_FILE); + return qsap_write_cfg(pcfg, &cmd_list[eCMD_CHAN], schan, tbuf, tlen, HOSTAPD_CONF_FILE); } static int qsap_set_operating_mode(s32 mode, s8 *pmode, s8 *tbuf, u32 *tlen) @@ -2126,7 +2116,7 @@ static int qsap_set_operating_mode(s32 mode, s8 *pmode, s8 *tbuf, u32 *tlen) ulen = *tlen; /** Read the current operating channel */ - if(NULL == (pcfgval = qsap_get_config_value(pconffile, cmd_list[eCMD_CHAN], tbuf, &ulen))) { + if(NULL == (pcfgval = qsap_get_config_value(pconffile, &cmd_list[eCMD_CHAN], tbuf, &ulen))) { LOGE("%s :Read mode error \n", __func__); return eERR_UNKNOWN; } @@ -2139,14 +2129,14 @@ static int qsap_set_operating_mode(s32 mode, s8 *pmode, s8 *tbuf, u32 *tlen) /** change to AUTO channel */ ulen = *tlen; snprintf(sconf, MAX_INT_STR, "%d", AUTO_CHANNEL); - if(eSUCCESS != qsap_write_cfg(pcfg, cmd_list[eCMD_CHAN], sconf, tbuf, &ulen, HOSTAPD_CONF_FILE)) { + if(eSUCCESS != qsap_write_cfg(pcfg, &cmd_list[eCMD_CHAN], sconf, tbuf, &ulen, HOSTAPD_CONF_FILE)) { LOGE("%s :Unable to update the channel \n", __func__); return eERR_UNKNOWN; } } ulen = *tlen; - if(NULL == (pcfgval = qsap_get_config_value(fIni, qsap_str[STR_DATA_RATE_IN_INI], tbuf, &ulen))) { + if(NULL == (pcfgval = qsap_get_config_value(fIni, &qsap_str[STR_DATA_RATE_IN_INI], tbuf, &ulen))) { LOGE("%s :Read mode error \n", __func__); return eERR_UNKNOWN; } @@ -2157,11 +2147,11 @@ static int qsap_set_operating_mode(s32 mode, s8 *pmode, s8 *tbuf, u32 *tlen) (((mode == HW_MODE_G) || (mode == HW_MODE_G_ONLY)) && (rate_idx > G_ONLY_MODE_MAX_DATA_RATE_IDX))) { snprintf(sconf, MAX_INT_STR, "%d", AUTO_DATA_RATE); ulen = *tlen; - qsap_write_cfg(fIni, qsap_str[STR_DATA_RATE_IN_INI], sconf, tbuf, &ulen, INI_CONF_FILE); + qsap_write_cfg(fIni, &qsap_str[STR_DATA_RATE_IN_INI], sconf, tbuf, &ulen, INI_CONF_FILE); } /** Update the operating mode */ - return qsap_write_cfg(pcfg, cmd_list[eCMD_HW_MODE], pmode, tbuf, tlen, HOSTAPD_CONF_FILE); + return qsap_write_cfg(pcfg, &cmd_list[eCMD_HW_MODE], pmode, tbuf, tlen, HOSTAPD_CONF_FILE); } static int qsap_set_data_rate(s32 drate_idx, s8 *presp, u32 *plen) @@ -2178,7 +2168,7 @@ static int qsap_set_data_rate(s32 drate_idx, s8 *presp, u32 *plen) ulen = *plen; /** Read the current operating mode */ - if(NULL == (pmode = qsap_get_config_value(pconffile, cmd_list[eCMD_HW_MODE], presp, &ulen))) { + if(NULL == (pmode = qsap_get_config_value(pconffile, &cmd_list[eCMD_HW_MODE], presp, &ulen))) { LOGE("%s :Unable to read mode \n", __func__); goto end; } @@ -2194,7 +2184,7 @@ static int qsap_set_data_rate(s32 drate_idx, s8 *presp, u32 *plen) snprintf(sconf, MAX_INT_STR, "%ld", drate_idx); /** Update the rate index in the configuration */ - return qsap_write_cfg(fIni, qsap_str[STR_DATA_RATE_IN_INI], sconf, presp, plen, INI_CONF_FILE); + return qsap_write_cfg(fIni, &qsap_str[STR_DATA_RATE_IN_INI], sconf, presp, plen, INI_CONF_FILE); end: *plen = snprintf(presp, *plen, "%s", ERR_UNKNOWN); @@ -2245,7 +2235,7 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) return; } - pVal = pcmd + strlen(cmd_list[cNum]); + pVal = pcmd + strlen(cmd_list[cNum].name); if( (cNum != eCMD_COMMIT) && (cNum != eCMD_RESET_TO_DEFAULT) && ((*pVal != '=') || (strlen(pVal) < 2)) ) { @@ -2255,7 +2245,7 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) pVal++; if((cNum != eCMD_COMMIT) && (cNum != eCMD_RESET_TO_DEFAULT)) { - LOGE("Cmd: %s Argument :%s \n", cmd_list[cNum], pVal); + LOGE("Cmd: %s Argument :%s \n", cmd_list[cNum].name, pVal); } switch(cNum) { @@ -2267,7 +2257,7 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) case eCMD_ADD_TO_DENY: case eCMD_REMOVE_FROM_DENY: ulen = MAX_FILE_PATH_LEN; - if(NULL != (pfile = qsap_get_allow_deny_file_name(pconffile, qsap_str[sNum], filename, &ulen))) { + if(NULL != (pfile = qsap_get_allow_deny_file_name(pconffile, &qsap_str[sNum], filename, &ulen))) { qsap_update_mac_list(pfile, cNum, pVal, presp, plen); } else { @@ -2305,10 +2295,10 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) status = ENABLE; } - if(eERR_UNKNOWN != qsap_change_cfg(pconffile, qsap_str[STR_ACCEPT_MAC_FILE], value)) { - if(eERR_UNKNOWN != qsap_change_cfg(pconffile, qsap_str[STR_DENY_MAC_FILE], status)) + if(eERR_UNKNOWN != qsap_change_cfg(pconffile, &qsap_str[STR_ACCEPT_MAC_FILE], value)) { + if(eERR_UNKNOWN != qsap_change_cfg(pconffile, &qsap_str[STR_DENY_MAC_FILE], status)) { - qsap_write_cfg(pconffile, cmd_list[cNum], pVal, presp, plen, HOSTAPD_CONF_FILE); + qsap_write_cfg(pconffile, &cmd_list[cNum], pVal, presp, plen, HOSTAPD_CONF_FILE); } else { goto error; @@ -2440,11 +2430,11 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) */ snprintf(pVal, MAX_INT_STR, "%ld", value); - qsap_write_cfg(pcfg, cmd_list[cNum], pVal, presp, plen, ini); + qsap_write_cfg(pcfg, &cmd_list[cNum], pVal, presp, plen, ini); ulen = MAX_FILE_PATH_LEN; if(SEC_MODE_WEP != qsap_read_security_mode(pcfg, filename, &ulen)) { - if(eERR_UNKNOWN == qsap_change_cfg(pcfg, cmd_list[cNum], 0)) { + if(eERR_UNKNOWN == qsap_change_cfg(pcfg, &cmd_list[cNum], 0)) { LOGE("%s: eCMD_DEFAULT_KEY \n", __func__); goto error; } @@ -2463,7 +2453,7 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) value = 0; } - if(eERR_UNKNOWN == qsap_change_cfg(pconffile, qsap_str[STR_HT_80211N], value)) { + if(eERR_UNKNOWN == qsap_change_cfg(pconffile, &qsap_str[STR_HT_80211N], value)) { LOGE("%s: unable to update 802.11 HT\n", __func__); goto error; } @@ -2477,13 +2467,13 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) if(FALSE == is_valid_wep_key(pVal, filename, MAX_FILE_PATH_LEN)) goto error; - qsap_write_cfg(pcfg, cmd_list[cNum], filename, presp, plen, ini); + qsap_write_cfg(pcfg, &cmd_list[cNum], filename, presp, plen, ini); /** if the security mode is not WEP, update the WEP features, and do NOT set the WEP security */ ulen = MAX_FILE_PATH_LEN; if(SEC_MODE_WEP != qsap_read_security_mode(pcfg, filename, &ulen)) { - if(eERR_UNKNOWN == qsap_change_cfg(pcfg, cmd_list[cNum], 0)) { + if(eERR_UNKNOWN == qsap_change_cfg(pcfg, &cmd_list[cNum], 0)) { LOGE("%s: CMD_WEP_KEY0 \n", __func__); goto error; } @@ -2614,10 +2604,6 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) if(TRUE != IS_VALID_WMM_STATE(value)) goto error; - if(value == ENABLE) - value = WMM_ENABLED_IN_INI; - else - value = WMM_DISABLED_IN_INI; snprintf(pVal, MAX_INT_STR, "%ld", value); cNum = STR_WMM_IN_INI; ini = INI_CONF_FILE; @@ -2733,11 +2719,11 @@ static void qsap_handle_set_request(s8 *pcmd, s8 *presp, u32 *plen) } if(ini == INI_CONF_FILE) { - LOGD("WRITE TO INI FILE :%s\n", qsap_str[cNum]); - qsap_write_cfg(fIni, qsap_str[cNum], pVal, presp, plen, ini); + LOGD("WRITE TO INI FILE :%s\n", qsap_str[cNum].name); + qsap_write_cfg(fIni, &qsap_str[cNum], pVal, presp, plen, ini); } else { - qsap_write_cfg(pcfg, cmd_list[cNum], pVal, presp, plen, ini); + qsap_write_cfg(pcfg, &cmd_list[cNum], pVal, presp, plen, ini); } return; @@ -2766,6 +2752,8 @@ void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen) /* Skip any blank spaces */ SKIP_BLANK_SPACE(pcmd); + check_for_configuration_files(); + 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); } @@ -2788,8 +2776,8 @@ void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen) #define DEFAULT_CHANNEL 4 #define DEFAULT_PASSPHRASE "12345678" #define DEFAULT_AUTH_ALG 1 -#define RECV_BUF_LEN 128 -#define CMD_BUF_LEN 80 +#define RECV_BUF_LEN 255 +#define CMD_BUF_LEN 255 /** Command input argv[4] = SSID, @@ -2805,6 +2793,7 @@ int qsapsetSoftap(int argc, char *argv[]) char respbuf[RECV_BUF_LEN]; unsigned long int rlen = RECV_BUF_LEN; int i; + int sec = SEC_MODE_NONE; LOGD("%s, %s, %s, %d\n", __FUNCTION__, argv[0], argv[1], argc); @@ -2829,7 +2818,6 @@ int qsapsetSoftap(int argc, char *argv[]) /** Security */ rlen = RECV_BUF_LEN; if(argc > 5) { - int sec = SEC_MODE_NONE; /**TODO : need to identify the SEC strings for "wep", "wpa", "wpa2" */ if(!strcmp(argv[5], "open")) @@ -2859,14 +2847,22 @@ int qsapsetSoftap(int argc, char *argv[]) /** Key -- passphrase */ rlen = RECV_BUF_LEN; - if(argc > 6) { - snprintf(cmdbuf, CMD_BUF_LEN, "set wpa_passphrase=%s",argv[6]); - } - else { - snprintf(cmdbuf, CMD_BUF_LEN, "set wpa_passphrase=%s", DEFAULT_PASSPHRASE); + if ( (sec == SEC_MODE_WPA_PSK) || (sec == SEC_MODE_WPA2_PSK) ) { + if(argc > 6) { + /* If the input passphrase is more than 63 characters, consider first 63 characters only*/ + if ( strlen(argv[6]) > 63 ) argv[6][63] = '\0'; + snprintf(cmdbuf, CMD_BUF_LEN, "set wpa_passphrase=%s",argv[6]); + } + else { + snprintf(cmdbuf, CMD_BUF_LEN, "set wpa_passphrase=%s", DEFAULT_PASSPHRASE); + } } (void) qsap_hostd_exec_cmd(cmdbuf, respbuf, &rlen); + if(strncmp("success", respbuf, rlen) != 0) { + LOGE("Failed to set passphrase \n"); + return -1; + } /** channel */ rlen = RECV_BUF_LEN; @@ -2896,3 +2892,39 @@ int qsapsetSoftap(int argc, char *argv[]) return 0; } + +void check_for_configuration_files(void) +{ + FILE * fp; + + /* Check if configuration files are present, if not create the default files */ + mkdir("/data/hostapd", 0770); + + /* If configuration file does not exhist copy the default file */ + if ( NULL == (fp = fopen(CONFIG_FILE, "r")) ) { + wifi_qsap_reset_to_default(CONFIG_FILE, DEFAULT_CONFIG_FILE_PATH); + } + else { + fclose(fp); + } + + /* If Accept MAC list file does not exhist, create an empty file */ + if ( NULL == (fp = fopen(ACCEPT_LIST_FILE, "r")) ) { + fp = fopen(ACCEPT_LIST_FILE, "w+"); + if ( fp ) fclose(fp); + } + else { + fclose(fp); + } + + /* If deny MAC list file does not exhist, create an empty file */ + if ( NULL == (fp = fopen(DENY_LIST_FILE, "r")) ) { + fp = fopen(DENY_LIST_FILE, "w+"); + if ( fp ) fclose(fp); + } + else { + fclose(fp); + } + + return; +} diff --git a/softap/sdk/qsap_api.h b/softap/sdk/qsap_api.h index 009edc4..763d4f6 100644 --- a/softap/sdk/qsap_api.h +++ b/softap/sdk/qsap_api.h @@ -78,15 +78,18 @@ enum error_val { eERR_LOAD_FAILED_SOFTAP }; -/** Soft AP SDK version */ -#define QSAP_SDK_VERSION "1.0" - /** Configuration file name */ #define CONFIG_FILE "/data/hostapd/hostapd.conf" /** Default configuration file path */ #define DEFAULT_CONFIG_FILE_PATH "/persist/qcom/softap/hostapd_default.conf" +/** Accept list file name */ +#define ACCEPT_LIST_FILE "/data/hostapd/hostapd.accept" + +/** Deny list file name */ +#define DENY_LIST_FILE "/data/hostapd/hostapd.deny" + /** Ini file */ #define INI_FILE "/system/etc/firmware/wlan/qcom_cfg.ini" @@ -130,12 +133,6 @@ enum error_val { #define DTIM_PERIOD_MIN (1) #define DTIM_PERIOD_MAX (255) -/** RTS threshold 1 to 2347 */ -#define RTS_THRESHOLD_MAX (2347) - -/** Fragmentation threshold 256 to 2346 */ -#define FRAG_THRESHOLD_MAX (2346) - /** WEP key lengths in ASCII and hex */ #define WEP_64_KEY_ASCII (5) #define WEP_64_KEY_HEX (10) @@ -153,10 +150,12 @@ enum error_val { #define AUTO_CHANNEL (0) #define BG_MAX_CHANNEL (11) +/** Fragmentation threshold 256 to 2346 */ #define FRAG_THRESHOLD_MIN (256) #define FRAG_THRESHOLD_MAX (2346) -#define RTS_THRESHOLD_MIN (0) +/** RTS threshold 1 to 2347 */ +#define RTS_THRESHOLD_MIN (1) #define RTS_THRESHOLD_MAX (2347) #define MIN_UUID_LEN (1) @@ -221,7 +220,7 @@ enum error_val { /** AP shutoff time */ #define AP_ENERGY_DETECT_TH_MIN (0) -#define AP_ENERGY_DETECT_TH_MAX (100) +#define AP_ENERGY_DETECT_TH_MAX (9) /** command request index - in the array Cmd_req[] */ enum eCmd_req { @@ -395,6 +394,7 @@ enum ap_reset { }; enum wmm_state { + WMM_AUTO_IN_INI = 0, WMM_ENABLED_IN_INI = 1, WMM_DISABLED_IN_INI = 2 }; @@ -416,6 +416,12 @@ enum eChoose_conf_file { INI_CONF_FILE = 1 }; +struct Command +{ + s8 * name; + s8 * default_value; +}; + /** Validate enable / disable softap */ #define IS_VALID_SOFTAP_ENABLE(x) (((value == ENABLE) || (value == DISABLE)) ? TRUE: FALSE) @@ -448,7 +454,7 @@ enum eChoose_conf_file { (!strcmp(x, "TKIP CCMP")) || (!strcmp(x, "CCMP TKIP"))) ? TRUE : FALSE) /** Validate the WMM status */ -#define IS_VALID_WMM_STATE(x) (((x == ENABLE) || (x == DISABLE)) ? TRUE: FALSE) +#define IS_VALID_WMM_STATE(x) (((x >= WMM_AUTO_IN_INI) && (x <= WMM_DISABLED_IN_INI)) ? TRUE: FALSE) /** Validate the WPS status */ #define IS_VALID_WPS_STATE(x) (((x == ENABLE) || (x == DISABLE)) ? TRUE: FALSE) @@ -520,13 +526,15 @@ enum eChoose_conf_file { #define IS_VALID_APSHUTOFFTIME(x) (((x >= AP_SHUTOFF_MIN) && (x <= AP_SHUTOFF_MAX)) ? TRUE : FALSE) /** Validate the AP shutoff time */ -#define IS_VALID_ENERGY_DETECT_TH(x) (((x >= AP_ENERGY_DETECT_TH_MIN) && (x <= AP_ENERGY_DETECT_TH_MAX)) ? 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) /** Function declartion */ void qsap_hostd_exec_cmd(s8 *pcmd, s8 *presp, u32 *plen); -s8 *qsap_get_config_value(s8 *pfile, s8 *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[]); void qsap_del_ctrl_iface(void); +s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault); +void check_for_configuration_files(void); #if __cplusplus }; // extern "C"