void swapWlanMibSetting(unsigned char wlanifNumA, unsigned char wlanifNumB) { unsigned char *wlanMibBuf=NULL; unsigned int totalSize = sizeof(CONFIG_WLAN_SETTING_T)*(NUM_VWLAN_INTERFACE+1); // 4vap+1rpt+1root wlanMibBuf = malloc(totalSize); if(wlanMibBuf != NULL) { memcpy(wlanMibBuf, pMib->wlan[wlanifNumA], totalSize); memcpy(pMib->wlan[wlanifNumA], pMib->wlan[wlanifNumB], totalSize); memcpy(pMib->wlan[wlanifNumB], wlanMibBuf, totalSize); free(wlanMibBuf); } #ifdef UNIVERSAL_REPEATER int rptEnable1, rptEnable2; char rptSsid1[MAX_SSID_LEN], rptSsid2[MAX_SSID_LEN]; memset(rptSsid1, 0x00, MAX_SSID_LEN); memset(rptSsid2, 0x00, MAX_SSID_LEN); apmib_get(MIB_REPEATER_ENABLED1, (void *)&rptEnable1); apmib_get(MIB_REPEATER_ENABLED2, (void *)&rptEnable2); apmib_get(MIB_REPEATER_SSID1, (void *)rptSsid1); apmib_get(MIB_REPEATER_SSID2, (void *)rptSsid2); apmib_set(MIB_REPEATER_ENABLED1, (void *)&rptEnable2); apmib_set(MIB_REPEATER_ENABLED2, (void *)&rptEnable1); apmib_set(MIB_REPEATER_SSID1, (void *)rptSsid2); apmib_set(MIB_REPEATER_SSID2, (void *)rptSsid1); #endif }
void Init_Internet(int argc, char** argv) { #ifdef HOME_GATEWAY int wisp_id=0, wan_mode=0, opmode=0; char br_interface[16]={0}; char wan_interface[16]={0}; char tmp_args[16]={0}; if(argc < 4) return; apmib_get(MIB_OP_MODE,(void *)&opmode); if(opmode == BRIDGE_MODE) return; apmib_get(MIB_WISP_WAN_ID,(void *)&wisp_id); sprintf(tmp_args, "%s",argv[1]); if(!strcmp(tmp_args, "pppoe")) wan_mode=3; else if(!strcmp(tmp_args, "pptp")) wan_mode=4; else if(!strcmp(tmp_args, "l2tp")) wan_mode=6; else{ printf("Un-support wan type for init\n"); return; } sprintf(br_interface, "%s", "br0"); sprintf(wan_interface, "%s",argv[3]); start_wan(wan_mode, opmode, wan_interface, br_interface, wisp_id, 0); #endif }
/* Fix whan device is change wlan mode from client to AP or Router. * * The CIPHER_SUITE of wpa or wpa2 can't be tkip */ static int check_wpa_cipher_suite() { int wlan_band, wlan_onoff_tkip, wlan_encrypt, wpaCipher, wpa2Cipher, wdsEncrypt; apmib_get( MIB_WLAN_BAND, (void *)&wlan_band) ; apmib_get( MIB_WLAN_11N_ONOFF_TKIP, (void *)&wlan_onoff_tkip) ; apmib_get( MIB_WLAN_ENCRYPT, (void *)&wlan_encrypt); apmib_get( MIB_WLAN_WDS_ENCRYPT, (void *)&wdsEncrypt); if(wlan_onoff_tkip == 0) //Wifi request { if(wlan_band == 8 || wlan_band == 10 || wlan_band == 11)//8:n; 10:gn; 11:bgn { if(wlan_encrypt ==ENCRYPT_WPA || wlan_encrypt ==ENCRYPT_WPA2){ wpaCipher = WPA_CIPHER_AES; apmib_set(MIB_WLAN_WPA_CIPHER_SUITE, (void *)&wpaCipher); wpa2Cipher = WPA_CIPHER_AES; apmib_set(MIB_WLAN_WPA2_CIPHER_SUITE, (void *)&wpa2Cipher); } if(wdsEncrypt == WDS_ENCRYPT_TKIP) { wdsEncrypt = WDS_ENCRYPT_DISABLED; apmib_set( MIB_WLAN_WDS_ENCRYPT, (void *)&wdsEncrypt); } } } }
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 }
void Reset_Domain_Query_Setting(void) { int opmode=-1; int lan_dhcp_mode=0; int wlan_mode_root=0; struct sockaddr hwaddr; unsigned char *pMacAddr; unsigned char cmdBuffer[100]; char lan_domain_name[ MAX_NAME_LEN]={0}; apmib_get( MIB_DOMAIN_NAME, (void *)lan_domain_name); apmib_get(MIB_OP_MODE,(void *)&opmode); apmib_get(MIB_DHCP,(void *)&lan_dhcp_mode); apmib_get( MIB_WLAN_MODE, (void *)&wlan_mode_root); if(opmode==1 &&((wlan_mode_root==1 && lan_dhcp_mode==15) || (wlan_mode_root==0 && lan_dhcp_mode==15)) && lan_domain_name[0]){ system("echo 1 > /proc/pocket/en_filter"); if(getInAddr("br0", HW_ADDR, (void *)&hwaddr)){ pMacAddr = hwaddr.sa_data; sprintf(cmdBuffer, "echo \"%s %02X%02X%02X%02X%02X%02X 0\" > /proc/pocket/filter_conf","00000000", pMacAddr[0], pMacAddr[1],pMacAddr[2], pMacAddr[3], pMacAddr[4], pMacAddr[5]); }else{ sprintf(cmdBuffer, "echo \"%s 000000000000 0\" > /proc/pocket/filter_conf","00000000"); } system(cmdBuffer); }else{ system("echo 0 > /proc/pocket/en_filter"); } }
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 set_lan_dhcpc(char *iface) { char script_file[100], deconfig_script[100], pid_file[100]; char *strtmp=NULL; char tmp[32], Ip[32], Mask[32], Gateway[32]; char cmdBuff[200]; unsigned char host_name[MAX_NAME_LEN]={0}; sprintf(script_file, "/usr/share/udhcpc/%s.sh", iface); /*script path*/ sprintf(deconfig_script, "/usr/share/udhcpc/%s.deconfig", iface);/*deconfig script path*/ sprintf(pid_file, "/etc/udhcpc/udhcpc-%s.pid", iface); /*pid path*/ apmib_get( MIB_IP_ADDR, (void *)tmp); strtmp= inet_ntoa(*((struct in_addr *)tmp)); sprintf(Ip, "%s",strtmp); apmib_get( MIB_SUBNET_MASK, (void *)tmp); strtmp= inet_ntoa(*((struct in_addr *)tmp)); sprintf(Mask, "%s",strtmp); apmib_get( MIB_DEFAULT_GATEWAY, (void *)tmp); strtmp= inet_ntoa(*((struct in_addr *)tmp)); sprintf(Gateway, "%s",strtmp); Create_script(deconfig_script, iface, LAN_NETWORK, Ip, Mask, Gateway); apmib_get( MIB_HOST_NAME, (void *)host_name); if(host_name[0]) sprintf(cmdBuff, "udhcpc -i %s -p %s -s %s -h %s &", iface, pid_file, script_file, host_name); else sprintf(cmdBuff, "udhcpc -i %s -p %s -s %s &", iface, pid_file, script_file); system(cmdBuff); }
/*method to start reload is co-operate to parse rule of reload.c*/ void start_wlan_by_schedule(int index) { int intValue=0, intValue1=0, i=0, entryNum=0, bak_idx=0, bak_vidx=0; char tmp1[64]={0}; SCHEDULE_T wlan_sched; int newfile=1; bak_idx=wlan_idx; wlan_idx=index; bak_idx=vwlan_idx; vwlan_idx=0; apmib_get(MIB_WLAN_WLAN_DISABLED, (void *)&intValue); #define WLAN_SCHEDULE_FILE "/var/wlsch.conf" sprintf(tmp1,WLAN_SCHEDULE_FILE"%d",index); unlink(tmp1); if(intValue==0){ apmib_get(MIB_WLAN_SCHEDULE_ENABLED, (void *)&intValue1); apmib_get(MIB_WLAN_SCHEDULE_TBL_NUM, (void *)&entryNum); if(intValue1==1 && entryNum > 0){ for (i=1; i<=entryNum; i++) { *((char *)&wlan_sched) = (char)i; apmib_get(MIB_WLAN_SCHEDULE_TBL, (void *)&wlan_sched); char line_buffer[100]={0}; if(wlan_sched.eco == 1 && !(wlan_sched.fTime == 0 && wlan_sched.tTime == 0)) { sprintf(line_buffer,"%d,%d,%d,%d\n",i,wlan_sched.day,wlan_sched.fTime, wlan_sched.tTime); sprintf(tmp1,WLAN_SCHEDULE_FILE"%d",index); write_line_to_file(tmp1, (newfile==1?1:2), line_buffer); newfile = 2; } } if(index == (NUM_WLAN_INTERFACE-1)){ sprintf(tmp1, "reload -k %s &", WLAN_SCHEDULE_FILE); system(tmp1); } } else{ /* do not care schedule*/ if(index == (NUM_WLAN_INTERFACE-1)){ sprintf(tmp1, "reload -k %s &", WLAN_SCHEDULE_FILE); system(tmp1); } } } else{ /*wlan is disabled, we do not care wlan schedule*/ if(index ==(NUM_WLAN_INTERFACE-1)){ sprintf(tmp1, "reload -k %s &", WLAN_SCHEDULE_FILE); system(tmp1); } } vwlan_idx=bak_vidx; wlan_idx=bak_idx; }
static void start_dnrd() { unsigned char Ip[32], cmdBuffer[100], tmpBuff[200]; unsigned char domanin_name[MAX_NAME_LEN]; int wlan_mode=0; apmib_get( MIB_WLAN_MODE, (void *)&wlan_mode); system("killall -9 dnrd 2> /dev/null"); apmib_get( MIB_IP_ADDR, (void *)tmpBuff); sprintf(Ip, "%s", inet_ntoa(*((struct in_addr *)tmpBuff))); apmib_get( MIB_DOMAIN_NAME, (void *)domanin_name); system("rm -f /var/hosts 2> /dev/null"); memset(cmdBuffer, 0x00, sizeof(cmdBuffer)); if(strlen(domanin_name) == 0) { /* if(getFilter_Type() == 0) //1:client { sprintf(cmdBuffer,"%s\\%s\n", Ip, "AlwaysHost"); } else */ { if(wlan_mode==0){//ap mode sprintf(cmdBuffer,"%s\\%s\n", Ip, "RealTekAP.com|RealTekAP.net"); }else if(wlan_mode==1){//client mode sprintf(cmdBuffer,"%s\\%s\n", Ip, "RealTekCL.com|RealTekCL.net"); } } write_line_to_file("/etc/hosts", 1, cmdBuffer); } else { /* if(getFilter_Type() == 0) //1:client { sprintf(cmdBuffer,"%s\\%s\n", Ip, "AlwaysHost"); } else */ { if(wlan_mode==0){//ap mode sprintf(cmdBuffer,"%s\\%s%s%s%s\n", Ip, domanin_name, "AP.com|",domanin_name, "AP.net"); }else if(wlan_mode==1){ sprintf(cmdBuffer,"%s\\%s%s%s%s\n", Ip, domanin_name, "CL.com|",domanin_name, "CL.net"); } } write_line_to_file("/etc/hosts", 1, cmdBuffer); } system("dnrd --cache=off -s 168.95.1.1"); }
int init_mac() { char tmpBuff[200], cmdBuffer[100]; // set mac address for eth apmib_get(MIB_HW_NIC0_ADDR, (void *)tmpBuff); sprintf(cmdBuffer, "%02x%02x%02x%02x%02x%02x", (unsigned char)tmpBuff[0], (unsigned char)tmpBuff[1], (unsigned char)tmpBuff[2], (unsigned char)tmpBuff[3], (unsigned char)tmpBuff[4], (unsigned char)tmpBuff[5]); RunSystemCmd(NULL_FILE, "ifconfig", "eth0", "hw", "ether",cmdBuffer, NULL_STR); //printf( "JBB AEI MAC: %s - %s\n", "eth0", cmdBuffer ); // set mac address for wifi char wlan_name[16] = {0}; int para_id; for( wlan_idx=0; wlan_idx<2; wlan_idx++ ) { for( vwlan_idx=0; vwlan_idx<=4; vwlan_idx++ ) { switch(vwlan_idx) { case 0: para_id = MIB_HW_WLAN_ADDR; break; case 1: para_id = MIB_HW_WLAN_ADDR1; break; case 2: para_id = MIB_HW_WLAN_ADDR2; break; case 3: para_id = MIB_HW_WLAN_ADDR3; break; case 4: para_id = MIB_HW_WLAN_ADDR4; break; } apmib_get(para_id, (void *)tmpBuff); sprintf(cmdBuffer, "%02x%02x%02x%02x%02x%02x", (unsigned char)tmpBuff[0], (unsigned char)tmpBuff[1], (unsigned char)tmpBuff[2], (unsigned char)tmpBuff[3], (unsigned char)tmpBuff[4], (unsigned char)tmpBuff[5]); if(vwlan_idx) snprintf(wlan_name, sizeof(wlan_name), "wlan%d-va%d", wlan_idx, vwlan_idx-1 ); else snprintf(wlan_name, sizeof(wlan_name), "wlan%d", wlan_idx); //printf( "JBB AEI MAC: %s - %s\n", wlan_name, cmdBuffer ); RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "down", NULL_STR); RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "hw", "ether", cmdBuffer, NULL_STR); } } }
void set_log(void) { int intValue=0, intValue1=0; char tmpBuffer[32]; char syslog_para[32]; char localServer[32]; apmib_get(MIB_SCRLOG_ENABLED, (void*)&intValue); if(intValue !=0 && intValue !=2 && intValue !=4 && intValue !=6 && intValue !=8 && intValue !=10 && intValue !=12 && intValue !=14) { apmib_get(MIB_REMOTELOG_ENABLED, (void*)&intValue1); if(intValue1 != 0){ apmib_get(MIB_REMOTELOG_SERVER, (void *)tmpBuffer); if (memcmp(tmpBuffer, "\x0\x0\x0\x0", 4)){ #ifdef RINGLOG /* ring log */ sprintf(localServer, "%s", inet_ntoa(*((struct in_addr *)tmpBuffer))); system("rm /var/log/log_split >/dev/null 2>&1"); sprintf(tmpBuffer, "echo %d > /var/log/log_split", LOG_SPLIT); system(tmpBuffer); sprintf(tmpBuffer, "%d", MAX_LOG_SIZE); sprintf(syslog_para, "%d", LOG_SPLIT); fprintf(stderr, "syslog will use %dKB for log(%d rotate, 1 original, %dKB for each)\n", MAX_LOG_SIZE * (LOG_SPLIT+1), LOG_SPLIT, MAX_LOG_SIZE); RunSystemCmd(NULL_FILE, "syslogd", "-L","-R", localServer, "-s", tmpBuffer, "-b", syslog_para, NULL_STR); #else sprintf(syslog_para, "%s", inet_ntoa(*((struct in_addr *)tmpBuffer))); RunSystemCmd(NULL_FILE, "syslogd", "-L", "-R", syslog_para, NULL_STR); #endif } }else{ //### add by sen_liu 2011.4.21 sync the system log update (enlarge from 1 pcs to 8 pcs) to SDKv2.5 from kernel 2.4 #ifdef RINGLOG /* ring log */ system("rm /var/log/log_split >/dev/null 2>&1"); sprintf(tmpBuffer, "echo %d > /var/log/log_split", LOG_SPLIT); system(tmpBuffer); sprintf(tmpBuffer, "%d", MAX_LOG_SIZE); sprintf(syslog_para, "%d", LOG_SPLIT); fprintf(stderr, "syslog will use %dKB for log(%d rotate, 1 original, %dKB for each)\n", MAX_LOG_SIZE * (LOG_SPLIT+1), LOG_SPLIT, MAX_LOG_SIZE); RunSystemCmd(NULL_FILE, "syslogd", "-L", "-s", tmpBuffer, "-b", syslog_para, NULL_STR); #else //### end RunSystemCmd(NULL_FILE, "syslogd", "-L", NULL_STR); #endif } RunSystemCmd(NULL_FILE, "klogd", NULL_STR); } return; }
int getDnsv6Info(dnsv6CfgParam_t *entry) { if ( !apmib_get(MIB_IPV6_DNSV6_PARAM,(void *)entry)){ return -1 ; } return 0; }
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 getAddr6Info(addrIPv6CfgParam_t *entry) { if ( !apmib_get(MIB_IPV6_ADDR_PARAM,(void *)entry)){ return -1 ; } return 0; }
int getTunnel6Info(tunnelCfgParam_t *entry) { if ( !apmib_get(MIB_IPV6_TUNNEL_PARAM,(void *)entry)){ return -1 ; } return 0; }
int getDhcpv6sInfo(dhcp6sCfgParam_t *entry) { if ( !apmib_get(MIB_IPV6_DHCPV6S_PARAM,(void *)entry)){ return -1 ; } return 0; }
void Init_QoS(int argc, char** argv) { #ifdef HOME_GATEWAY int wisp_id=0, wan_mode=0, opmode=0; apmib_get(MIB_OP_MODE,(void *)&opmode); if(opmode == 1) return; apmib_get(MIB_WISP_WAN_ID,(void *)&wisp_id); apmib_get(MIB_WAN_DHCP,(void *)&wan_mode); set_QoS(opmode, wan_mode, wisp_id); #endif }
/*New BT Torrent*/ void formBTNewTorrent(request *wp, char *path, char *query) { char filepath[128]; char *strptr; char *filename; char *nextwebpage; nextwebpage=req_get_cstream_var(wp, "submit-url",""); strptr=req_get_cstream_var(wp,("filename"),""); char_replace(strptr,'\\','/'); filename=strrchr(strptr, '/'); if(filename == NULL) { printf("ERROR, filename NULL\n"); return; } //printf("filename %s \n",filename); if(!apmib_get(MIB_BT_UPLOAD_DIR,filepath)) { ERR_MSG("Get seeds directory failed"); return; } if(!dirExits(filepath)) { ERR_MSG("Seeds Directory Not Exists"); return; } strcat(filepath,filename); //printf("filepath %s\n",filepath); bt_saveTorrentfile(filepath,wp->post_data, wp->post_data_len); send_redirect_perm(wp,nextwebpage); }
int getRadvdInfo(radvdCfgParam_t *entry) { if ( !apmib_get(MIB_IPV6_RADVD_PARAM,(void *)entry)){ return -1 ; } return 0; }
int isBandModeBoth() { int val; apmib_get(MIB_WLAN_BAND2G5G_SELECT, (void *)&val); if(val == BANDMODEBOTH) return 1; else return 0; }
int kill_ppp(void) { #if defined(PPPOE_DISC_FLOW_PATCH) int sessid = 0; char cmdBuf[50],tmpBuff[30]; int ppp_flag = 0; memset(tmpBuff,0, sizeof(tmpBuff)); apmib_get(MIB_PPP_SESSION_NUM, (void *)&sessid); apmib_get(MIB_PPP_SERVER_MAC, (void *)tmpBuff); apmib_get(MIB_PPP_NORMAL_FINISH, (void *)&ppp_flag); if(!ppp_flag) //1:nomal 0:abnormal { if(memcmp(tmpBuff, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LEN)) { sprintf(cmdBuf,"flash clearppp %d %02x%02x%02x%02x%02x%02x", sessid,(unsigned char)tmpBuff[0],(unsigned char)tmpBuff[1],(unsigned char)tmpBuff[2],(unsigned char)tmpBuff[3],(unsigned char)tmpBuff[4],(unsigned char)tmpBuff[5]); system(cmdBuf); sessid = 0; memset(tmpBuff,0,sizeof(tmpBuff)); apmib_set(MIB_PPP_SESSION_NUM, (void *)&sessid); apmib_set(MIB_PPP_SERVER_MAC, (void *)tmpBuff); } } //system("flash set PPP_NORMAL_FINISH 0"); ppp_flag = 0 ; apmib_set(MIB_PPP_NORMAL_FINISH, (void *)&ppp_flag); apmib_update(CURRENT_SETTING); #else int sessid = 0; char cmdBuf[50],tmpBuff[30]; memset(tmpBuff,0, sizeof(tmpBuff)); apmib_get(MIB_PPP_SESSION_NUM, (void *)&sessid); apmib_get(MIB_PPP_SERVER_MAC, (void *)tmpBuff); sprintf(cmdBuf,"flash clearppp %d %02x%02x%02x%02x%02x%02x",sessid,(unsigned char)tmpBuff[0],(unsigned char)tmpBuff[1],(unsigned char)tmpBuff[2],(unsigned char)tmpBuff[3],(unsigned char)tmpBuff[4],(unsigned char)tmpBuff[5]); system(cmdBuf); sleep(2); // Wait util pppoe server reply PADT, then start pppoe dialing, otherwise pppoe server will reply PADS with PPPoE tags: Generic-Error. #endif return 1; }
static int ulinker_get_decided_mode() { int mode; int auto_wan; apmib_get(MIB_ULINKER_AUTO, (void *)&auto_wan); if (auto_wan == 1) mode = get_flag_value(ULINKER_MODE_FLAG); else { #if 0 int op_mode, wan_mode, dhcp_mode, wlan_mode; apmib_get(MIB_OP_MODE, (void *)&op_mode); apmib_get(MIB_WAN_DHCP, (void *)&wan_mode); apmib_get(MIB_DHCP, (void *)&dhcp_mode); apmib_get(MIB_WLAN_MODE, (void *)&wlan_mode); if (op_mode == 0) { mode = ULINKER_RT_DHCP_MODE: mode = ULINKER_RT_PPPOE_MODE: } else if (op_mode == 1) {
static inline int set_eth1_mac(void) { char *mac = calloc(sizeof(char), 20); char *buf = calloc(sizeof(char), 64); /* set eth1 mac */ #if 0 //fixme apmib_get(MIB_HW_NIC1_ADDR, (void *)mac); #else get_mib(mac, "HW_NIC1_ADDR"); #endif sprintf(buf, "ifconfig eth1 hw ether %s", mac); system(buf); if (mac) free(mac); if (buf) free(buf); return 1; }
unsigned char GetDhcpValueToSetFixedIP( void ) { #if 0 int ret; DHCP_T dhcp; ret = apmib_get( MIB_DHCP, &dhcp ); if( ret ) { /* DHCP client -> Disable */ if( dhcp == DHCP_CLIENT ) dhcp = DHCP_DISABLED; } else dhcp = DHCP_DISABLED; return dhcp; #else return NET_DHCP_DISABLED; #endif }
int GetGatewayOperationMode( void ) { /* * Mode LAN WAN * ---------- ----- ------ * 0: gateway br0 eth1 <-- WAN, eth1 * 1: bridge br0 N/A <-- LAN, br0 * 2: wisp br0 wlan0 <-- WAN, wlan0 */ OPMODE_T opmode; /* refresh flash content */ // TODO: remove apmib_reinit //apmib_reinit(); if ( !apmib_get( MIB_OP_MODE, (void *)&opmode) ) return 0; return opmode; }
int up_mib_value() { int old_ver=0; int new_ver=0; int i=0; apmib_get(MIB_MIB_VER, (void *)&old_ver); new_ver = atoi(update_mib[0].value); if(old_ver == new_ver) { return -1; } else printf("MIB Version update!\n"); i=0; while(new_mib[i].id != 0) { upmib_setMib(new_mib,i); //apmib_set(new_mib[i].id,strToValue(new_mib[i].value,new_mib[i].type)); //RunSystemCmd(NULL_FILE, "flash", "set", new_mib[i].name, new_mib[i].value, NULL_STR); i++; } i=0; while(update_mib[i].id != 0) { upmib_setMib(update_mib,i); //apmib_set(update_mib[i].id,strToValue(update_mib[i].value,update_mib[i].type)); // RunSystemCmd(NULL_FILE, "flash", "set", update_mib[i].name, update_mib[i].value, NULL_STR); i++; } apmib_update(HW_SETTING); apmib_update(DEFAULT_SETTING); apmib_update(CURRENT_SETTING); return 0; }
} void handleForm(request *req) { char *ptr; int i; #define SCRIPT_ALIAS "/boafrm/" //fprintf(stderr, "###%s:%d req->request_uri=%s###\n", __FILE__, __LINE__, req->request_uri); #ifdef ACTIONTEC_WCB int cgi_flag = 1; ptr = strstr(req->request_uri, ".cgi"); if(!ptr) { ptr = strstr(req->request_uri, SCRIPT_ALIAS); cgi_flag = 0; } #else ptr = strstr(req->request_uri, SCRIPT_ALIAS); #endif apmib_get(MIB_WAN_DHCP, (void *)&last_wantype); if (ptr==NULL) { send_r_not_found(req); return; } else { form_name_t *now_form; #ifdef ACTIONTEC_WCB if(cgi_flag) ptr = '\0'; else ptr += strlen(SCRIPT_ALIAS); #else ptr+=strlen(SCRIPT_ALIAS); #endif for (i=0; root_form[i].name!=NULL; i++) { now_form = &root_form[i]; #ifdef ACTIONTEC_WCB if((cgi_flag && strstr(req->request_uri, now_form->name)) || (!cgi_flag && (strlen(ptr) == strlen(now_form->name)) && (memcmp(ptr,now_form->name,strlen(now_form->name))==0))) { #else if ((strlen(ptr) == strlen(now_form->name)) && (memcmp(ptr,now_form->name,strlen(now_form->name))==0)) { #endif send_r_request_ok2(req); /* All's well */ /*#ifdef USE_AUTH if (req->auth_flag == 1) { // user //brad add for wizard if(!strcmp(req->request_uri,"/boafrm/formSetEnableWizard")){ send_redirect_perm(req, "/wizard_back.htm"); }else{ //ptr= (char *)req_get_cstream_var(req, ("webpage"), ("")); //strcpy(last_url, ptr); //sprintf(ok_msg,"%s","\"Only <b>admin</b> account can change the settings.<br>\""); //send_redirect_perm(req, WEB_PAGE_APPLY_OK); ptr= (char *)req_get_cstream_var(req, ("webpage"), ("")); if(ptr ==NULL) sprintf(last_url, "/%s", directory_index); else strcpy(last_url, ptr); if(!strcmp(req->request_uri,"/boafrm/formSetRestorePrev") || !strcmp(req->request_uri,"/boafrm/formSetFactory")){ sprintf(last_url, "%s","util_savesetting.asp"); if (req->upload_data) free(req->upload_data); } if(!strcmp(req->request_uri,"/boafrm/formFirmwareUpgrade")){ sprintf(last_url, "%s","util_firmware.asp"); if (req->upload_data) free(req->upload_data); } if(!strcmp(req->request_uri,"/boafrm/formWPS")){ wps_action= (char *)req_get_cstream_var(req, ("wpsAction"), ("")); if(!strcmp(wps_action, "pbc") || !strcmp(wps_action, "pin")){ now_form->function(req,NULL,NULL); freeAllTempStr(); return; } } sprintf(ok_msg,"%s","\"Only <b>admin</b> account can change the settings.<br>\""); send_redirect_perm(req, WEB_PAGE_APPLY_OK); } } else #endif*/ now_form->function(req,NULL,NULL); update_content_length(req); freeAllTempStr(); return; } } } send_r_not_found(req); } void handleScript(request *req,char *left1,char *right1) { char *left=left1,*right=right1; asp_name_t *now_asp; unsigned int funcNameLength; int i, j; left += 2; right -= 1; while (1) { while (*left==' ') {if(left>=right) break;++left;} while (*left==';') {if(left>=right) break;++left;} while (*left=='(') {if(left>=right) break;++left;} while (*left==')') {if(left>=right) break;++left;} while (*left==',') {if(left>=right) break;++left;} if (left >= right) break; /* count the function name length */ { char *ptr = left; funcNameLength = 0; while (*ptr!='(' && *ptr!=' ') { ptr++; funcNameLength++; if ((unsigned int )ptr >= (unsigned int)right) { break; } } } for (j=0; root_asp[j].name!=NULL; j++) { now_asp = &root_asp[j]; if ((strlen(now_asp->name) == funcNameLength) && (memcmp(left,now_asp->name,strlen(now_asp->name))==0)) { char *leftc,*rightc; int argc=0; char *argv[8]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; left += strlen(now_asp->name); while (1) { int size,exit=0; while (1) { if (*left==')') { exit=1; break; } if (*left=='\"') break; if ((unsigned int)left > (unsigned int)right) { exit=1; break; } left++; } if (exit==1) break; leftc = left; leftc++; rightc = strstr(leftc,"\""); if (rightc==NULL) break; size = (unsigned int)rightc-(unsigned int)leftc+1; argv[argc] = (char *)malloc(size); if (argv[argc]==NULL) break; memcpy(argv[argc],leftc,size-1); argv[argc][size-1] = '\0'; argc++; left = rightc + 1; } //fprintf(stderr, "###%s:%d now_asp->name=%s###\n", __FILE__, __LINE__, now_asp->name); now_asp->function(req,argc,argv); for (i=0; i<argc; i++) free(argv[i]); break; } } ++left;
} void asp_init(int argc,char **argv) { int i, num; char interface[10]; extern int getWlStaNum(char *interface, int *num); root_temp.next=NULL; root_temp.str=NULL; // david ---- queury number of wlan interface ---------------- wlan_num = 0; for (i=0; i<NUM_WLAN_INTERFACE; i++) { sprintf(interface, "wlan%d", i); if (getWlStaNum(interface, &num) < 0) break; wlan_num++; } #if defined(VOIP_SUPPORT) && defined(ATA867x) // no wlan interface in ATA867x #else if (wlan_num==0) wlan_num = 1; // set 1 as default #endif #ifdef MBSSID vwlan_num = NUM_VWLAN_INTERFACE; #endif //--------------------------------------------------------- //conti: root_temp.next = NULL; root_temp.str = NULL; if (apmib_init() == 0) { printf("Initialize AP MIB failed!\n"); return; } save_cs_to_file(); apmib_get(MIB_WAN_DHCP, (void *)&last_wantype); /* determine interface name by mib value */ WAN_IF = "eth1"; BRIDGE_IF = "br0"; ELAN_IF = "eth0"; ELAN2_IF = "eth2"; ELAN3_IF = "eth3"; ELAN4_IF = "eth4"; #ifdef HOME_GATEWAY PPPOE_IF = "ppp0"; #elif defined(VOIP_SUPPORT) && defined(ATA867x) BRIDGE_IF = "eth0"; ELAN_IF = "eth0"; #else BRIDGE_IF = "br0"; ELAN_IF = "eth0"; #endif strcpy(WLAN_IF,"wlan0"); //--------------------------- query_temp_var = (char *)malloc(MAX_QUERY_TEMP_VAL_SIZE); if (query_temp_var==NULL) exit(0); return; //main_end: //shmdt(pRomeCfgParam);
// This translation engine can not process <%...%> interlace with <#...#> void do_ej(char *path, FILE *stream) { #define PATTERN_LENGTH 1024 #define FRAG_SIZE 128 #define RESERVE_SIZE 4 int frag_size = FRAG_SIZE; int pattern_size = PATTERN_LENGTH - RESERVE_SIZE; char pat_buf[PATTERN_LENGTH]; char *pattern = pat_buf, *asp = NULL, *asp_end = NULL, *key = NULL, *key_end = NULL; char *start_pat, *end_pat, *lang; FILE *fp; int conn_break = 0; size_t ret, read_len, len; int no_translate = 1; unsigned char lang_mib[16]; //2011.04.12 Jerry if (!(fp = fopen(path, "r"))) return; #ifdef TRANSLATE_ON_FLY // Load dictionary file // If the router is restored to default, using browser's language setting to display ALL pages if (is_firsttime () && Accept_Language[0] != '\0') { lang = Accept_Language; } else { apmib_get( MIB_PREFERRED_LANG, (void *)&lang_mib); lang = lang_mib; } if (load_dictionary (lang, &kw)) { no_translate = 0; } #endif //defined TRANSLATE_ON_FLY start_pat = end_pat = pattern; memset (pattern + pattern_size, 0, 4); while (conn_break == 0) { int special; // Arrange pattern[] if available buffer length (end_pat~pattern[pattern_size]) is smaller than frag_size if (((pattern + pattern_size) - end_pat) < frag_size) { len = end_pat - start_pat; memcpy (pattern, start_pat, len); start_pat = pattern; end_pat = start_pat + len; *end_pat = '\0'; } read_len = (pattern + pattern_size) - end_pat; len = fread (end_pat, 1, read_len, fp); if (len == 0) { if (start_pat < end_pat) { fwrite (start_pat, 1, (size_t) (end_pat - start_pat), stream); } break; } end_pat += len; *end_pat = '\0'; asp = strstr (start_pat, asp_mark1); key = NULL; if (no_translate == 0) { key = strstr (start_pat, kw_mark1); } special = 0; while ((start_pat < end_pat) && special == 0) { int postproc = 0; /* 0: need more data; 1: translate; 2: execute asp; 3: write only; */ char *s, *e, *p; /* asp asp_end * ^ ^ * +------------------------------<%.......%>-------------------------------+ * | XXXXXXXXXXXXXXXXXXXXX<#.......#>YYYYYYYYYYYYYYYYYY0 |0000 * +------------------------------------------------------------------------+ * ^ ^ ^ ^ ^ ^ ^ * | | | | p | | * pattern start_pat,s key,e(2) key_end end_pat,e(1) pattern + pattern_size * ^ | * +--------------------------------+ * */ // If <%...%> and <#...#> do not exist in pattern[], write whole pattern[]. s = start_pat; e = end_pat; if (key != NULL && asp == NULL) { e = key; // Write start_pat ~ (key - 1) key_end = strstr (key, kw_mark2); if (key_end != NULL) { // We do have <#...#> in pattern[]. postproc = 1; } } else if (key != NULL && asp != NULL) { // We have <%...%> and <#...#> in pattern[], process first occurrence if (asp < key) { e = asp; // Write start_pat ~ (asp - 1) asp_end = strstr (asp, asp_mark2); if (asp_end != NULL) { // We do have whole <%...%>. postproc = 2; } } else { e = key; // Write start_pat ~ (key - 1) key_end = strstr (key, kw_mark2); if (key_end != NULL) { // We do have whole <#...#>. postproc = 1; } } } else if (key == NULL && asp != NULL) { e = asp; // Write start_pat ~ (asp - 1) asp_end = strstr (asp, asp_mark2); if (asp_end != NULL) { // We do have whole <%...%>. postproc = 2; } } else { // Special case. If last character is '<' // DO NOT write this character due to next one may be % or #. if (*(e-1) == *asp_mark1 || *(e-1) == *kw_mark1) { special = 1; e--; } postproc = 3; } // process text preceeding <# or <% if (e > s) { ret = fwrite (s, 1, (size_t) (e - s), stream); if (ret == 0 || ret < (e - s)) { /* the connection had been damaged. DO NOT process another data. */ /* (reduce response time of httpd) */ // cprintf ("fwrite() ret %d, s %p e %p len %d, break do_ej()'s while loop\n", ret, s, e, e-s); conn_break = 1; break; } else { start_pat = e; } } // post process p = NULL; if (postproc == 1) { // translate p = translate_lang (key + strlen (kw_mark1), key_end, stream, &kw); if (no_translate == 0 && p != NULL) { key = strstr (p, kw_mark1); } } else if (postproc == 2) { // execute asp p = process_asp (asp + strlen (asp_mark1), asp_end, stream); if (p != NULL) { asp = strstr (p, asp_mark1); } } else if (postproc == 3) { // no <%...%> or <#...#> p = e; } else if (postproc == 0) { // read more data break; } if (p != NULL) { start_pat = p; } } /* while ((start_pat < end_pat) && special == 0) */ } /* while (conn_break == 0) */ fflush (stream); fclose(fp); system("/bin/clear_cache.sh"); }
int Domain_query_Process() { int i; int Operation_Mode=0; int WLAN_Mode=0; unsigned char LAN_Mac[12]; char cmdBuffer[100]; int lan_dhcp=0; char lan_domain_name[ MAX_NAME_LEN]={0}; unsigned char Confirm_Threshold=0; int Type=0; int Check_status=0; apmib_get( MIB_DOMAIN_NAME, (void *)lan_domain_name); if(Start_Domain_Query_Process==0 ||isFileExist("/var/system/start_init") || !lan_domain_name[0]){//during init procedure //printf("web init return directly\n"); return 0; } apmib_get( MIB_OP_MODE, (void *)&Operation_Mode); apmib_get( MIB_WLAN_MODE, (void *)&WLAN_Mode); apmib_get( MIB_DHCP, (void *)&lan_dhcp); if(Operation_Mode==1 && ((WLAN_Mode == 1 && lan_dhcp==15)|| (WLAN_Mode == 0 && lan_dhcp==15))){ //in bridge mode and wlan ap/client mode if(CurrentTime < WAIT_TIME){ //it time to check wlan connected or not /*if wlan is connected will not start dhcp server*/ Check_status = Check_Wlan_isConnected(WLAN_Mode); if( Check_status==1 && DHCPD_State==1){ //wlan connetced //printf("wlan connected within WAIT_TIME and start dhcpc\n"); system("killall -9 udhcpd 2> /dev/null"); system("killall -9 udhcpc 2> /dev/null"); system("echo 1 > /proc/pocket/en_filter"); //start to filter dhcp discover in bridge if(getLan_MacAddress(LAN_Mac)){ sprintf(cmdBuffer, "echo \"00000000 %s 0\" > /proc/pocket/filter_conf", LAN_Mac); system(cmdBuffer); }else{ system("echo \"00000000 000000000000 0\" > /proc/pocket/filter_conf"); } system("rm -f /var/run/udhcpd.pid 2> /dev/null"); system("rm -f /etc/udhcpc/udhcpc-br0.pid 2> /dev/null"); #if defined(LOGDEBUG_ENABLED) if(WLAN_Mode == 1){ syslog(LOG_INFO, "klogd: DNQP: Connected within WAIT_TIME, Start DHCP Client\n"); printf("DNQP: Connected within WAIT_TIME, Start DHCP Client\n"); } #endif set_lan_dhcpc("br0"); DHCPC_State=2; // start DHCP client DHCPD_State=0; WLAN_State=1; if(WLAN_Mode == 0){ #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: AP mode, within WAIT_TIME, Start DHCP Client, shutdown wlan first\n"); printf("DNQP: AP mode, within WAIT_TIME, Start DHCP Client, shutdown wlan first\n"); #endif system("ifconfig wlan0 down"); #if defined (CONFIG_RTL_92D_SUPPORT) system("ifconfig wlan1 down"); #endif Kill_Wlan_Applications(); } wlan_iface_state=1; }else if(Check_status ==0 && DHCPD_State==1){ if(isFileExist(DHCPD_PID_FILE)==0){ system("killall -9 udhcpd 2> /dev/null"); system("rm -f /var/run/udhcpd.pid 2> /dev/null"); system("echo 1 > /proc/pocket/en_filter"); //start to filter dhcp discover in bridge if(getLan_MacAddress(LAN_Mac)){ sprintf(cmdBuffer, "echo \"00000000 %s 2\" > /proc/pocket/filter_conf", LAN_Mac); system(cmdBuffer); }else{ system("echo \"00000000 000000000000 2\" > /proc/pocket/filter_conf"); } #if defined(LOGDEBUG_ENABLED) if(WLAN_Mode == 1){ syslog(LOG_INFO, "klogd: DNQP: Disconnected within WAIT_TIME, Start DHCP Server\n"); printf("DNQP: Disconnected within WAIT_TIME, Start DHCP Server\n"); } #endif set_lan_dhcpd("br0", 2); for(i=0;i<3;i++){ if(isFileExist(DHCPD_PID_FILE)){ break; }else{ sleep(1); } } if(WLAN_Mode == 1){ system("ifconfig eth0 down"); //system("ifconfig eth1 down"); sleep(5); system("ifconfig eth0 up"); //system("ifconfig eth1 up"); } else if(WLAN_Mode == 0) { #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: AP mode, within WAIT_TIME, Start DHCP Server, shutdown wlan first\n"); printf("DNQP: AP mode, within WAIT_TIME, Start DHCP Server, shutdown wlan first\n"); #endif system("ifconfig wlan0 down"); #if defined (CONFIG_RTL_92D_SUPPORT) system("ifconfig wlan1 down"); #endif Kill_Wlan_Applications(); } start_dnrd(); wlan_iface_state=1; system("iptables -F INPUT"); WLAN_State=0; } } }else if(CurrentTime >= WAIT_TIME){ //it's time to check wlan connect or not Check_status = Check_Wlan_isConnected(WLAN_Mode); if(Check_status ==0){ //wlan/eth1 is not connetced //disconnect state if(isFileExist(DHCPD_PID_FILE)==0){ //dhcp server is not running if(WLAN_Mode==0) Confirm_Threshold=0; if(WLAN_Mode==1) Confirm_Threshold=20; if(WLAN_State==1 && Confirm_Time < Confirm_Threshold){ Confirm_Time++; goto ToNext; } Confirm_Time=0; if(isFileExist("/etc/udhcpc/udhcpc-br0.pid")){ system("killall -9 udhcpc 2> /dev/null"); system("rm -f /etc/udhcpc/udhcpc-br0.pid 2> /dev/null"); } sleep(1); system("killall -9 udhcpd 2> /dev/null"); system("rm -f /var/run/udhcpd.pid 2> /dev/null"); #if defined(LOGDEBUG_ENABLED) if(WLAN_Mode == 1){ syslog(LOG_INFO, "klogd: DNQP: Disconnected after WAIT_TIME, Start DHCP Server\n"); printf("DNQP: Disconnected after WAIT_TIME, Start DHCP Server\n"); } #endif set_lan_dhcpd("br0", 2); for(i=0;i<3;i++){ if(isFileExist(DHCPD_PID_FILE)){ break; }else{ sleep(1); } } system("echo 1 > /proc/pocket/en_filter"); //start to filter dhcp discover in bridge if(getLan_MacAddress(LAN_Mac)){ sprintf(cmdBuffer, "echo \"00000000 %s 2\" > /proc/pocket/filter_conf", LAN_Mac); system(cmdBuffer); }else{ system("echo \"00000000 000000000000 2\" > /proc/pocket/filter_conf"); } if(WLAN_Mode == 1){ system("ifconfig eth0 down"); //system("ifconfig eth1 down"); sleep(5); system("ifconfig eth0 up"); //system("ifconfig eth1 up"); } else if(WLAN_Mode == 0) { #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: AP mode, after WAIT_TIME, Start DHCP Server, shutdown wlan first\n"); printf("DNQP: AP mode, after WAIT_TIME, Start DHCP Server, shutdown wlan first\n"); #endif system("ifconfig wlan0 down"); #if defined (CONFIG_RTL_92D_SUPPORT) system("ifconfig wlan1 down"); #endif Kill_Wlan_Applications(); } start_dnrd(); wlan_iface_state=1; system("iptables -F INPUT"); if(WLAN_Mode == 0){ WLAN_State=0; } }else{ //dhcp server is running, and not connected if(isFileExist("/etc/udhcpc/udhcpc-br0.pid")){ system("killall -9 udhcpc 2> /dev/null"); system("rm -f /etc/udhcpc/udhcpc-br0.pid 2> /dev/null"); if(getLan_MacAddress(LAN_Mac)){ sprintf(cmdBuffer, "echo \"00000000 %s 2\" > /proc/pocket/filter_conf", LAN_Mac); system(cmdBuffer); }else{ system("echo \"00000000 000000000000 2\" > /proc/pocket/filter_conf"); } }else{ Type = getFilter_Type(); if(Type==0){ #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: Disconnected after WAIT_TIME, Filter state is 0, reset to 2 in DHCP server state\n"); printf("DNQP: AP mode, Disconnected after WAIT_TIME, Filter state is 0, reset to 2 in DHCP server state\n"); #endif system("echo \"00000000 000000000000 2\" > /proc/pocket/filter_conf"); }else if(Type==2 && WLAN_State==1){ Renew_State++; } if(WLAN_Mode == 0 && Renew_State >= 1 && WLAN_State==1){ WLAN_State=0; Renew_State=0; #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: AP mode, Disconnected after WAIT_TIME, LastState is Connected, clean WLAN_State to cause start DHCP client when Connect again\n"); printf("DNQP: AP mode, Disconnected after WAIT_TIME, LastState is Connected, clean WLAN_State to cause start DHCP client when Connect again\n"); #endif } } } }else{ //connected state if(WLAN_State ==0){ system("killall -9 udhcpd 2> /dev/null"); system("killall -9 udhcpc 2> /dev/null"); system("rm -f /var/run/udhcpd.pid 2> /dev/null"); system("rm -f /etc/udhcpc/udhcpc-br0.pid 2> /dev/null"); system("echo 1 > /proc/pocket/en_filter"); //start to filter dhcp discover in bridge if(getLan_MacAddress(LAN_Mac)){ sprintf(cmdBuffer, "echo \"00000000 %s 0\" > /proc/pocket/filter_conf", LAN_Mac); system(cmdBuffer); }else{ system("echo \"00000000 000000000000 0\" > /proc/pocket/filter_conf"); } #if defined(LOGDEBUG_ENABLED) if(WLAN_Mode == 1){ syslog(LOG_INFO, "klogd: DNQP: Connected after WAIT_TIME, Start DHCP Client\n"); printf("DNQP: Connected after WAIT_TIME, Start DHCP Client\n"); } #endif set_lan_dhcpc("br0"); DHCPC_State=2; // start DHCP client system("iptables -A INPUT -p icmp --icmp-type echo-request -i br0 -j DROP"); // sleep(1); WLAN_State=1; Restore_IptablesRule=1; check_count=0; if(WLAN_Mode == 0){ #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: AP mode, after WAIT_TIME, Start DHCP Client, shutdown wlan first\n"); printf("DNQP: AP mode, after WAIT_TIME, Start DHCP Client, shutdown wlan first\n"); #endif system("ifconfig wlan0 down"); #if defined (CONFIG_RTL_92D_SUPPORT) system("ifconfig wlan1 down"); #endif Kill_Wlan_Applications(); } wlan_iface_state=1; }else{ if(Restore_IptablesRule==1){ if(isFileExist(DHCPD_PID_FILE)){ unlink(DHCPD_PID_FILE); } if(check_count > 5){ system("iptables -F INPUT"); Restore_IptablesRule=0; }else{ check_count++; } } if(getFilter_Type()==0){ if(Confirm_DHCP_Time >= DHCPC_WAIT_TIME && (DHCPC_State==1 || DHCPC_State==2)){ system("killall -9 udhcpd 2> /dev/null"); system("killall -9 udhcpc 2> /dev/null"); sleep(1); system("rm -f /var/run/udhcpd.pid 2> /dev/null"); system("rm -f /etc/udhcpc/udhcpc-br0.pid 2> /dev/null"); #if defined(LOGDEBUG_ENABLED) if(WLAN_Mode == 1){ syslog(LOG_INFO, "klogd: DNQP: Connected after WAIT_TIME, DHCP Client start, and CanNOT get ip after 20 seconds, Start DHCP Server\n"); printf("DNQP: Connected after WAIT_TIME, DHCP Client start, and CanNOT get ip after 20 seconds, Start DHCP Server\n"); } #endif set_lan_dhcpd("br0", 2); for(i=0;i<3;i++){ if(isFileExist(DHCPD_PID_FILE)){ break; }else{ sleep(1); } } system("echo 1 > /proc/pocket/en_filter"); //start to filter dhcp discover in bridge if(getLan_MacAddress(LAN_Mac)){ sprintf(cmdBuffer, "echo \"00000000 %s 2\" > /proc/pocket/filter_conf", LAN_Mac); system(cmdBuffer); }else{ system("echo \"00000000 000000000000 2\" > /proc/pocket/filter_conf"); } if(WLAN_Mode == 1){ system("ifconfig eth0 down"); //system("ifconfig eth1 down"); sleep(5); system("ifconfig eth0 up"); //system("ifconfig eth1 up"); } else if(WLAN_Mode == 0) { #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: AP mode, Connected after WAIT_TIME, DHCP Client start, and CanNOT get ip after 20 seconds, Start DHCP Server, shutdown wlan first\n"); printf("DNQP: AP mode, Connected after WAIT_TIME, DHCP Client start, and CanNOT get ip after 20 seconds, Start DHCP Server, shutdown wlan first\n"); #endif system("ifconfig wlan0 down"); #if defined (CONFIG_RTL_92D_SUPPORT) system("ifconfig wlan1 down"); #endif Kill_Wlan_Applications(); } start_dnrd(); wlan_iface_state=1; system("iptables -F INPUT"); if(WLAN_State==0) WLAN_State=1; DHCPC_State=0; }else Confirm_DHCP_Time++; }else{ Confirm_DHCP_Time=0; if (DHCPC_State == 2) { if(WLAN_Mode == 1){ system("ifconfig eth0 down"); //system("ifconfig eth1 down"); sleep(5); system("ifconfig eth0 up"); //system("ifconfig eth1 up"); } if(WLAN_Mode == 0){ system("ifconfig wlan0 down"); #if defined (CONFIG_RTL_92D_SUPPORT) system("ifconfig wlan1 down"); #endif Kill_Wlan_Applications(); } wlan_iface_state=1; system("iptables -F INPUT"); } DHCPC_State=1; } } if(WLAN_Mode ==1){ if(WLAN_State==1 && (Confirm_Time >= 3 && Confirm_Time < 20) &&getFilter_Type()==1){ //printf("client ever disconnect for 3~20 seconds, we should update our ip address\n"); #if defined(LOGDEBUG_ENABLED) syslog(LOG_INFO, "klogd: DNQP: Client mode, client ever disconnect for 3~20 seconds, we should update our ip address\n"); printf("DNQP: Client mode, client ever disconnect for 3~20 seconds, we should update our ip address\n"); #endif WLAN_State=0; Confirm_Time=0; } } } } ToNext: if(CurrentTime > WAIT_TIME+5) CurrentTime=WAIT_TIME; else CurrentTime++; if(wlan_iface_state==1){ Type = getFilter_Type(); if(Type==2 ||Type==1 ){ //dhcp server state, we wait 8 seconds, type=2:server state, type=1:dhcp client and got ip address confirm_wlan_iface_state++; if(confirm_wlan_iface_state >=8){ if(WLAN_Mode == 0){ #if defined(LOGDEBUG_ENABLED) if(Type==2){ syslog(LOG_INFO, "klogd: DNQP: AP mode, Up wlan interface when dhcp server started\n"); printf("DNQP: AP mode, Up wlan interface when dhcp server started\n"); }else if (Type==1){ syslog(LOG_INFO, "klogd: DNQP: AP mode, Up wlan interface when dhcp client got ip\n"); printf("DNQP: AP mode, Up wlan interface when dhcp client got ip\n"); } #endif system("ifconfig wlan0 up"); #if defined (CONFIG_RTL_92D_SUPPORT) if(isBandModeBoth()) { system("ifconfig wlan1 up"); } #endif sleep(1); Start_Wlan_Applications(); } wlan_iface_state=0; confirm_wlan_iface_state=0; } } } #if 0 if(WLAN_State==1 && check_ssid() && CurrentTime >= WAIT_TIME){ WLAN_State=0;//restart all procedure system("iptables -F INPUT");//to avoid add iptables rule duplicate } #endif }else{ system("echo 0 > /proc/pocket/en_filter"); } return 0; }