diff --git a/libqsap_sdk/qsap.c b/libqsap_sdk/qsap.c index 1e27db1..ee1e5b4 100644 --- a/libqsap_sdk/qsap.c +++ b/libqsap_sdk/qsap.c @@ -6,28 +6,27 @@ #include -#include #include #include +#include #include "qsap_api.h" extern struct Command qsap_str[]; -s32 is_softap_enabled(void) -{ +s32 is_softap_enabled(void) { s32 mode = 0; int ret; ret = qsap_get_mode(&mode); if (eSUCCESS != ret) { - ALOGD("Failed to get the mode of operation\n"); - return eERR_UNKNOWN; + ALOGD("Failed to get the mode of operation\n"); + return eERR_UNKNOWN; } if (mode == IW_MODE_MASTER) { - ALOGD("HOSTAPD Enabled\n"); - return ENABLE; + ALOGD("HOSTAPD Enabled\n"); + return ENABLE; } ALOGD("HOSTAPD Disabled\n"); @@ -35,17 +34,17 @@ s32 is_softap_enabled(void) return DISABLE; } -s32 wifi_qsap_set_tx_power(s32 tx_power) -{ -#define QCSAP_IOCTL_SET_MAX_TX_POWER (SIOCIWFIRSTPRIV + 22) +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; + 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))) { + if (NULL == (iface = qsap_get_config_value(CONFIG_FILE, &qsap_str[STR_INTERFACE], interface, + (u32*)&len))) { ALOGE("%s :interface error \n", __func__); return ret; } diff --git a/libqsap_sdk/qsap_api.c b/libqsap_sdk/qsap_api.c index 157414b..bfcf758 100644 --- a/libqsap_sdk/qsap_api.c +++ b/libqsap_sdk/qsap_api.c @@ -4,164 +4,164 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include -#include #include #include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include "nl80211_copy.h" #include "qsap_api.h" -#define QCSAP_IOCTL_GET_CHANNEL (SIOCIWFIRSTPRIV+9) +#define QCSAP_IOCTL_GET_CHANNEL (SIOCIWFIRSTPRIV + 9) /* * WARNING: On updating the cmd_list, the enum esap_cmd in file * qsap_api.h must be updates to reflect the changes */ 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", "0.0.1.0" }, - { "wmm_enabled", "0" }, + {"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", "0.0.1.0"}, + {"wmm_enabled", "0"}, - /** Warning: Do not change the order of the WPS commands */ - { "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 *********/ + /** Warning: Do not change the order of the WPS commands */ + {"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", NULL }, - { "rts_threshold", NULL }, - { "wpa_group_rekey", NULL }, - { "country_code", NULL }, - { "ap_isolate", NULL }, - { "ieee80211d", NULL }, - { "apstat", NULL }, - { "auto_shut_off_time", NULL }, - { "energy_detect_threshold", "128" }, - { "basic_rates", NULL }, - { "require_ht", NULL }, - { "ieee80211n", "1" }, - { "setchannelrange", NULL }, - { "autochannel", 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 }, - { "vendor_elements", NULL }, - { "assocresp_elements", NULL }, - { "acs_exclude_dfs", NULL }, - { "wowlan_triggers", "any" }, - { "accept_mac_file", NULL }, - { "deny_mac_file", NULL }, - { "owe_transition_ifname", NULL }, - { "sae_require_mfp", NULL }, - { "ieee80211ax", NULL }, - { "enable_edmg", NULL }, - { "edmg_channel", NULL }, + {"fragm_threshold", NULL}, + {"rts_threshold", NULL}, + {"wpa_group_rekey", NULL}, + {"country_code", NULL}, + {"ap_isolate", NULL}, + {"ieee80211d", NULL}, + {"apstat", NULL}, + {"auto_shut_off_time", NULL}, + {"energy_detect_threshold", "128"}, + {"basic_rates", NULL}, + {"require_ht", NULL}, + {"ieee80211n", "1"}, + {"setchannelrange", NULL}, + {"autochannel", 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}, + {"vendor_elements", NULL}, + {"assocresp_elements", NULL}, + {"acs_exclude_dfs", NULL}, + {"wowlan_triggers", "any"}, + {"accept_mac_file", NULL}, + {"deny_mac_file", NULL}, + {"owe_transition_ifname", NULL}, + {"sae_require_mfp", NULL}, + {"ieee80211ax", NULL}, + {"enable_edmg", NULL}, + {"edmg_channel", NULL}, }; 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" }, + {"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"}, }; /** configuration file path */ -char *pconffile = CONFIG_FILE; +char* pconffile = CONFIG_FILE; /** * Get the channel being used in the soft AP. */ -int qsap_get_operating_channel(s32 *pchan) -{ +int qsap_get_operating_channel(s32* pchan) { int sock; struct iwreq wrq; s8 interface[MAX_CONF_LINE_LEN]; u32 len = MAX_CONF_LINE_LEN; - s8 *pif; + s8* pif; int ret; - if(ENABLE != is_softap_enabled()) { + if (ENABLE != is_softap_enabled()) { goto error; } - if(NULL == (pif = qsap_get_config_value(pconffile, &qsap_str[STR_INTERFACE], interface, &len))) { + if (NULL == + (pif = qsap_get_config_value(pconffile, &qsap_str[STR_INTERFACE], interface, &len))) { ALOGE("%s :interface error \n", __func__); goto error; } @@ -169,7 +169,7 @@ int qsap_get_operating_channel(s32 *pchan) interface[len] = '\0'; sock = socket(AF_INET, SOCK_DGRAM, 0); - if(sock < 0) { + if (sock < 0) { ALOGE("%s :socket error \n", __func__); goto error; } @@ -182,14 +182,14 @@ int qsap_get_operating_channel(s32 *pchan) wrq.u.data.flags = 0; ret = ioctl(sock, QCSAP_IOCTL_GET_CHANNEL, &wrq); - if(ret < 0) { - ALOGE("%s: ioctl failure \n",__func__); + if (ret < 0) { + ALOGE("%s: ioctl failure \n", __func__); close(sock); goto error; } ALOGE("Recv len :%d \n", wrq.u.data.length); - *pchan = *(int *)(&wrq.u.name[0]); + *pchan = *(int*)(&wrq.u.name[0]); ALOGE("Operating channel :%d \n", *pchan); close(sock); return eSUCCESS; @@ -200,20 +200,17 @@ error: return eERR_CHAN_READ; } -static int iftypeCallback(struct nl_msg* msg, void* arg) -{ +static int iftypeCallback(struct nl_msg* msg, void* arg) { struct nlmsghdr* ret_hdr = nlmsg_hdr(msg); - struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; + struct nlattr* tb_msg[NL80211_ATTR_MAX + 1]; int* type = arg; - struct genlmsghdr *gnlh = (struct genlmsghdr*) nlmsg_data(ret_hdr); + struct genlmsghdr* gnlh = (struct genlmsghdr*)nlmsg_data(ret_hdr); - nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL); + nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (tb_msg[NL80211_ATTR_IFTYPE]) { *type = nla_get_u32(tb_msg[NL80211_ATTR_IFTYPE]); - } return NL_SKIP; } @@ -221,93 +218,87 @@ static int iftypeCallback(struct nl_msg* msg, void* arg) /** * Get the mode of operation. */ -int qsap_get_mode(s32 *pmode) -{ +int qsap_get_mode(s32* pmode) { int ret = eERR_UNKNOWN; struct nl_sock* sk = NULL; int nl80211_id = -1; int if_type = -1; s8 interface[MAX_CONF_LINE_LEN]; u32 len = MAX_CONF_LINE_LEN; - s8 *pif; + s8* pif; struct nl_msg* msg = NULL; - //get interface name - if(NULL == (pif = qsap_get_config_value(pconffile, - &qsap_str[STR_INTERFACE], interface, &len))) { + // get interface name + if (NULL == + (pif = qsap_get_config_value(pconffile, &qsap_str[STR_INTERFACE], interface, &len))) { ALOGD("%s :interface error \n", __func__); goto nla_put_failure; } interface[len] = '\0'; - //allocate socket + // allocate socket sk = nl_socket_alloc(); - //return if socket allocation fails - if(sk == NULL){ - ALOGE( "socket allocation failure"); - return ret; + // return if socket allocation fails + if (sk == NULL) { + ALOGE("socket allocation failure"); + return ret; } - //connect to generic netlink + // connect to generic netlink if (genl_connect(sk)) { - ALOGE( "Netlink socket Connection failure"); + ALOGE("Netlink socket Connection failure"); ret = eERR_UNKNOWN; goto nla_put_failure; } - //find the nl80211 driver ID + // find the nl80211 driver ID nl80211_id = genl_ctrl_resolve(sk, "nl80211"); - //attach a callback - nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, - iftypeCallback, &if_type); + // attach a callback + nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, iftypeCallback, &if_type); - //allocate a message + // allocate a message msg = nlmsg_alloc(); - //return if message allocation fails - if(msg == NULL){ - ALOGE( "message allocation failure"); - goto nla_put_failure; + // return if message allocation fails + if (msg == NULL) { + ALOGE("message allocation failure"); + goto nla_put_failure; } // setup the message genlmsg_put(msg, 0, 0, nl80211_id, 0, 0, NL80211_CMD_GET_INTERFACE, 0); - //add message attributes + // add message attributes NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(pif)); // Send the message ret = nl_send_auto_complete(sk, msg); - if (ret < 0 ) { - ALOGE( "nl_send_auto_complete failure"); + if (ret < 0) { + ALOGE("nl_send_auto_complete failure"); ret = eERR_UNKNOWN; goto nla_put_failure; } - //block for message to return + // block for message to return nl_recvmsgs_default(sk); *pmode = if_type; - ALOGI("%s: (%s) NL80211 Get Mode = %d \n",__func__, pif, (int)*pmode); + ALOGI("%s: (%s) NL80211 Get Mode = %d \n", __func__, pif, (int)*pmode); ret = eSUCCESS; nla_put_failure: - if (sk) - nl_socket_free(sk); - if (msg) - nlmsg_free(msg); + if (sk) nl_socket_free(sk); + if (msg) nlmsg_free(msg); return ret; } -static int qsap_scnprintf(char *str, size_t size, const char *format, ...) -{ +static int qsap_scnprintf(char* str, size_t size, const char* format, ...) { va_list arg_ptr; int ret = 0; - if (size < 1) - return 0; + if (size < 1) return 0; va_start(arg_ptr, format); ret = vsnprintf(str, size, format, arg_ptr); va_end(arg_ptr); @@ -325,18 +316,18 @@ static int qsap_scnprintf(char *str, size_t size, const char *format, ...) * in the 'presp', is provided as the output * @param ignore_comment [IN] if set, read the commented value also * @return void -*/ -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]; - u16 len; - s8 *val; + */ +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]; + u16 len; + s8* val; /** Open the configuration file */ fcfg = fopen(pfile, "r"); - if(NULL == fcfg) { + if (NULL == fcfg) { ALOGE("%s : unable to open file \n", __func__); *plen = qsap_scnprintf(presp, *plen, "%s", ERR_RES_UNAVAILABLE); return eERR_FILE_OPEN; @@ -344,37 +335,34 @@ static s32 qsap_read_cfg(s8 *pfile, struct Command * pcmd, s8 *presp, u32 *plen, /** Read the line from the configuration file */ len = strlen(pcmd->name); - while(NULL != fgets(buf, MAX_CONF_LINE_LEN, fcfg)) { - s8 *pline = buf; + while (NULL != fgets(buf, MAX_CONF_LINE_LEN, fcfg)) { + s8* pline = buf; - if (strlen(buf) == 0) - continue; + if (strlen(buf) == 0) continue; /** Skip the commented lines */ - if(buf[0] == '#') { + if (buf[0] == '#') { if (ignore_comment) { pline++; - } - else continue; + } else + continue; } /** Identify the configuration parameter in the configuration file */ - if(!strncmp(pline, pcmd->name, len) && (pline[len] == '=')) { + 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--; + /* 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'; + buf[tmp_indx + 1] = '\0'; - if ( NULL != var ) { + if (NULL != var) { val = strchr(pline, '='); - if(NULL == val) - break; + if (NULL == val) break; *plen = qsap_scnprintf(presp, *plen, "%s %s%s", SUCCESS, var, val); - } - else { + } else { *plen = qsap_scnprintf(presp, *plen, "%s %s", SUCCESS, pline); } fclose(fcfg); @@ -383,12 +371,12 @@ static s32 qsap_read_cfg(s8 *pfile, struct Command * pcmd, s8 *presp, u32 *plen, } /** Send the default value, if we are reading from ini file */ - if ( pcmd->default_value ) { - *plen = qsap_scnprintf(presp, *plen, "%s %s=%s", SUCCESS, var?var:pcmd->name, pcmd->default_value); + if (pcmd->default_value) { + *plen = qsap_scnprintf(presp, *plen, "%s %s=%s", SUCCESS, var ? var : pcmd->name, + pcmd->default_value); fclose(fcfg); return eSUCCESS; - } - else { + } else { /** Configuration parameter is absent in the file */ *plen = qsap_scnprintf(presp, *plen, "%s", ERR_FEATURE_NOT_ENABLED); } @@ -398,16 +386,14 @@ static s32 qsap_read_cfg(s8 *pfile, struct Command * pcmd, s8 *presp, u32 *plen, return eERR_CONFIG_PARAM_MISSING; } -s8 *qsap_get_config_value(s8 *pfile, struct Command *pcmd, s8 *pbuf, u32 *plen) -{ - s8 *ptr = NULL; +s8* qsap_get_config_value(s8* pfile, struct Command* pcmd, s8* pbuf, u32* plen) { + s8* ptr = NULL; - if(eSUCCESS == qsap_read_cfg(pfile, pcmd, pbuf, (u32 *)plen, NULL, GET_ENABLED_ONLY)) { + if (eSUCCESS == qsap_read_cfg(pfile, pcmd, pbuf, (u32*)plen, NULL, GET_ENABLED_ONLY)) { ptr = strchr(pbuf, '='); - if(NULL != ptr){ + if (NULL != ptr) { ptr++; - } - else { + } else { ALOGE("Invalid entry, %s\n", pcmd->name); } } @@ -415,15 +401,14 @@ s8 *qsap_get_config_value(s8 *pfile, struct Command *pcmd, s8 *pbuf, u32 *plen) return ptr; } -s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault) -{ +s16 wifi_qsap_reset_to_default(s8* pcfgfile, s8* pdefault) { FILE *fcfg, *ftmp; char buf[MAX_CONF_LINE_LEN]; int status = eSUCCESS; fcfg = fopen(pdefault, "r"); - if(NULL == fcfg) { + if (NULL == fcfg) { ALOGE("%s : unable to open file \n", __func__); return eERR_FILE_OPEN; } @@ -431,13 +416,13 @@ s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault) qsap_scnprintf(buf, sizeof(buf), "%s~", pcfgfile); ftmp = fopen(buf, "w+"); - if(NULL == ftmp) { + if (NULL == ftmp) { ALOGE("%s : unable to open file \n", __func__); fclose(fcfg); return eERR_FILE_OPEN; } - while(NULL != fgets(buf, MAX_CONF_LINE_LEN, fcfg)) { + while (NULL != fgets(buf, MAX_CONF_LINE_LEN, fcfg)) { fprintf(ftmp, "%s", buf); } @@ -446,8 +431,7 @@ s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault) qsap_scnprintf(buf, sizeof(buf), "%s~", pcfgfile); - if(eERR_UNKNOWN == rename(buf, pcfgfile)) - status = eERR_CONF_FILE; + if (eERR_UNKNOWN == rename(buf, pcfgfile)) status = eERR_CONF_FILE; /** Remove the temporary file. Dont care the return value */ unlink(buf); @@ -455,32 +439,27 @@ s16 wifi_qsap_reset_to_default(s8 *pcfgfile, s8 *pdefault) return status; } -static int check_for_config_file_size(FILE *fp) -{ - int length = 0; +static int check_for_config_file_size(FILE* fp) { + int length = 0; - if( NULL != fp ) - { - fseek(fp, 0L, SEEK_END); - length = ftell(fp); - } + if (NULL != fp) { + fseek(fp, 0L, SEEK_END); + length = ftell(fp); + } - return length; + return length; } -void check_for_configuration_files(void) -{ - FILE * fp; - char *pfile; +void check_for_configuration_files(void) { + FILE* fp; + char* pfile; /* 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")) ) { + if (NULL == (fp = fopen(pconffile, "r"))) { wifi_qsap_reset_to_default(pconffile, 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); @@ -489,11 +468,9 @@ void check_for_configuration_files(void) } /* If Accept MAC list file does not exist, copy the default file */ - if ( NULL == (fp = fopen(ACCEPT_LIST_FILE, "r")) ) { + if (NULL == (fp = fopen(ACCEPT_LIST_FILE, "r"))) { 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); @@ -504,15 +481,12 @@ void check_for_configuration_files(void) /* 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)); + 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 ( 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); - } - 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); @@ -523,8 +497,7 @@ void check_for_configuration_files(void) /* 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)); + ALOGE("Error changing permissions of %s to 0660: %s", pfile, strerror(errno)); } return; } diff --git a/libqsap_sdk/qsap_api.h b/libqsap_sdk/qsap_api.h index 9f1a643..3178e44 100644 --- a/libqsap_sdk/qsap_api.h +++ b/libqsap_sdk/qsap_api.h @@ -10,17 +10,17 @@ #define LOG_TAG "QCSDK" #include -typedef unsigned char u8; -typedef char s8; +typedef unsigned char u8; +typedef char s8; typedef unsigned short int u16; -typedef signed short int s16; -typedef unsigned int u32; -typedef signed int s32; +typedef signed short int s16; +typedef unsigned int u32; +typedef signed int s32; /** Success and error messages */ -#define SUCCESS "success" -#define ERR_FEATURE_NOT_ENABLED "failure feature not enabled" -#define ERR_RES_UNAVAILABLE "failure resource unavailable" +#define SUCCESS "success" +#define ERR_FEATURE_NOT_ENABLED "failure feature not enabled" +#define ERR_RES_UNAVAILABLE "failure resource unavailable" /** Error numbers used with the SDK */ enum error_val { @@ -67,158 +67,154 @@ enum error_val { #define DENY_LIST_FILE "/data/vendor/wifi/hostapd/hostapd.deny" /** Maximum length of the line in the configuration file */ -#define MAX_CONF_LINE_LEN (156) +#define MAX_CONF_LINE_LEN (156) /** parameters for read config */ -#define GET_ENABLED_ONLY 0 +#define GET_ENABLED_ONLY 0 /** - * Command numbers, these numbers form the index into the array of - * command names stored in the 'cmd_list'. - * - * Warning: An addtion of an entry in 'esap_cmd', should be followed - * by an addition of a command name string in the 'cmd_list' array - */ + * Command numbers, these numbers form the index into the array of + * command names stored in the 'cmd_list'. + * + * Warning: An addtion of an entry in 'esap_cmd', should be followed + * by an addition of a command name string in the 'cmd_list' array + */ typedef enum esap_cmd { - eCMD_INVALID = -1, - eCMD_SSID = 0, - eCMD_BSSID = 1, - eCMD_CHAN = 2, - eCMD_BCN_INTERVAL = 3, - eCMD_DTIM_PERIOD = 4, - eCMD_HW_MODE = 5, - eCMD_AUTH_ALGS = 6, - eCMD_SEC_MODE = 7, - eCMD_WEP_KEY0 = 8, - eCMD_WEP_KEY1 = 9, - eCMD_WEP_KEY2 = 10, - eCMD_WEP_KEY3 = 11, - eCMD_DEFAULT_KEY = 12, - eCMD_PASSPHRASE = 13, - eCMD_WPA_PAIRWISE = 14, - eCMD_RSN_PAIRWISE = 15, - eCMD_MAC_ADDR = 16, - eCMD_RESET_AP = 17, - eCMD_MAC_ACL = 18, - eCMD_ADD_TO_ALLOW = 19, - eCMD_ADD_TO_DENY = 20, - eCMD_REMOVE_FROM_ALLOW = 21, - eCMD_REMOVE_FROM_DENY = 22, - eCMD_ALLOW_LIST = 23, - eCMD_DENY_LIST = 24, - eCMD_COMMIT = 25, - eCMD_ENABLE_SOFTAP = 26, - eCMD_DISASSOC_STA = 27, - eCMD_RESET_TO_DEFAULT = 28, - eCMD_PROTECTION_FLAG = 29, - eCMD_DATA_RATES = 30, - eCMD_ASSOC_STA_MACS = 31, - eCMD_TX_POWER = 32, - eCMD_SDK_VERSION = 33, - eCMD_WMM_STATE = 34, + eCMD_INVALID = -1, + eCMD_SSID = 0, + eCMD_BSSID = 1, + eCMD_CHAN = 2, + eCMD_BCN_INTERVAL = 3, + eCMD_DTIM_PERIOD = 4, + eCMD_HW_MODE = 5, + eCMD_AUTH_ALGS = 6, + eCMD_SEC_MODE = 7, + eCMD_WEP_KEY0 = 8, + eCMD_WEP_KEY1 = 9, + eCMD_WEP_KEY2 = 10, + eCMD_WEP_KEY3 = 11, + eCMD_DEFAULT_KEY = 12, + eCMD_PASSPHRASE = 13, + eCMD_WPA_PAIRWISE = 14, + eCMD_RSN_PAIRWISE = 15, + eCMD_MAC_ADDR = 16, + eCMD_RESET_AP = 17, + eCMD_MAC_ACL = 18, + eCMD_ADD_TO_ALLOW = 19, + eCMD_ADD_TO_DENY = 20, + eCMD_REMOVE_FROM_ALLOW = 21, + eCMD_REMOVE_FROM_DENY = 22, + eCMD_ALLOW_LIST = 23, + eCMD_DENY_LIST = 24, + eCMD_COMMIT = 25, + eCMD_ENABLE_SOFTAP = 26, + eCMD_DISASSOC_STA = 27, + eCMD_RESET_TO_DEFAULT = 28, + eCMD_PROTECTION_FLAG = 29, + eCMD_DATA_RATES = 30, + eCMD_ASSOC_STA_MACS = 31, + eCMD_TX_POWER = 32, + eCMD_SDK_VERSION = 33, + eCMD_WMM_STATE = 34, /** WARNING: The order of WPS commands should not be altered. New commands SHOULD be added above or below this */ - eCMD_WPS_STATE = 35, - eCMD_WPS_CONFIG_METHOD = 36, - eCMD_UUID = 37, - eCMD_DEVICE_NAME = 38, - eCMD_MANUFACTURER = 39, - eCMD_MODEL_NAME = 40, - eCMD_MODEL_NUMBER = 41, - eCMD_SERIAL_NUMBER = 42, - eCMD_DEVICE_TYPE = 43, - eCMD_OS_VERSION = 44, - eCMD_FRIENDLY_NAME = 45, - eCMD_MANUFACTURER_URL = 46, - eCMD_MODEL_DESC = 47, - eCMD_MODEL_URL = 48, - eCMD_UPC = 49, + eCMD_WPS_STATE = 35, + eCMD_WPS_CONFIG_METHOD = 36, + eCMD_UUID = 37, + eCMD_DEVICE_NAME = 38, + eCMD_MANUFACTURER = 39, + eCMD_MODEL_NAME = 40, + eCMD_MODEL_NUMBER = 41, + eCMD_SERIAL_NUMBER = 42, + eCMD_DEVICE_TYPE = 43, + eCMD_OS_VERSION = 44, + eCMD_FRIENDLY_NAME = 45, + eCMD_MANUFACTURER_URL = 46, + eCMD_MODEL_DESC = 47, + eCMD_MODEL_URL = 48, + eCMD_UPC = 49, /******************************************************/ - eCMD_FRAG_THRESHOLD = 50, - eCMD_RTS_THRESHOLD = 51, - eCMD_GTK_TIMEOUT = 52, - eCMD_COUNTRY_CODE = 53, - eCMD_INTRA_BSS_FORWARD = 54, - eCMD_REGULATORY_DOMAIN = 55, - eCMD_AP_STATISTICS = 56, - eCMD_AP_AUTOSHUTOFF = 57, + eCMD_FRAG_THRESHOLD = 50, + eCMD_RTS_THRESHOLD = 51, + eCMD_GTK_TIMEOUT = 52, + eCMD_COUNTRY_CODE = 53, + eCMD_INTRA_BSS_FORWARD = 54, + eCMD_REGULATORY_DOMAIN = 55, + eCMD_AP_STATISTICS = 56, + eCMD_AP_AUTOSHUTOFF = 57, eCMD_AP_ENERGY_DETECT_TH = 58, - eCMD_BASIC_RATES = 59, - eCMD_REQUIRE_HT = 60, - eCMD_IEEE80211N = 61, - eCMD_SET_CHANNEL_RANGE = 62, - eCMD_GET_AUTO_CHANNEL = 63, - 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_BASIC_RATES = 59, + eCMD_REQUIRE_HT = 60, + eCMD_IEEE80211N = 61, + eCMD_SET_CHANNEL_RANGE = 62, + eCMD_GET_AUTO_CHANNEL = 63, + 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_VENDOR_ELEMENT = 77, - eCMD_ASSOCRESP_ELEMENT = 78, - eCMD_ACS_EXCLUDE_DFS = 79, - eCMD_WOWLAN_TRIGGERS = 80, - eCMD_ACCEPT_MAC_FILE = 81, - eCMD_DENY_MAC_FILE = 82, - eCMD_OWE_TRANS_IFNAME = 83, - eCMD_SAE_REQUIRE_MPF = 84, + eCMD_INTERFACE = 73, + eCMD_SSID2 = 74, + eCMD_BRIDGE = 75, + eCMD_CTRL_INTERFACE = 76, + eCMD_VENDOR_ELEMENT = 77, + eCMD_ASSOCRESP_ELEMENT = 78, + eCMD_ACS_EXCLUDE_DFS = 79, + eCMD_WOWLAN_TRIGGERS = 80, + eCMD_ACCEPT_MAC_FILE = 81, + eCMD_DENY_MAC_FILE = 82, + eCMD_OWE_TRANS_IFNAME = 83, + eCMD_SAE_REQUIRE_MPF = 84, - eCMD_IEEE80211AX = 85, + eCMD_IEEE80211AX = 85, - eCMD_ENABLE_EDMG = 86, - eCMD_EDMG_CHANNEL = 87, + eCMD_ENABLE_EDMG = 86, + eCMD_EDMG_CHANNEL = 87, - eCMD_LAST /** New command numbers should be added above this */ + eCMD_LAST /** New command numbers should be added above this */ } esap_cmd_t; /** non-commands */ typedef enum esap_str { - STR_WPA = 0, - STR_ACCEPT_MAC_FILE = 1, - STR_DENY_MAC_FILE = 2, - STR_MAC_IN_INI = 3, - STR_PROT_FLAG_IN_INI = 4, - STR_DATA_RATE_IN_INI = 5, - STR_TX_POWER_IN_INI = 6, - STR_FRAG_THRESHOLD_IN_INI = 7, - STR_RTS_THRESHOLD_IN_INI = 8, - STR_COUNTRY_CODE_IN_INI = 9, + STR_WPA = 0, + STR_ACCEPT_MAC_FILE = 1, + STR_DENY_MAC_FILE = 2, + STR_MAC_IN_INI = 3, + STR_PROT_FLAG_IN_INI = 4, + STR_DATA_RATE_IN_INI = 5, + STR_TX_POWER_IN_INI = 6, + STR_FRAG_THRESHOLD_IN_INI = 7, + STR_RTS_THRESHOLD_IN_INI = 8, + STR_COUNTRY_CODE_IN_INI = 9, STR_INTRA_BSS_FORWARD_IN_INI = 10, - STR_WMM_IN_INI = 11, - STR_802DOT11D_IN_INI = 12, - STR_HT_80211N = 13, - STR_CTRL_INTERFACE = 14, - STR_INTERFACE = 15, - STR_EAP_SERVER = 16, - STR_AP_AUTOSHUTOFF = 17, - STR_AP_ENERGY_DETECT_TH = 18, + STR_WMM_IN_INI = 11, + STR_802DOT11D_IN_INI = 12, + STR_HT_80211N = 13, + STR_CTRL_INTERFACE = 14, + STR_INTERFACE = 15, + STR_EAP_SERVER = 16, + STR_AP_AUTOSHUTOFF = 17, + STR_AP_ENERGY_DETECT_TH = 18, eSTR_LAST } esap_str_t; -enum { - DISABLE = 0, - ENABLE = 1 -}; +enum { DISABLE = 0, ENABLE = 1 }; -struct Command -{ - s8 * name; - s8 * default_value; +struct Command { + s8* name; + s8* default_value; }; /** Function declartion */ s32 is_softap_enabled(void); -s8 *qsap_get_config_value(s8 *pfile, struct Command *pcmd, s8 *pbuf, u32 *plen); -int qsap_get_mode(s32 *pmode); +s8* qsap_get_config_value(s8* pfile, struct Command* pcmd, s8* pbuf, u32* plen); +int qsap_get_mode(s32* pmode); #endif