void stop_vpn_server(void) { int i; char pppd_pid[32]; char* svcs[] = { "bcrelay", "pptpd", NULL, NULL }; if (get_xl2tpd_vpns_active()) { svcs[2] = "xl2tpd"; xl2tpd_killed_vpns = 1; } kill_services(svcs, 5, 1); /* force kill all clients pppd */ for (i=0; i<MAX_CLIENTS_NUM; i++) { sprintf(pppd_pid, "/var/run/ppp%d.pid", VPN_SERVER_PPP_UNIT+i); kill_pidfile_s(pppd_pid, SIGKILL); } nvram_set_int_temp("l2tp_srv_t", 0); unlink(VPNS_PPP_UP_SCRIPT); unlink(VPNS_PPP_DW_SCRIPT); #if defined(APP_OPENVPN) stop_openvpn_server(); #endif unlink(VPN_SERVER_LEASE_FILE); }
void media_processcheck(void) { media_timer = (media_timer + 1) % 6; if (!media_timer) { #if 0 if (nvram_match("apps_dms_ex", "1") && nvram_match("dms_comp_mode", "1") && pids("ushare")) { if (nvram_match("ushare_debug", "1")) { system("date"); dbg("ushare reloading media content...\n"); } kill_pidfile_s("/var/run/ushare.pid", SIGHUP); } #endif if ( nvram_match("wan_route_x", "IP_Routed") && nvram_match("apps_itunes_ex", "1") && pids("mt-daapd") && !pids("mDNSResponder") ) { if (pids("mDNSResponder")) system("killall mDNSResponder"); if (!nvram_match("computer_name", "") && is_valid_hostname(nvram_safe_get("computer_name"))) doSystem("mDNSResponder %s thehost %s _daap._tcp. 3689 &", nvram_safe_get("lan_ipaddr_t"), nvram_safe_get("computer_name")); else doSystem("mDNSResponder %s thehost %s _daap._tcp. 3689 &", nvram_safe_get("lan_ipaddr_t"), nvram_safe_get("productid")); } } }
void notify_watchdog_wifi(int is_5ghz) { int wd_notify_id = (is_5ghz) ? WD_NOTIFY_ID_WIFI5 : WD_NOTIFY_ID_WIFI2; nvram_set_int_temp("wd_notify_id", wd_notify_id); kill_pidfile_s(WD_PID_FILE, SIGUSR1); }
void notify_watchdog_time(void) { if (pids("watchdog")) kill_pidfile_s(WD_PID_FILE, SIGHUP); else eval("/sbin/watchdog"); }
void refresh_ntpc(void) { if (nvram_match("wan_route_x", "IP_Routed") && (!has_wan_ip() || !found_default_route())) return; setenv("TZ", nvram_safe_get("time_zone_x"), 1); if (pids("ntpclient")) system("killall ntpclient"); if (!pids("ntp")) { stop_ntpc(); start_ntpc(); } else kill_pidfile_s("/var/run/ntp.pid", SIGTSTP); }
int wpacli_main(int argc, char **argv) { char tmp[100], prefix[WAN_PREFIX_SZ]; int unit; if (!argv[1] || (unit = wan_prefix(argv[1], prefix)) < 0) return EINVAL; if (!nvram_match(strcat_r(prefix, "auth_x", tmp), "eap-md5")) return 0; if (nvram_match(strcat_r(prefix, "proto", tmp), "dhcp") && strncmp(argv[2], "EAP-SUCCESS", sizeof("EAP-SUCCESS")) == 0) { /* Renew DHCP lease */ snprintf(tmp, sizeof(tmp), "/var/run/udhcpc%d.pid", unit); kill_pidfile_s(tmp, SIGUSR1); } logmessage("auth client", "%s", argv[2]); return 0; }
char *processPacket(int sockfd, char *pdubuf) { IBOX_COMM_PKT_HDR *phdr; IBOX_COMM_PKT_HDR_EX *phdr_ex; IBOX_COMM_PKT_RES_EX *phdr_res; PKT_GET_INFO *ginfo; // PKT_GET_INFO_STA *stainfo; // PKT_GET_INFO_EX1 *cmd; // PKT_GET_INFO_EX1 *res; // PKT_GET_INFO_SITES *res_sites; // PKT_GET_INFO_PROFILE *cmd_profiles, *res_profiles; #ifdef WAVESERVER // eric++ int fail = 0; pid_t pid; DIR *dir; int fd, ret, bytes; unsigned char tmp_buf[15]; // /proc/XXXXXX WS_INFO_T *wsinfo; #endif //#ifdef WL700G STORAGE_INFO_T *st; //#endif // int i; char ftype[8], prinfo[128]; /* get disk type */ int free_space; #ifdef RTCONFIG_WIRELESSREPEATER char tmp[100], prefix[] = "wlXXXXXXXXXXXXXX"; #endif phdr = (IBOX_COMM_PKT_HDR *)pdubuf; phdr_res = (IBOX_COMM_PKT_RES_EX *)pdubuf_res; // fprintf(stderr,"Get: %x %x %x\n", phdr->ServiceID, phdr->PacketType, phdr->OpCode); if (phdr->ServiceID==NET_SERVICE_ID_IBOX_INFO && phdr->PacketType==NET_PACKET_TYPE_CMD) { if (phdr->OpCode!=NET_CMD_ID_GETINFO && phdr->OpCode!=NET_CMD_ID_GETINFO_MANU&& phdr_res->OpCode==phdr->OpCode && phdr_res->Info==phdr->Info) { // if transaction id is equal to the transaction id of the last response message, just re-send message again; return pdubuf_res; } phdr_res->ServiceID=NET_SERVICE_ID_IBOX_INFO; phdr_res->PacketType=NET_PACKET_TYPE_RES; phdr_res->OpCode=phdr->OpCode; if (phdr->OpCode!=NET_CMD_ID_GETINFO && phdr->OpCode!=NET_CMD_ID_GETINFO_MANU) { phdr_ex = (IBOX_COMM_PKT_HDR_EX *)pdubuf; // Check Mac Address if (memcpy(phdr_ex->MacAddress, mac, 6)==0) { _dprintf("Mac Error %2x%2x%2x%2x%2x%2x\n", (unsigned char)phdr_ex->MacAddress[0], (unsigned char)phdr_ex->MacAddress[1], (unsigned char)phdr_ex->MacAddress[2], (unsigned char)phdr_ex->MacAddress[3], (unsigned char)phdr_ex->MacAddress[4], (unsigned char)phdr_ex->MacAddress[5] ); return NULL; } // Check Password //if (strcmp(phdr_ex->Password, "admin")!=0) //{ // phdr_res->OpCode = phdr->OpCode | NET_RES_ERR_PASSWORD; // _dprintf("Password Error %s\n", phdr_ex->Password); // return NULL; //} phdr_res->Info = phdr_ex->Info; memcpy(phdr_res->MacAddress, phdr_ex->MacAddress, 6); } switch(phdr->OpCode) { case NET_CMD_ID_GETINFO_MANU: // case NET_CMD_ID_GETINFO: _dprintf("NET CMD GETINFO_MANU\n"); // tmp test ginfo=(PKT_GET_INFO *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES)); memset(ginfo, 0, sizeof(ginfo)); #if 0 #ifdef PRNINFO readPrnID(ginfo->PrinterInfo); #else memset(ginfo->PrinterInfo, 0, sizeof(ginfo->PrinterInfo)); #endif #else if (strlen(nvram_safe_get("u2ec_mfg")) && strlen(nvram_safe_get("u2ec_device"))) { if (strstr(nvram_safe_get("u2ec_device"), nvram_safe_get("u2ec_mfg"))) sprintf(ginfo->PrinterInfo, "%s", nvram_safe_get("u2ec_device")); else sprintf(ginfo->PrinterInfo, "%s %s", nvram_safe_get("u2ec_mfg"), nvram_safe_get("u2ec_device")); } #endif /* get disk type */ #ifdef RTCONFIG_WIRELESSREPEATER if (nvram_get_int("sw_mode") == SW_MODE_REPEATER) { snprintf(prefix, sizeof(prefix), "wl%d.1_", nvram_get_int("wlc_band")); strcpy(ssid_g, nvram_safe_get(strcat_r(prefix, "ssid", tmp))); } else #endif strcpy(ssid_g, nvram_safe_get("wl0_ssid")); strcpy(productid_g, get_productid()); strcpy(ginfo->SSID, ssid_g); strcpy(ginfo->NetMask, get_lan_netmask()); strcpy(ginfo->ProductID, productid_g); // disable for tmp strcpy(ginfo->FirmwareVersion, firmver_g); // disable for tmp memcpy(ginfo->MacAddress, mac, 6); #ifdef WCLIENT ginfo->OperationMode = OPERATION_MODE_WB; ginfo->Regulation = 0xff; #endif #ifdef WAVESERVER st = (STORAGE_INFO_T *) (pdubuf_res + sizeof (IBOX_COMM_PKT_RES) + sizeof (PKT_GET_INFO) + sizeof(WS_INFO_T)); #else st = (STORAGE_INFO_T *) (pdubuf_res + sizeof (IBOX_COMM_PKT_RES) + sizeof (PKT_GET_INFO)); #endif //printf("get storage status(1)\n"); // tmp test getStorageStatus(st); //#endif /* #ifdef WL700G */ /* Disable WSC functions for MFG test*/ nvram_set("asus_mfg", "1"); /* nvram_set("wsc_config_state", "1"); system("killall wsccmd"); system("killall wsc"); system("killall upnp"); system("killall ntp"); system("killall ntpclient"); system("killall lld2d"); */ sendInfo(sockfd, pdubuf_res); return pdubuf_res; case NET_CMD_ID_GETINFO: _dprintf("NET CMD GETINFO\n"); ginfo=(PKT_GET_INFO *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES)); memset(ginfo, 0, sizeof(ginfo)); #if 0 #ifdef PRNINFO readPrnID(ginfo->PrinterInfo); #else memset(ginfo->PrinterInfo, 0, sizeof(ginfo->PrinterInfo)); #endif #else if (strlen(nvram_safe_get("u2ec_mfg")) && strlen(nvram_safe_get("u2ec_device"))) { if (strstr(nvram_safe_get("u2ec_device"), nvram_safe_get("u2ec_mfg"))) sprintf(ginfo->PrinterInfo, "%s", nvram_safe_get("u2ec_device")); else sprintf(ginfo->PrinterInfo, "%s %s", nvram_safe_get("u2ec_mfg"), nvram_safe_get("u2ec_device")); } #endif #ifdef RTCONFIG_WIRELESSREPEATER if (nvram_get_int("sw_mode") == SW_MODE_REPEATER) { snprintf(prefix, sizeof(prefix), "wl%d.1_", nvram_get_int("wlc_band")); strcpy(ssid_g, nvram_safe_get(strcat_r(prefix, "ssid", tmp))); } else #endif strcpy(ssid_g, nvram_safe_get("wl0_ssid")); strcpy(productid_g, get_productid()); strcpy(ginfo->SSID, ssid_g); strcpy(ginfo->NetMask, get_lan_netmask()); strcpy(ginfo->ProductID, productid_g); // disable for tmp strcpy(ginfo->FirmwareVersion, firmver_g); // disable for tmp memcpy(ginfo->MacAddress, mac, 6); #ifdef WCLIENT ginfo->OperationMode = OPERATION_MODE_WB; ginfo->Regulation = 0xff; #endif #ifdef WAVESERVER // eric++ // search /tmp/waveserver and get information wsinfo = (WS_INFO_T*) (pdubuf_res + sizeof (IBOX_COMM_PKT_RES) + sizeof (PKT_GET_INFO)); fd = open (WS_INFO_FILENAME, O_RDONLY); if (fd != -1) { bytes = sizeof (WS_INFO_T); while (bytes > 0) { ret = read (fd, wsinfo, bytes); if (ret > 0) { bytes -= ret; } else if (ret < 0) { fail++; break; } else if (ret == 0) { fail++; break; } } /* while () */ } else { fail++; } if (fail == 0 && bytes == 0) { ret = read (fd, &pid, sizeof (pid_t)); if (ret == sizeof (pid_t)) { sprintf (tmp_buf, "/proc/%d", pid); dir = opendir (tmp_buf); if (dir == NULL) { // file exist, but the process had been killed fail++; } closedir (dir); } else { // file not found or error occurred fail++; } } if (fail != 0) { memset (wsinfo, 0, sizeof (WS_INFO_T)); } #endif /* #ifdef WAVESERVER */ #ifdef WAVESERVER st = (STORAGE_INFO_T *) (pdubuf_res + sizeof (IBOX_COMM_PKT_RES) + sizeof (PKT_GET_INFO) + sizeof(WS_INFO_T)); #else st = (STORAGE_INFO_T *) (pdubuf_res + sizeof (IBOX_COMM_PKT_RES) + sizeof (PKT_GET_INFO)); #endif getStorageStatus(st); sendInfo(sockfd, pdubuf_res); return pdubuf_res; case NET_CMD_ID_GETINFO_EX2: _dprintf("\n we got case GETINFO_EX2\n"); // tmp test ginfo=(PKT_GET_INFO *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES)); memset(ginfo, 0, sizeof(ginfo)); memset(ginfo->PrinterInfo, 0, sizeof(ginfo->PrinterInfo)); /* get disk type */ memset(ftype, 0, sizeof(ftype)); memset(prinfo, 0, sizeof(prinfo)); free_space = get_ftype(ftype); _dprintf("get ftpye is %s, free = %d\n", ftype, free_space); sprintf(prinfo, "%s:%d!$", ftype, free_space); memcpy(ginfo->PrinterInfo, prinfo, strlen(prinfo)); sendInfo(sockfd, pdubuf_res); return pdubuf_res; #ifdef WCLIENT case NET_CMD_ID_GETINFO_EX: cmd = (PKT_GET_INFO_EX1 *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); res = (PKT_GET_INFO_EX1 *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)); stainfo = (PKT_GET_INFO_STA *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)+sizeof(PKT_GET_INFO_EX1)); if (cmd->FieldID!=FIELD_GENERAL_CURRENT_STA) return NULL; res->FieldCount=1; res->FieldID=FIELD_GENERAL_CURRENT_STA; memcpy(stainfo, &stainfo_g, sizeof(stainfo_g)); stainfo->connectionStatus = sta_status(); _dprintf("GetSTA: %s\n", stainfo->ssid); sendInfo(sockfd, pdubuf_res); return pdubuf_res; case NET_CMD_ID_SETINFO: cmd=(PKT_GET_INFO_EX1 *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); stainfo = (PKT_GET_INFO_STA *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)+sizeof(PKT_GET_INFO_EX1)); _dprintf("SSID: %s\n", stainfo->ssid); sendInfo(sockfd, pdubuf_res); return pdubuf_res; case NET_CMD_ID_GETINFO_SITES: cmd=(PKT_GET_INFO_EX1 *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); res_sites = (PKT_GET_INFO_SITES *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)); sta_start_scanning(); //sta_count_reset(); sleep(2); wl_scan_results(); _dprintf("Get INFO %d\n", sites_g_count); res_sites->Count = sites_g_count; for (i=0;i<res_sites->Count&&i<MAX_SITE_NUMBER;i++) { memcpy(&res_sites->Sites[i%8], &sites_g[i], sizeof(SITES)); if (i%8==0&&i!=0) { res_sites->Index = i/8; sendInfo(sockfd, pdubuf_res); } } if (i%8!=0) { res_sites->Index = i/8; sendInfo(sockfd, pdubuf_res); _dprintf("Send:%d %d\n", res_sites->Index, res_sites->Count); } return pdubuf_res; case NET_CMD_ID_GETINFO_PROF: cmd_profiles = (PKT_GET_INFO_PROFILE *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); res_profiles = (PKT_GET_INFO_PROFILE *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)); res_profiles->StartIndex = cmd_profiles->StartIndex; res_profiles->Count = cmd_profiles->Count; for (i=0;i<cmd_profiles->Count;i++) { memcpy(&res_profiles->p.Profiles[i], &profiles_g[cmd_profiles->StartIndex+i], sizeof(PROFILES)); } sendInfo(sockfd, pdubuf_res); return pdubuf_res; case NET_CMD_ID_SETINFO_PROF: cmd_profiles =(PKT_GET_INFO_PROFILE *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); res_profiles = (PKT_GET_INFO_SITES *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)); if (cmd_profiles->Count==0) { if (cmd_profiles->StartIndex == 0xff) // Save to file { } else { scan_g_type = cmd_profiles->p.ProfileControl.ButtonType; scan_g_mode = cmd_profiles->p.ProfileControl.ButtonMode; stainfo_g.profileCount = cmd_profiles->p.ProfileControl.ProfileCount; sta_start_connecting_one(&profiles_g[cmd_profiles->StartIndex]); //printf("set: %d %d\n", cmd_profiles->StartIndex, stainfo_g.profileCount); profiles_g_count = stainfo_g.profileCount; wl_write_profile(); } } else { for (i=0;i<cmd_profiles->Count;i++) { memcpy(&profiles_g[cmd_profiles->StartIndex + i], &cmd_profiles->p.Profiles[i], sizeof(PROFILES)); } } sendInfo(sockfd, pdubuf_res); return pdubuf_res; #endif case NET_CMD_ID_MANU_CMD: { #define MAXSYSCMD 256 char cmdstr[MAXSYSCMD]; PKT_SYSCMD *syscmd; PKT_SYSCMD_RES *syscmd_res; FILE *fp; printf("1. NET_CMD_ID_MANU_CMD:\n"); _dprintf("2. NET_CMD_ID_MANU_CMD:\n"); fprintf(stderr, "3. NET_CMD_ID_MANU_CMD:\n"); syscmd = (PKT_SYSCMD *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); syscmd_res = (PKT_SYSCMD_RES *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)); if (syscmd->len>=MAXSYSCMD) syscmd->len=MAXSYSCMD; syscmd->cmd[syscmd->len]=0; syscmd->len=strlen(syscmd->cmd); fprintf(stderr,"system cmd: %d %s\n", syscmd->len, syscmd->cmd); #if 0 if (!strcmp(syscmd->cmd, "GetAliveUsbDeviceInfo")) { // response format: "USB device name","current status of the device","IP of cccupied user" if (nvram_match("u2ec_device", "")) sprintf(syscmd_res->res, "\"%s\",\"%s\"", "", ""); else if (nvram_invmatch("u2ec_busyip", "")) // sprintf(syscmd_res->res, "\"%s\",\"%s\",\"%s\"", nvram_safe_get("u2ec_device"), "Busy", nvram_safe_get("u2ec_busyip")); sprintf(syscmd_res->res, "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"", ssid_g, productid_g, nvram_safe_get("u2ec_device"), "Busy", nvram_safe_get("u2ec_busyip")); else // sprintf(syscmd_res->res, "\"%s\",\"%s\"", nvram_safe_get("u2ec_device"), "Idle"); sprintf(syscmd_res->res, "\"%s\",\"%s\",\"%s\",\"%s\"", ssid_g, productid_g, nvram_safe_get("u2ec_device"), "Idle"); syscmd_res->len = strlen(syscmd_res->res); _dprintf("%d %s\n", syscmd_res->len, syscmd_res->res); // kill_pidfile_s("/var/run/usdsvr_broadcast.pid", SIGUSR1); sendInfo(sockfd, pdubuf_res); } else if (!strncmp(syscmd->cmd, "ClientPostMsg ", 14)) { char userip[16]; char usermsg[256]; char *p; int flag_invalid = 0; /* format: ClientPostMsg"Occupied User IP","ClientMsg" */ memset(userip, 0x0, 16); memset(usermsg, 0x0, 256); strncpy(userip, syscmd->cmd + 15, 16); // skip "ClientPostMsg \"" if (p = strchr(userip, '"')) *p = '\0'; else // invalid format { flag_invalid = 1; strcpy(userip, "255.255.255.255"); } if (!flag_invalid) // skip "ClientPostMsg\"Occupied User IP\",\"" { strcpy(usermsg, syscmd->cmd + 15 + strlen(userip) + 3); if (strlen(usermsg) > 1) usermsg[strlen(usermsg) - 1] = '\0'; } else strcpy(usermsg, "invalid message format!"); if (!strcmp(userip, "255.255.255.255")) { nvram_set("u2ec_msg_broadcast", usermsg); kill_pidfile_s("/var/run/usdsvr_broadcast.pid", SIGUSR2); } else { nvram_set("u2ec_clntip_unicast", userip); nvram_set("u2ec_msg_unicast", usermsg); kill_pidfile_s("/var/run/usdsvr_unicast.pid", SIGTSTP); } // strcpy(syscmd_res->res, usermsg); // syscmd_res->len = strlen(syscmd_res->res); // _dprintf("client ip: %s\n", userip); // _dprintf("%d %s\n", syscmd_res->len, syscmd_res->res); // sendInfo(sockfd, pdubuf_res); } else #endif { sprintf(cmdstr, "%s > /tmp/syscmd.out", syscmd->cmd); system(cmdstr); fprintf(stderr,"rund: %s\n", cmdstr); fp = fopen("/tmp/syscmd.out", "r"); if (fp!=NULL) { syscmd_res->len = fread(syscmd_res->res, 1, sizeof(syscmd_res->res), fp); fclose(fp); } else syscmd_res->len=0; fprintf(stderr,"%d %s\n", syscmd_res->len, syscmd_res->res); /* repeat 3 times for MFG by Yen*/ sendInfo(sockfd, pdubuf_res); sendInfo(sockfd, pdubuf_res); sendInfo(sockfd, pdubuf_res); if(strstr(syscmd->cmd, "Commit")) { int x=0; while(x<7) { sendInfo(sockfd, pdubuf_res); x++; } } /* end of MFG */ fprintf(stderr,"\nSendInfo 3 times!\n"); } return pdubuf_res; } #ifdef BTN_SETUP // This option can not co-exist with WCLIENT case NET_CMD_ID_SETKEY_EX: { #define MAXSYSCMD 256 char cmdstr[MAXSYSCMD]; PKT_SET_INFO_GW_QUICK_KEY *pkey; PKT_SET_INFO_GW_QUICK_KEY *pkey_res; if (!is_setup_mode(BTNSETUP_START)) return NULL; pkey=(PKT_SET_INFO_GW_QUICK_KEY *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); pkey_res = (PKT_SET_INFO_GW_QUICK_KEY *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)); #ifdef ENCRYPTION if (pkey->KeyLen==0) return NULL; #else pkey_res->KeyLen=0; #endif sprintf(cmdstr, "%2x%2x%2x%2x%2x%2x\n", (unsigned char)phdr_ex->MacAddress[0], (unsigned char)phdr_ex->MacAddress[1], (unsigned char)phdr_ex->MacAddress[2], (unsigned char)phdr_ex->MacAddress[3], (unsigned char)phdr_ex->MacAddress[4], (unsigned char)phdr_ex->MacAddress[5] ); nvram_set("bs_mac", cmdstr); sprintf(cmdstr, "Set MAC %s", cmdstr); syslog(LOG_NOTICE, cmdstr); sendInfo(sockfd, pdubuf_res); return pdubuf_res; } case NET_CMD_ID_QUICKGW_EX: { #define MAXSYSCMD 64 char cmdstr[MAXSYSCMD]; PKT_SET_INFO_GW_QUICK *gwquick; PKT_SET_INFO_GW_QUICK *gwquick_res; if (!is_setup_mode(BTNSETUP_DATAEXCHANGE)) return NULL; gwquick=(PKT_SET_INFO_GW_QUICK *)(pdubuf+sizeof(IBOX_COMM_PKT_HDR_EX)); gwquick_res = (PKT_SET_INFO_GW_QUICK *)(pdubuf_res+sizeof(IBOX_COMM_PKT_RES_EX)); #ifdef ENCRYPTION if (gwquick->QuickFlag&QFCAP_ENCRYPTION) { // DECRYPTION first } else return NULL #endif bs_put_setting(gwquick); if (!(gwquick->QuickFlag&QFCAP_WIRELESS)) // get setting bs_get_setting(gwquick_res); else memcpy(gwquick_res, gwquick, sizeof(PKT_SET_INFO_GW_QUICK)); #ifdef ENCRYPTION // ENCRYPTION first gwquick_res->QuickFlag = (QFCAP_ENCRYPTION|QFCAP_WIRELESS); #else gwquick_res->QuickFlag = (QFCAP_WIRELESS); #endif sendInfo(sockfd, pdubuf_res); return pdubuf_res; } #endif default: return NULL; } } return NULL; }
static int start_wpa_supplicant(int unit, int restart) { FILE *fp; char tmp[100]; char prefix[] = "wanXXXXXXXXXX_"; char options[sizeof("/etc/wpa_supplicantXXXXXXXXXX.conf")]; char pidfile[sizeof("/var/run/wpa_supplicantXXXXXXXXXX.pid")]; char *wpa_argv[] = {"/usr/sbin/wpa_supplicant", "-B", "-W", "-i", NULL, /* interface */ "-D", "wired", "-c", options, "-P", pidfile, NULL }; char *cli_argv[] = {"/usr/sbin/wpa_cli", "-B", "-i", NULL, /* interface */ "-a", "/tmp/wpa_cli", NULL}; int ret; snprintf(prefix, sizeof(prefix), "wan%d_", unit); snprintf(options, sizeof(options), "/etc/wpa_supplicant%d.conf", unit); snprintf(pidfile, sizeof(pidfile), "/var/run/wpa_supplicant%d.pid", unit); if (restart && pids("wpa_supplicant")) return kill_pidfile_s(pidfile, SIGUSR2); /* Get interface */ wpa_argv[4] = nvram_safe_get(strcat_r(prefix, "ifname", tmp)); cli_argv[3] = wpa_argv[4]; /* Get driver, wired default */ #ifndef RTCONFIG_RALINK /* Both BCM 5.x and 6.x */ if (get_switch() == SWITCH_BCM5325) wpa_argv[6] = "roboswitch"; #endif /* Generate options file */ if ((fp = fopen(options, "w")) == NULL) { perror(options); return -1; } fprintf(fp, "ctrl_interface=/var/run/wpa_supplicant\n" "ap_scan=0\n" "fast_reauth=1\n" "network={\n" " key_mgmt=IEEE8021X\n" " eap=MD5\n" " identity=\"%s\"\n" " password=\"%s\"\n" " eapol_flags=0\n" "}\n", nvram_safe_get(strcat_r(prefix, "pppoe_username", tmp)), nvram_safe_get(strcat_r(prefix, "pppoe_passwd", tmp))); fclose(fp); /* Start supplicant & monitor */ ret = _eval(wpa_argv, NULL, 0, NULL); if (ret == 0) _eval(cli_argv, NULL, 0, NULL); return 0; }
/* wathchdog is runned in NORMAL_PERIOD, 1 seconds * check in each NORMAL_PERIOD * 1. button * * check in each NORAML_PERIOD*10 * * 1. ntptime * 2. time-dependent service * 3. http-process * 4. usb hotplug status */ void watchdog(void) { /* handle button */ btn_check(); /* if timer is set to less than 1 sec, then bypass the following */ if (itv.it_value.tv_sec == 0) return; if (nvram_match("asus_mfg", "1")) { system("rmmod hw_nat"); if (pids("ntp")) system("killall -SIGTERM ntp"); if (pids("ntpclient")) system("killall ntpclient"); if (pids("udhcpc")) system("killall -SIGTERM udhcpc"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) if (pids("ots")) system("killall ots"); #endif stop_wanduck(); stop_logger(); stop_upnp(); // it may cause upnp cannot run stop_dhcpd(); stop_dns(); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) stop_pspfix(); #endif stop_wsc(); stop_wsc_2g(); stop_lltd(); stop_networkmap(); stop_httpd(); stop_lpd(); stop_u2ec(); kill_pidfile_s("/var/run/linkstatus_monitor.pid", SIGTERM); if (pids("detectWan")) system("killall detectWan"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) stop_rstats(); kill_pidfile_s("/var/run/detect_internet.pid", SIGTERM); #endif if (pids("tcpcheck")) system("killall -SIGTERM tcpcheck"); #ifdef HTTPD_CHECK if (pids("httpdcheck")) system("killall -SIGTERM httpdcheck"); #endif if (pids("traceroute")) system("killall traceroute"); if (pids("usbled")) system("killall -SIGTERM usbled"); nvram_set("asus_mfg", "2"); } #if 0 // reboot signal checking if (nvram_match("reboot", "1")) { printf("[watchdog] nvram match reboot\n"); reboot_count++; if (reboot_count >= 2) { // kill(1, SIGTERM); sys_exit(); } return; } #else if (nvram_match("reboot", "1")) return; #endif if (stop_service_type_99) return; if (!nvram_match("asus_mfg", "0")) return; watchdog_period = (watchdog_period + 1) % 10; if (watchdog_period) return; #ifdef BTN_SETUP if (btn_pressed_setup >= BTNSETUP_START) return; #endif #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) if (count_to_stop_wps > 0) { count_to_stop_wps--; if (!count_to_stop_wps) { // if (nvram_match("wl_radio_x", "1")) stop_wsc(); // psp fix // if (nvram_match("rt_radio_x", "1")) stop_wsc_2g(); // psp fix nvram_set("wps_enable", "0"); // psp fix } } #endif ddns_timer = (ddns_timer + 1) % 4320; if (nvram_match("asus_debug", "1")) mem_timer = (mem_timer + 1) % 60; if (!watchdog_count) watchdog_count++; else if (watchdog_count++ == 1) { #if 0 if (!strcmp(nvram_safe_get("rc_service"), "restart_upnp")) service_handle(); else #endif if ( nvram_match("router_disable", "0") && nvram_match("upnp_enable", "1") && nvram_match("upnp_started", "0") ) { // if (has_wan_ip()) { dbg("[watchdog] starting upnp...\n"); stop_upnp(); start_upnp(); } } } /* check for time-dependent services */ svc_timecheck(); /* http server check */ httpd_processcheck(); u2ec_processcheck(); media_processcheck(); #if 0 samba_processcheck(); #endif pppd_processcheck(); if (nvram_match("wan_route_x", "IP_Routed")) nm_processcheck(); cpu_usage_minotor(); dm_block_chk(); if (nvram_match("asus_debug", "1") && !mem_timer) { print_num_of_connections(); dbg("Hardware NAT: %s\n", is_hwnat_loaded() ? "Enabled": "Disabled"); dbg("Software QoS: %s\n", nvram_match("qos_enable", "1") ? "Enabled": "Disabled"); dbg("pppd running: %s\n", pids("pppd") ? "Yes": "No"); #if 0 dbg("CPU usage: %d%%\n", get_cpu_usage()); #else dbg("CPU usage: %d%%\n", cpu_main(0, NULL, 0)); #endif system("free"); system("date"); print_uptime(); } #ifdef CDMA /* CDMA_DOWN = 99, none * CDMA_DOWN = 1, currently down * CDMA_DOWN = 2, currently up * CDMA_DOWN = 0, currently trying to connect */ if (nvram_match("cdma_down", "1")) { logmessage("CDMA client", "cdma is down(%d)!", cdma_down); cdma_down++; cdma_connec t = 0; if (cdma_down == 2) { printf("[watchdog] stop wan\n"); stop_wan(); start_wan(); } else if (cdma_down >= 12) /* 2 minutes timeout for retry */ { cdma_down = 0; } } else if (nvram_match("cdma_down", "0")) { logmessage("CDMA client", "cdma try connect(%d)!", cdma_connect); cdma_down = 0; cdma_connect++; if (cdma_connect > 12) /* 2 minitues timeout for connecting */ { nvram_set("cdma_down", "1"); } } else { cdma_down = 0; cdma_connect = 0; } #endif if (nvram_match("wan_route_x", "IP_Routed")) { if (!is_phyconnected() || !has_wan_ip()) return; /* sync time to ntp server if necessary */ if (!nvram_match("wan_dns_t", "") && !nvram_match("wan_gateway_t", "")) { ntp_timesync(); } if ( nvram_match("ddns_enable_x", "1") && (!nvram_match("ddns_updated", "1") || !ddns_timer) ) { logmessage("RT-N56U", "[start ddns] watchdog"); start_ddns(); } if (!ddns_timer) { stop_networkmap(); start_networkmap(); } } else { if (/*!nvram_match("lan_dns_t", "") && */!nvram_match("lan_gateway_t", "")) ntp_timesync(); } }
/* * Kills process whose PID is stored in plaintext in pidfile * @param pidfile PID file, signal * @return 0 on success and errno on failure */ int inline kill_pidfile(const char *pidfile) { return kill_pidfile_s(pidfile, SIGTERM); }
/* * Kills process whose PID is stored in plaintext in pidfile * @param pidfile PID file * @return 0 on success and errno on failure */ int kill_pidfile(char *pidfile) { return kill_pidfile_s(pidfile, SIGTERM); }