int switchToClientMode(void) { int intVal=0; int i; intVal=BANDMODESINGLE; apmib_set(MIB_WLAN_BAND2G5G_SELECT,(void *)&intVal); intVal=15; //A+B+G+N mode apmib_set(MIB_WLAN_BAND,(void *)&intVal); for(i=0 ; i<NUM_WLAN_INTERFACE ; i++) { unsigned char wlanif[10]; memset(wlanif,0x00,sizeof(wlanif)); sprintf(wlanif, "wlan%d",i); if(SetWlan_idx(wlanif)) { int intVal; intVal = SMACSPHY; apmib_set(MIB_WLAN_MAC_PHY_MODE, (void *)&intVal); } } SetWlan_idx("wlan0"); /*enable wlan0*/ intVal = 0; apmib_set(MIB_WLAN_WLAN_DISABLED, (void *)&intVal); /*set wlan0 mode to client mode*/ intVal = 1; apmib_set(MIB_WLAN_MODE, (void *)&intVal); /*set wlan0 Channel Width to 40Mhz*/ intVal=1; apmib_set(MIB_WLAN_CHANNEL_BONDING, (void *)&intVal) ; SetWlan_idx("wlan1"); /*disable wlan1*/ intVal = 1; apmib_set(MIB_WLAN_WLAN_DISABLED, (void *)&intVal); /*set wlan1 mode to client mode*/ intVal = 1; apmib_set(MIB_WLAN_MODE, (void *)&intVal); /*set wlan1 Channel Width to 40Mhz*/ intVal=1; apmib_set(MIB_WLAN_CHANNEL_BONDING, (void *)&intVal) ; SetWlan_idx("wlan0"); return 0; }
int getWispRptIfaceName(char*pIface,int wlanId) { int rptEnabled=0,wlanMode=0,opMode=0; char wlan_wanIfName[16]={0}; if(wlanId == 0) apmib_get(MIB_REPEATER_ENABLED1, (void *)&rptEnabled); else if(1 == wlanId) apmib_get(MIB_REPEATER_ENABLED2, (void *)&rptEnabled); else return -1; apmib_get(MIB_OP_MODE,(void *)&opMode); if(opMode!=WISP_MODE) return -1; apmib_save_wlanIdx(); sprintf(wlan_wanIfName,"wlan%d",wlanId); SetWlan_idx(wlan_wanIfName); //for wisp rpt mode,only care root ap apmib_get(MIB_WLAN_MODE, (void *)&wlanMode); if(AP_MODE==wlanMode && rptEnabled) {//root AP mode and rpt enabled, use -vxd as wanIf if(!strstr(pIface,"-vxd")) { strcat(pIface,"-vxd"); } }else { char * ptmp = strstr(pIface,"-vxd"); if(ptmp) memset(ptmp,0,sizeof(char)*strlen("-vxd")); } apmib_recov_wlanIdx(); return 0; }
void start_upnpd(int isgateway, int sys_op) { #ifdef HOME_GATEWAY int intValue=0, intValue1=0; if(SetWlan_idx("wlan0")){ apmib_get(MIB_WLAN_WSC_DISABLE, (void *)&intValue); } if(isgateway==1 && sys_op !=1) apmib_get(MIB_UPNP_ENABLED, (void *)&intValue1); else intValue1=0; if(intValue==0 && intValue1==0){//wps enabled and upnp igd is disabled RunSystemCmd(NULL_FILE, "mini_upnpd", "-wsc", "/tmp/wscd_config", "-daemon", NULL_STR); //system("mini_upnpd -wsc /tmp/wscd_config &"); }else if(intValue==1 && intValue1==1){//wps is disabled, and upnp igd is enabled RunSystemCmd(NULL_FILE, "mini_upnpd", "-igd", "/tmp/igd_config", "-daemon", NULL_STR); //system("mini_upnpd -igd /tmp/igd_config &"); }else if(intValue==0 && intValue1==1){//both wps and upnp igd are enabled RunSystemCmd(NULL_FILE, "mini_upnpd", "-wsc", "/tmp/wscd_config", "-igd", "/tmp/igd_config","-daemon", NULL_STR); //system("mini_upnpd -wsc /tmp/wscd_config -igd /tmp/igd_config &"); }else if(intValue==1 && intValue1==0){//both wps and upnp igd are disabled /*do nothing*/ } #endif }
short whichWlanIfIs(PHYBAND_TYPE_T phyBand) { int i; int ori_wlan_idx=wlan_idx; int ret=-1; for(i=0 ; i<NUM_WLAN_INTERFACE ; i++) { unsigned char wlanif[10]; memset(wlanif,0x00,sizeof(wlanif)); sprintf(wlanif, "wlan%d",i); if(SetWlan_idx(wlanif)) { int phyBandSelect; apmib_get(MIB_WLAN_PHY_BAND_SELECT, (void *)&phyBandSelect); if(phyBandSelect == phyBand) { ret = i; break; } } } wlan_idx=ori_wlan_idx; return ret; }
int setinit(int argc, char** argv) { int i, cmdRet=-1; int intValue=0, intValue1=0; char cmdBuffer[100], tmpBuff[512]; char *token=NULL, *savestr1=NULL; char tmp_args[16]; char Ip[32], Mask[32], Gateway[32]; char strPID[32]; int pid = 0; int wlan_support = 0; int index; int old_wlan_idx; int repeater_enable1=0; int repeater_enable2=0; int reinit=1; #ifdef AEI_WECB if( (!strcmp(argv[2], "aei")) && (!strcmp(argv[3], "mac"))) { #ifdef AEI_CTL_BRIDGE init_mac(); #endif up_mib_value(); RunSystemCmd(REINIT_FILE, "echo", "1", NULL_STR); RunSystemCmd("/var/sys_op", "echo", "1", NULL_STR); RunSystemCmd("/proc/sys/net/ipv4/ip_forward", "echo", "0", NULL_STR); RunSystemCmd(PROC_BR_IGMPPROXY, "echo", "0", NULL_STR); /*cleanup hardware tables*/ RunSystemCmd(HW_NAT_FILE, "echo", "2", NULL_STR); /*bridge mode*/ RunSystemCmd("/proc/br_wlanblock", "echo","0",NULL_STR); RunSystemCmd(NULL_FILE, "iptables", "-F", NULL_STR); RunSystemCmd(NULL_FILE, "iptables", "-F", "-t", "nat", NULL_STR); RunSystemCmd(NULL_FILE, "iptables", "-A", "INPUT", "-j", "ACCEPT", NULL_STR); RunSystemCmd(NULL_FILE, "rm", "-f", "/var/eth1_ip", NULL_STR); RunSystemCmd(NULL_FILE, "rm", "-f", "/var/ntp_run", NULL_STR); //set kthreadd high priority for performance RunSystemCmd(NULL_FILE, "renice -20 2", NULL_STR); //set ksoftirqd high priority for performance RunSystemCmd(NULL_FILE, "renice -20 3", NULL_STR); //set boa high priority if(isFileExist(WEBS_PID_FILE)){ pid=getPid_fromFile(WEBS_PID_FILE); if(pid != 0){ sprintf(strPID, "%d", pid); RunSystemCmd(NULL_FILE, "renice", "-20", strPID, NULL_STR); } } RunSystemCmd("/proc/custom_Passthru", "echo", (intValue & 0x1)?"1":"0", NULL_STR); /*enable igmp snooping*/ /*igmp snooping is independent with igmp proxy*/ #ifdef AEI_IGMPV3 RunSystemCmd(PROC_BR_IGMPVERSION, "echo", "3", NULL_STR); #else RunSystemCmd(PROC_BR_IGMPVERSION, "echo", "2", NULL_STR); #endif RunSystemCmd(PROC_BR_IGMPSNOOP, "echo", "1", NULL_STR); #if defined(AEI_DISABLE_IGMP_QUERY) || defined(AEI_CONTROL_IGMP_QUERY) RunSystemCmd(PROC_BR_IGMPQUERY, "echo", "0", NULL_STR); #else RunSystemCmd(PROC_BR_IGMPQUERY, "echo", "1", NULL_STR); #endif RunSystemCmd(PROC_BR_MLDSNOOP, "echo", "1", NULL_STR); RunSystemCmd(PROC_BR_MLDQUERY, "echo", "1", NULL_STR); /*increase routing cache rebuild count from 4 to 2048*/ RunSystemCmd(RT_CACHE_REBUILD_COUNT, "echo", "2048", NULL_STR); return 0; } #endif //step 1: 802.1x client support #ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT if((isFileExist(RS_USER_CERT_5G)==0) && (isFileExist(RS_ROOT_CERT_5G)==0) && (isFileExist(RS_USER_CERT_2G)==0) && (isFileExist(RS_ROOT_CERT_2G)==0)){ RunSystemCmd(NULL_FILE, "rsCert","-rd", NULL_STR); } #endif printf("Init Start...\n"); //step 2 num_wlan_interface=get_interfaces_list(5, "wlan", NULL, wlan_interface, sizeof(wlan_interface)); num_wlan_virtual_interface=get_interfaces_list(9, "wlan", "-va", wlan_virtual_interface, sizeof(wlan_virtual_interface)); /*currently, we just support init gw/ap all */ // clean_process(BRIDGE_MODE,0,1, 1, "br0", wlan_interface, "eth1"); RunSystemCmd(HW_NAT_FILE, "echo", "2", NULL_STR); /*bridge mode*/ RunSystemCmd(NULL_FILE, "killall", "-9", "reload", NULL_STR); /*init wlan interface*/ //ifconfig rootap down && flash set_mib for(i=0;i<NUM_WLAN_INTERFACE;i++) { int wlan_disable = 1; unsigned char wlan_name[10]; memset(wlan_name,0x00,sizeof(wlan_name)); int j; for(j=0; j<NUM_VWLAN; j++){ sprintf(wlan_name, "wlan%d-va%d",i, j); RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "down", NULL_STR); } sprintf(wlan_name, "wlan%d",i); apmib_save_wlanIdx(); if(SetWlan_idx(wlan_name)) { apmib_get( MIB_WLAN_WLAN_DISABLED, (void *)&wlan_disable); if(wlan_disable == 1) { RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "down", NULL_STR); RunSystemCmd(NULL_FILE, "iwpriv", wlan_name, "radio_off", NULL_STR); } else { RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "down", NULL_STR); cmdRet=RunSystemCmd(NULL_FILE, "flash", "set_mib", wlan_name, NULL_STR); if(cmdRet != 0) { printf("init %s failed!\n", wlan_name); continue; } } } apmib_recov_wlanIdx(); } //ifconfig vap down && flash set_mib if(wlan_interface[0]){ if(wlan_virtual_interface[0]){ token=NULL; savestr1=NULL; sprintf(tmpBuff, "%s", wlan_virtual_interface); token = strtok_r(tmpBuff," ", &savestr1); do{ if (token == NULL){ break; }else{ RunSystemCmd(NULL_FILE, "ifconfig", token, "down", NULL_STR); RunSystemCmd(NULL_FILE, "flash", "set_mib", token, NULL_STR);/*set virtual wlan iface*/ } token = strtok_r(NULL, " ", &savestr1); }while(token !=NULL); } } /////////////////////////////////////////////////////////// //set_br_interface(tmpBuff); sprintf(tmpBuff, "%s %s", wlan_interface, wlan_virtual_interface); setbridge(tmpBuff);//ifconfig wlanx up or not sprintf(br_interface, "%s", "br0"); start_wlanapp(1); system("reload -k /var/wlsch.conf &"); #if defined(CONFIG_IPV6) set_ipv6(BRIDGE_MODE); #endif return 0; }
int switchFromClientMode(void) { int i; int macPhyMode; int wlanBand2G5GSelect; int val; /*qinjunjie:should not force config pocket as to dual mac dual phy in AP/Router mode, because, if user config pocket as single mac single phy in AP/Router mode, but change to dual mac dual phy after reboot, ,it's un-reasonable*/ apmib_get(MIB_WLAN_BAND2G5G_SELECT,(void *)&wlanBand2G5GSelect); /* Set both wireless interface is radio on and DMACDPHY */ if(wlanBand2G5GSelect == BANDMODEBOTH) { int intVal; for(i=0 ; i<NUM_WLAN_INTERFACE ; i++) { unsigned char wlanif[10]; memset(wlanif,0x00,sizeof(wlanif)); sprintf(wlanif, "wlan%d",i); if(SetWlan_idx(wlanif)) { intVal = DMACDPHY; apmib_set(MIB_WLAN_MAC_PHY_MODE, (void *)&intVal); intVal = 0; apmib_set(MIB_WLAN_WLAN_DISABLED, (void *)&intVal); } } /* 92d rule, 5g must up in wlan0 */ /* phybandcheck */ if(whichWlanIfIs(PHYBAND_5G) != 0) { swapWlanMibSetting(0,1); } SetWlan_idx("wlan0"); apmib_get(MIB_WLAN_BAND,(void *)&intVal); if(intVal == 15) //15:abgn there is no abgn band selection in ap mode { intVal = BAND_5G_11AN; apmib_set(MIB_WLAN_BAND,(void *)&intVal); } SetWlan_idx("wlan1"); apmib_get(MIB_WLAN_BAND,(void *)&intVal); if(intVal == 15) //15:abgn there is no abgn band selection in ap mode { intVal = BAND_11BG+BAND_11N; apmib_set(MIB_WLAN_BAND,(void *)&intVal); } } else if(wlanBand2G5GSelect == BANDMODESINGLE) { int intVal=0; for(i=0 ; i<NUM_WLAN_INTERFACE ; i++) { unsigned char wlanif[10]; memset(wlanif,0x00,sizeof(wlanif)); sprintf(wlanif, "wlan%d",i); if(SetWlan_idx(wlanif)) { int intVal; intVal = SMACSPHY; apmib_set(MIB_WLAN_MAC_PHY_MODE, (void *)&intVal); } } SetWlan_idx("wlan0"); intVal = 0; apmib_set(MIB_WLAN_WLAN_DISABLED, (void *)&intVal); apmib_get(MIB_WLAN_BAND,(void *)&intVal); if(intVal == 15) //15:abgn there is no abgn band selection in ap mode { apmib_get(MIB_WLAN_PHY_BAND_SELECT, (void *)&intVal); if(intVal == PHYBAND_2G) intVal = BAND_11BG+BAND_11N; else intVal = BAND_5G_11AN; apmib_set(MIB_WLAN_BAND,(void *)&intVal); } SetWlan_idx("wlan1"); intVal = 1; apmib_set(MIB_WLAN_WLAN_DISABLED, (void *)&intVal); apmib_get(MIB_WLAN_BAND,(void *)&intVal); if(intVal == 15) //15:abgn there is no abgn band selection in ap mode { apmib_get(MIB_WLAN_PHY_BAND_SELECT, (void *)&intVal); if(intVal == PHYBAND_2G) intVal = BAND_11BG+BAND_11N; else intVal = BAND_5G_11AN; apmib_set(MIB_WLAN_BAND,(void *)&intVal); } } /*set wlan0 mode to ap mode*/ SetWlan_idx("wlan0"); val = 0; apmib_set(MIB_WLAN_MODE, (void *)&val); /*set wlan1 mode to ap mode*/ SetWlan_idx("wlan1"); val = 0; apmib_set(MIB_WLAN_MODE, (void *)&val); SetWlan_idx("wlan0"); return 0; }