/* * Copyright 2004, ASUSTek Inc. * All Rights Reserved. * * THIS SOFTWARE IS OFFERED "AS IS", AND ASUS GRANTS NO WARRANTIES OF ANY * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. * * $Id: services_ex.c,v 1.14 2009/03/03 02:39:54 james26_jang Exp $ */ #ifdef ASUS_EXT #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "iboxcom.h" #include "lp.h" #include #include #include #ifdef WCN #include "ILibParsers.h" #include #endif // WCN #ifdef DLM #include #include #include #include // 2008.02 James. void start_apps(); void stop_apps(); void run_ftpsamba(); void stop_ftpsamba(); void stop_samba(); void stop_ftp(); void stop_dms(); void write_disc_status(); void get_first_partition(char *); #endif // DLM void wfc_parser(const char *); void char_to_ascii(char *, char *); #ifdef CDMA // for stop_cdrom { #include #include // for stop_cdrom } // for eject_scsi { #include #include // for eject_scsi } #endif // CDMA #define logs(s) syslog(LOG_NOTICE, s) #ifdef USB_SUPPORT #ifdef WSC/* Cherry Cho added in 2008/4/8. */ extern int wsc_restart; #endif // WSC #ifdef DLM /* CRC lookup table */ static unsigned long crcs[256]={ 0x00000000,0x77073096,0xEE0E612C,0x990951BA, 0x076DC419,0x706AF48F,0xE963A535,0x9E6495A3,0x0EDB8832,0x79DCB8A4,0xE0D5E91E, 0x97D2D988,0x09B64C2B,0x7EB17CBD,0xE7B82D07,0x90BF1D91,0x1DB71064,0x6AB020F2, 0xF3B97148,0x84BE41DE,0x1ADAD47D,0x6DDDE4EB,0xF4D4B551,0x83D385C7,0x136C9856, 0x646BA8C0,0xFD62F97A,0x8A65C9EC,0x14015C4F,0x63066CD9,0xFA0F3D63,0x8D080DF5, 0x3B6E20C8,0x4C69105E,0xD56041E4,0xA2677172,0x3C03E4D1,0x4B04D447,0xD20D85FD, 0xA50AB56B,0x35B5A8FA,0x42B2986C,0xDBBBC9D6,0xACBCF940,0x32D86CE3,0x45DF5C75, 0xDCD60DCF,0xABD13D59,0x26D930AC,0x51DE003A,0xC8D75180,0xBFD06116,0x21B4F4B5, 0x56B3C423,0xCFBA9599,0xB8BDA50F,0x2802B89E,0x5F058808,0xC60CD9B2,0xB10BE924, 0x2F6F7C87,0x58684C11,0xC1611DAB,0xB6662D3D,0x76DC4190,0x01DB7106,0x98D220BC, 0xEFD5102A,0x71B18589,0x06B6B51F,0x9FBFE4A5,0xE8B8D433,0x7807C9A2,0x0F00F934, 0x9609A88E,0xE10E9818,0x7F6A0DBB,0x086D3D2D,0x91646C97,0xE6635C01,0x6B6B51F4, 0x1C6C6162,0x856530D8,0xF262004E,0x6C0695ED,0x1B01A57B,0x8208F4C1,0xF50FC457, 0x65B0D9C6,0x12B7E950,0x8BBEB8EA,0xFCB9887C,0x62DD1DDF,0x15DA2D49,0x8CD37CF3, 0xFBD44C65,0x4DB26158,0x3AB551CE,0xA3BC0074,0xD4BB30E2,0x4ADFA541,0x3DD895D7, 0xA4D1C46D,0xD3D6F4FB,0x4369E96A,0x346ED9FC,0xAD678846,0xDA60B8D0,0x44042D73, 0x33031DE5,0xAA0A4C5F,0xDD0D7CC9,0x5005713C,0x270241AA,0xBE0B1010,0xC90C2086, 0x5768B525,0x206F85B3,0xB966D409,0xCE61E49F,0x5EDEF90E,0x29D9C998,0xB0D09822, 0xC7D7A8B4,0x59B33D17,0x2EB40D81,0xB7BD5C3B,0xC0BA6CAD,0xEDB88320,0x9ABFB3B6, 0x03B6E20C,0x74B1D29A,0xEAD54739,0x9DD277AF,0x04DB2615,0x73DC1683,0xE3630B12, 0x94643B84,0x0D6D6A3E,0x7A6A5AA8,0xE40ECF0B,0x9309FF9D,0x0A00AE27,0x7D079EB1, 0xF00F9344,0x8708A3D2,0x1E01F268,0x6906C2FE,0xF762575D,0x806567CB,0x196C3671, 0x6E6B06E7,0xFED41B76,0x89D32BE0,0x10DA7A5A,0x67DD4ACC,0xF9B9DF6F,0x8EBEEFF9, 0x17B7BE43,0x60B08ED5,0xD6D6A3E8,0xA1D1937E,0x38D8C2C4,0x4FDFF252,0xD1BB67F1, 0xA6BC5767,0x3FB506DD,0x48B2364B,0xD80D2BDA,0xAF0A1B4C,0x36034AF6,0x41047A60, 0xDF60EFC3,0xA867DF55,0x316E8EEF,0x4669BE79,0xCB61B38C,0xBC66831A,0x256FD2A0, 0x5268E236,0xCC0C7795,0xBB0B4703,0x220216B9,0x5505262F,0xC5BA3BBE,0xB2BD0B28, 0x2BB45A92,0x5CB36A04,0xC2D7FFA7,0xB5D0CF31,0x2CD99E8B,0x5BDEAE1D,0x9B64C2B0, 0xEC63F226,0x756AA39C,0x026D930A,0x9C0906A9,0xEB0E363F,0x72076785,0x05005713, 0x95BF4A82,0xE2B87A14,0x7BB12BAE,0x0CB61B38,0x92D28E9B,0xE5D5BE0D,0x7CDCEFB7, 0x0BDBDF21,0x86D3D2D4,0xF1D4E242,0x68DDB3F8,0x1FDA836E,0x81BE16CD,0xF6B9265B, 0x6FB077E1,0x18B74777,0x88085AE6,0xFF0F6A70,0x66063BCA,0x11010B5C,0x8F659EFF, 0xF862AE69,0x616BFFD3,0x166CCF45,0xA00AE278,0xD70DD2EE,0x4E048354,0x3903B3C2, 0xA7672661,0xD06016F7,0x4969474D,0x3E6E77DB,0xAED16A4A,0xD9D65ADC,0x40DF0B66, 0x37D83BF0,0xA9BCAE53,0xDEBB9EC5,0x47B2CF7F,0x30B5FFE9,0xBDBDF21C,0xCABAC28A, 0x53B39330,0x24B4A3A6,0xBAD03605,0xCDD70693,0x54DE5729,0x23D967BF,0xB3667A2E, 0xC4614AB8,0x5D681B02,0x2A6F2B94,0xB40BBE37,0xC30C8EA1,0x5A05DF1B,0x2D02EF8D}; #endif // DLM enum { WEB_NONE = 0, WEB_PWCWEB, WEB_OVWEB, WEB_AUDIO, USB_PRINTER, //2008.05 James. MASS_STORAGE //2008.03.13 Yau add #ifdef CDMA , USB_ACM // HSDPA #endif // CDMA } WEBTYPE; char *PWCLIST[] = {"471","69a","46d","55d","41e","4cc","d81", NULL}; char *OVLIST[] = {"5a9","813","b62", NULL}; #endif // USB_SUPPORT char buf_g[512]; char usb1[128]; char usb2[128]; void diag_PaN(void) { FILE *fp; // char *token; // char mfr[32]; // char model[64]; // int fd; // int i = 0; // struct parport_splink_device_info prn_info; /* dump pci device */ fp=fopen("/proc/pci", "r"); if (fp!=NULL) { while(fgets(buf_g, sizeof(buf_g), fp)) { if(strstr(buf_g, "PCI device")) fprintf(stderr, buf_g); } fclose(fp); } #ifdef RT2400_SUPPORT if (nvram_match("nobr", "1")) fprintf(stderr, "dumping 0x4301 for manu.\n"); #endif // RT2400_SUPPORT #ifdef USB_SUPPORT /*if (nvram_match("usb_device", "1")) { fprintf(stderr, "new USB device\r\n"); }//*/ #endif // USB_SUPPORT #ifdef PRINTER_SUPPORT #ifdef PARPORT_SUPPORT if( (fd=open("/dev/lp0", O_RDWR)) < 0 ) //Someone is opening the lp0 { fp=fopen("/proc/sys/dev/parport/parport0/devices/lp/deviceid","r"); if( fp != NULL) { while ( fgets(buf_g, sizeof(buf_g), fp) != NULL ) { if(buf_g[0] == '\n') { continue; } if(strncmp(buf_g , "Model: " , strlen("Model: ")) == 0) { token = buf_g + strlen("Model: "); sprintf(buf_g, "PARPORT: %s", token); fprintf(stderr, "%s\r\n", buf_g); //logmessage("PARPORT", buf_g); } } fclose(fp); } //else logmessage("NO", "No printer found"); } else { if( ioctl(fd, LPGETID, &prn_info) <0 ) { //logmessage("PaN", "No printer found"); //PRINT("ioctl error\n"); } else { memccpy(mfr , prn_info.mfr , 1 , 32); memccpy(model , prn_info.model , 1 , 32); sprintf(buf_g, "PARPORT: %s", model); fprintf(stderr, "%s\r\n", buf_g); //logmessage("PARPORT", buf_g); } close(fd); } #endif // PARPORT_SUPPORT #endif // PRINTER_SUPPORT fprintf(stderr, "echo for PaN ::: &&&PaN\r\n"); } int start_dhcpd(void) { FILE *fp; char *dhcpd_argv[] = {"udhcpd", "/tmp/udhcpd.conf", NULL, NULL}; char *slease = "/tmp/udhcpd-br0.sleases"; pid_t pid; if (nvram_match("router_disable", "1") || nvram_invmatch("lan_proto", "dhcp")) return 0; dprintf("%s %s %s %s\n", nvram_safe_get("lan_ifname"), nvram_safe_get("dhcp_start"), nvram_safe_get("dhcp_end"), nvram_safe_get("lan_lease")); if (!(fp = fopen("/tmp/udhcpd-br0.leases", "a"))) { perror("/tmp/udhcpd-br0.leases"); return errno; } fclose(fp); /* Write configuration file based on current information */ if (!(fp = fopen("/tmp/udhcpd.conf", "w"))) { perror("/tmp/udhcpd.conf"); return errno; } fprintf(fp, "pidfile /var/run/udhcpd-br0.pid\n"); fprintf(fp, "start %s\n", nvram_safe_get("dhcp_start")); fprintf(fp, "end %s\n", nvram_safe_get("dhcp_end")); fprintf(fp, "interface %s\n", nvram_safe_get("lan_ifname")); fprintf(fp, "remaining yes\n"); fprintf(fp, "lease_file /tmp/udhcpd-br0.leases\n"); fprintf(fp, "option subnet %s\n", nvram_safe_get("lan_netmask")); if (nvram_invmatch("dhcp_gateway_x","")) fprintf(fp, "option router %s\n", nvram_safe_get("dhcp_gateway_x")); else fprintf(fp, "option router %s\n", nvram_safe_get("lan_ipaddr")); if (nvram_invmatch("dhcp_dns1_x","")) fprintf(fp, "option dns %s\n", nvram_safe_get("dhcp_dns1_x")); fprintf(fp, "option dns %s\n", nvram_safe_get("lan_ipaddr")); fprintf(fp, "option lease %s\n", nvram_safe_get("dhcp_lease")); if (nvram_invmatch("dhcp_wins_x","")) fprintf(fp, "option wins %s\n", nvram_safe_get("dhcp_wins_x")); if (nvram_invmatch("lan_domain", "")) fprintf(fp, "option domain %s\n", nvram_safe_get("lan_domain")); fclose(fp); if (nvram_match("dhcp_static_x","1")) { write_static_leases(slease); dhcpd_argv[2] = slease; } else { dhcpd_argv[2] = NULL; } _eval(dhcpd_argv, NULL, 0, &pid); dprintf("done\n"); return 0; } int stop_dhcpd(void) { // char sigusr1[] = "-XX"; int ret; /* * Process udhcpd handles two signals - SIGTERM and SIGUSR1 * * - SIGUSR1 saves all leases in /tmp/udhcpd.leases * - SIGTERM causes the process to be killed * * The SIGUSR1+SIGTERM behavior is what we like so that all current client * leases will be honorred when the dhcpd restarts and all clients can extend * their leases and continue their current IP addresses. Otherwise clients * would get NAK'd when they try to extend/rebind their leases and they * would have to release current IP and to request a new one which causes * a no-IP gap in between. */ ret = eval("killall", "udhcpd"); dprintf("done\n"); return ret; } int start_dns(void) { FILE *fp; char *dproxy_argv[] = {"dproxy", "-d", "-c", "/tmp/dproxy.conf", NULL}; pid_t pid; char word[100]; int ret, active; if (nvram_match("router_disable", "1")) return 0; /* Create resolv.conf with empty nameserver list */ if (!(fp = fopen("/tmp/resolv.conf", "r"))) { if (!(fp = fopen("/tmp/resolv.conf", "w"))) { perror("/tmp/resolv.conf"); return errno; } else fclose(fp); } else fclose(fp); if (!(fp = fopen("/tmp/dproxy.conf", "w"))) { perror("/tmp/dproxy.conf"); return errno; } fprintf(fp, "name_server=140.113.1.1\n"); fprintf(fp, "ppp_detect=no\n"); fprintf(fp, "purge_time=1200\n"); fprintf(fp, "deny_file=/tmp/dproxy.deny\n"); fprintf(fp, "cache_file=/tmp/dproxy.cache\n"); fprintf(fp, "hosts_file=/tmp/hosts\n"); fprintf(fp, "dhcp_lease_file=\n"); fprintf(fp, "ppp_dev=/var/run/ppp0.pid\n"); fclose(fp); // if user want to set dns server by himself if (nvram_invmatch("wan_dnsenable_x", "1")) { /* Write resolv.conf with upstream nameservers */ if (!(fp = fopen("/tmp/resolv.conf", "w"))) { perror("/tmp/resolv.conf"); return errno; } if (nvram_invmatch("wan_dns1_x","")) fprintf(fp, "nameserver %s\n", nvram_safe_get("wan_dns1_x")); if (nvram_invmatch("wan_dns2_x","")) fprintf(fp, "nameserver %s\n", nvram_safe_get("wan_dns2_x")); fclose(fp); } active = timecheck_item(nvram_safe_get("url_date_x"), nvram_safe_get("url_time_x")); if (nvram_match("url_enable_x", "1") && active) { int i; if (!(fp = fopen("/tmp/dproxy.deny", "w"))) { perror("/tmp/dproxy.deny"); return errno; } for(i=0; i0) { char *ddns_argv[] = {"ez-ipupdate", "-S", service, "-i", wan_ifname, "-u", usrstr, "-h", host, "-e", "/sbin/ddns_updated", "-b", "/tmp/ddns.cache", wild ? "-w" : NULL, NULL}; pid_t pid; dprintf("ddns update %s %s\n", server, service); nvram_unset("ddns_cache"); nvram_unset("ddns_ipaddr"); nvram_unset("ddns_status"); eval("killall", "ez-ipupdate"); _eval(ddns_argv, NULL, 0, &pid); } return 0; } int stop_ddns(void) { int ret = eval("killall", "ez-ipupdate"); dprintf("done\n"); return ret; } int start_logger(void) { pid_t pid; char *syslogd_argv[] = {"syslogd", "-m", "0", "-t", nvram_safe_get("time_zone_x"), "-O", "/tmp/syslog.log", NULL, NULL, /* -R host */ NULL, /* -L */ NULL}; int argc = 7; #ifdef KERNEL_DBG char *klogd_argv[] = {"klogd", "-d", NULL}; #else char *klogd_argv[] = {"klogd", NULL}; #endif // if (nvram_match("router_disable", "1")) // return 0; if (nvram_invmatch("log_ipaddr", "")) { syslogd_argv[argc++] = "-R"; syslogd_argv[argc++] = nvram_safe_get("log_ipaddr"); syslogd_argv[argc++] = "-L"; } //unlink("/tmp/syslog.log"); _eval(syslogd_argv, NULL, 0, &pid); if (nvram_match("kernel_dbg", "1") || nvram_invmatch("fw_log_x", "none")) _eval(klogd_argv, NULL, 0, &pid); // remote log not easy to ok sleep(1); return 0; } int stop_logger(void) { int ret1 = eval("killall", "klogd"); int ret2 = eval("killall", "syslogd"); dprintf("done\n"); return (ret1|ret2); } int start_misc(void) { char *infosvr_argv[] = {"infosvr", "br0", NULL}; char *ots_argv[] = {"ots", NULL}; // 2008.01 James. For communicating to utility. char *watchdog_argv[] = {"watchdog", NULL}; char *utelnetd_argv[] = {"utelnetd", NULL}; pid_t pid; _eval(infosvr_argv, NULL, 0, &pid); _eval(ots_argv, NULL, 0, &pid); // 2008.01 James. For communicating to utility. _eval(watchdog_argv, NULL, 0, &pid); if(!strcmp(nvram_safe_get("telnet_down"), "0")) _eval(utelnetd_argv, NULL, 0, &pid); /* adjust some special parameters here */ /* tx power */ #if 0 #ifndef WL500GPV2 /* adjust some special parameters here */ /* tx power */ if (nvram_match("wl_radio_power_x", "0")) { eval("wl", "txpwr1", "-o", "-q", "14"); } else if (nvram_match("wl_radio_power_x", "1")) { eval("wl", "txpwr1", "-o", "-q", "15"); } else if (nvram_match("wl_radio_power_x", "2")) { eval("wl", "txpwr1", "-o", "-q", "20"); } else if (nvram_match("wl_radio_power_x", "3")) { eval("wl", "txpwr1", "-o", "-q", "22"); } else if (nvram_match("wl_radio_power_x", "4")) { eval("wl", "txpwr1", "-o", "-q", "23"); } else if (nvram_match("wl_radio_power_x", "5")) { eval("wl", "txpwr1", "-o", "-q", "25"); } else if (nvram_match("wl_radio_power_x", "6")) { eval("wl", "txpwr1", "-o", "-q", "30"); } else if (nvram_match("wl_radio_power_x", "7")) { eval("wl", "txpwr1", "-o", "-q", "35"); } else if (nvram_match("wl_radio_power_x", "8")) { eval("wl", "txpwr1", "-o", "-q", "40"); } else if (nvram_match("wl_radio_power_x", "9")) { eval("wl", "txpwr1", "-o", "-q", "45"); } else if (nvram_match("wl_radio_power_x", "10")) { eval("wl", "txpwr1", "-o", "-q", "50"); } #endif // WL500GPV2 #endif // 0 // for all product, fix antdiv eval("wl", "antdiv", "0"); eval("wl", "txant", "0"); #ifdef CDMA // HSDPA { if(nvram_match("hsdpa_enable", "1")) { char *AT_argv[] = {"AT", NULL}; //_eval(AT_argv, NULL, 0, &pid); } #endif // CDMA // HSDPA } if (nvram_match("wl_radio_x", "0")) wl_led_ctrl(0); return 0; } int stop_misc(void) { int ret1 = eval("killall", "infosvr"); eval("killall", "ots"); eval("killall", "utelnetd"); eval("killall", "watchdog"); //eval("rm", "-f", "/var/run/watchdog.pid"); // 2007.11 James. unlink("/var/run/watchdog.pid"); // 2008.08 James. eval("killall", "ntp"); dprintf("done\n"); return(ret1); } int stop_misc_no_watchdog(void) { int ret1 = eval("killall", "infosvr"); eval("killall", "ntp"); dprintf("done\n"); return(ret1); } #ifndef USB_SUPPORT int start_usb(void) { return 0; } int stop_usb(void) { return 0; } int hotplug_usb(void) { return 0; } #else // USB_SUPPORT int start_usb(void) { eval("insmod", "usbcore"); eval("insmod", "usb-ohci"); eval("insmod", "ehci-hcd"); eval("mount", "-t", "usbdevfs", "none", "/proc/bus/usb/"); #ifdef U2EC char *u2ec_argv[] = {"u2ec", NULL}; pid_t pid_u2ec; _eval(u2ec_argv, NULL, 0, &pid_u2ec); #else // U2EC semaphore_create(); nvram_set("MFP_busy", "0"); #endif // U2EC #ifdef PRINTER_SUPPORT #ifdef PARPORT_SUPPORT symlink("/dev/printers/0", "/dev/lp0"); symlink("/dev/lp0", "/tmp/lp0"); eval("insmod", "parport.o"); eval("insmod", "parport_splink.o"); eval("insmod", "lp.o"); #endif // PARPORT_SUPPORT eval("insmod", "printer.o"); mkdir("/var/state", 0777); mkdir("/var/state/parport", 0777); mkdir("/var/state/parport/svr_statue", 0777); { char *lpd_argv[]={"lpd", NULL}; pid_t pid; sleep(2); _eval(lpd_argv, ">/dev/null", 0, &pid); } #endif // PRINTER_SUPPORT #ifdef MASSSTORAGE_SUPPORT if (nvram_invmatch("usb_ftpenable_x", "0")) { eval("insmod", "scsi_mod.o"); eval("insmod", "sd_mod.o"); sleep(1); // 2008.06 James. For some flashes, must delay for detecting. eval("insmod", "usb-storage.o"); eval("insmod", "cdrom", "autoclose=0", "autoeject=1", "lockdoor=0", "check_media_type=1"); eval("insmod", "sr_mod"); umask(0000); // added by Jiahao for WL500gP mkdir("/tmp/harddisk", 0777); } #endif // MASSSTORAGE_SUPPORT #ifdef AUDIO_SUPPORT eval("insmod", "soundcore.o"); eval("insmod", "audio.o"); start_audio(); #endif // AUDIO_SUPPORT #ifdef WEBCAM_SUPPORT if (nvram_invmatch("usb_webenable_x", "0")) { eval("insmod", "videodev.o"); // link video symlink("/dev/v4l/video0", "/dev/video"); start_rcamd(); } #endif // WEBCAM_SUPPORT #ifdef CDMA eval("insmod", "acm.o"); // eval("insmod", "usbserial.o", "vendor=0x1165", "product=0x0001"); // eval("insmod", "usbserial.o", "vendor=0x1a8d", "product=0x1002"); //Huawei E220 // HSDPA // eval("insmod", "usbserial.o", "vendor=0x0b05", "product=0x0302"); //Bandluxe C100 // eval("insmod", "usbserial.o", "vendor=0x0bb4", "product=0x00ce"); //ASUS T500 // eval("insmod", "usbserial.o", "vendor=0x0421", "product=0x04f0"); //Nokia 95 // eval("insmod", "usbserial.o", "vendor=0x0fce", "product=0xd039"); //SE K800 #endif // CDMA return 0; // 2007.11 James. } int stop_usb(void) { #ifdef MASSSTORAGE_SUPPORT if (nvram_invmatch("usb_ftpenable_x", "0")) { #ifdef DLM eval("killall", "snarf"); eval("killall", "ctorrent"); eval("killall", "rtorrent"); eval("killall", "giftd"); eval("killall", "dmathined"); eval("killall", "dms"); eval("killall", "-SIGKILL", "nmbd"); eval("killall", "-SIGKILL", "smbd"); eval("killall", "-SIGKILL", "vsftpd"); #endif // DLM eval("rmmod", "sr_mod"); eval("rmmod", "cdrom"); eval("rmmod", "usb-storage"); eval("rmmod", "sd_mod"); eval("rmmod", "scsi_mod"); } #endif // MASSSTORAGE_SUPPORT #ifdef PRINTER_SUPPORT eval("killall", "lpd"); eval("rmmod", "printer"); #ifdef PARPORT_SUPPORT eval("rmmod", "lp.o"); eval("rmmod", "parport_splink.o"); eval("rmmod", "parport.o"); #endif // PARPORT_SUPPORT #endif // PRINTER_SUPPORT #ifdef AUDIO_SUPPORT eval("rmmod", "audio"); eval("rmmod", "soundcore"); stop_audio(); #endif // AUDIO_SUPPORT #ifdef WEBCAM_SUPPORT if (nvram_invmatch("usb_webenable_x", "0")) { stop_rcamd(); eval("killall", "rcamd"); eval("killall", "sendmail"); eval("rmmod", "pwc"); eval("rmmod", "ov511_decomp"); eval("rmmod", "ov518_decomp"); eval("rmmod", "ov51x"); eval("rmmod", "i2c-core"); eval("rmmod", "videodev"); } #endif // WEBCAM_SUPPORT #ifdef CDMA // HSDPA eval("rmmod", "acm"); #endif // CDMA // HSDPA eval("rmmod", "ehci-hcd"); eval("rmmod", "usb-ohci"); eval("rmmod", "usbcore"); return 0; // 2007.11 James. } void start_script(int *new_disc) // added by Jiahao for WL500gP { char nvram_str[32]; int i=0; #ifdef DLM char run_path[64]; char runbuf[256]; int run_count=0; #endif // DLM #ifdef WCN char run_path_wcn[64]; int disc_index=0; int j=0; int wcn_count=0; #endif // WCN for(i=0;i<2;i++) { if ( *(new_disc+i)==1 ) { #ifdef DLM memset(nvram_str, 0, sizeof(nvram_str)); sprintf(nvram_str, "usb_disc%d_path0", i); memset(run_path, 0, sizeof(run_path)); strcpy(run_path, nvram_safe_get(nvram_str)); #endif // DLM #ifdef WCN memset(run_path_wcn, 0, sizeof(run_path_wcn)); sprintf(nvram_str, "usb_disc%d_index", i); disc_index=atoi(nvram_safe_get(nvram_str)); for (j=0; j/dev/null", 0, NULL); return 0; } int remove_webcam_main(int webflag) { if (webflag == WEB_PWCWEB) { eval("rmmod", "pwc"); } else { eval("rmmod", "i2c-core"); eval("rmmod", "ov511_decomp"); eval("rmmod", "ov518_decomp"); eval("rmmod", "ov51x"); } nvram_set("usb_webdriver_x", ""); return 0; } int remove_usb_webcam(char *product, int webflag) { char pidfile[32]; sprintf(pidfile, "/var/run/httpd-%s.pid", nvram_safe_get("usb_webhttpport_x")); kill_pidfile(pidfile); kill_pidfile("/var/run/rcamd.pid"); if (webflag == WEB_PWCWEB) { eval("rmmod", "pwc"); } else { eval("rmmod", "i2c-core"); eval("rmmod", "ov511_decomp"); eval("rmmod", "ov518_decomp"); eval("rmmod", "ov51x"); } nvram_set("usb_webdriver_x", ""); return 0; } int start_rcamd(void) { char *rcamd_argv[] = {"rcamdmain", NULL}; pid_t pid; _eval(rcamd_argv, NULL, 0, &pid); return 0; } int stop_rcamd(void) { int ret = eval("killall", "rcamdmain"); return ret; // 2007.11 James. } #endif // WEBCAM_SUPPORT /* remove usb mass storage */ int remove_usb_mass(char *product) { nvram_set("usb_storage_device_remove", ""); // 2007.12 James. // 2007.12 James { #ifdef DLM char *message; unsigned int len = 0; int result = 0; printf("\n*** start to umount disk! ***\n"); // 2008.06 James. { umount_disc_parts_rc(1); umount_disc_parts_rc(2); nvram_set("usb_disc0_pid", ""); nvram_set("usb_disc0_safely_removed", "0"); nvram_set("usb_disc1_pid", ""); nvram_set("usb_disc1_safely_removed", "0"); // 2008.06 James. } sync(); // 2008.04 James. result = eval("rmmod", "cdrom"); printf("\n*** start to rmmod usb-storage! ***\n"); //result = system("rmmod usb-storage"); result = eval("/sbin/rmmod", "usb-storage"); // 2008.04 James. printf("\n*** start to insmod usb-storage! ***\n"); //result = system("insmod usb-storage"); result = eval("/sbin/insmod", "usb-storage"); // 2008.04 James. result = eval("/sbin/insmod", "cdrom"); printf("\n*** start to mount the plugged disk! ***\n"); if((strlen(nvram_safe_get("usb_disc0_port")) > 0 && strcmp(nvram_safe_get("usb_disc0_safely_removed"), "1")) || (strlen(nvram_safe_get("usb_disc1_port")) > 0 && strcmp(nvram_safe_get("usb_disc1_safely_removed"), "1")) ) hotplug_usb_mass(""); #endif // DLM // 2007.12 James } return 0; } int remove_storage_main(void) { remove_usb_mass(NULL); return 0; } #define MOUNT_VAL_FAIL 0 #define MOUNT_VAL_RONLY 1 #define MOUNT_VAL_RW 2 int mount_r(char *usb_part, char *usb_file_part) { char msg[64]; // 2007.12 James { if(!mount(usb_part, usb_file_part, "ext3", MS_SYNCHRONOUS, NULL)) { chmod(usb_file_part, 0777); sprintf(msg, "ext3 fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("ext3 fs mounted to %s\n", usb_file_part); eval("/sbin/test_of_var_files_in_mount_path", usb_file_part); return MOUNT_VAL_RW; } // 2007.12 James } if(!mount(usb_part, usb_file_part, "ext2", MS_SYNCHRONOUS, NULL)) { chmod(usb_file_part, 0777); sprintf(msg, "ext2 fs mounted to %s\n", usb_file_part); #ifdef DLM logmessage("USB storage", msg); #endif // DLM printf("ext2 fs mounted to %s\n", usb_file_part); eval("/sbin/test_of_var_files_in_mount_path", usb_file_part); // 2007.12. James. return MOUNT_VAL_RW; } /* marked by Jiahao for WL500gP #ifdef LANGUAGE_EN if(!mount(usb_part, usb_file_part, "vfat", MS_SYNCHRONOUS, NULL)) { sprintf(msg, "vfat fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("vfat fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RW; } #endif #ifdef LANGUAGE_TW if(!mount(usb_part, usb_file_part, "vfat", MS_SYNCHRONOUS, "codepage=950,iocharset=cp950")) { umask(0022); sprintf(msg, "vfat fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("vfat fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RW; } #endif #ifdef LANGUAGE_CN if(!mount(usb_part, usb_file_part, "vfat", MS_SYNCHRONOUS, "codepage=936,iocharset=cp936")) { umask(0022); sprintf(msg, "vfat fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("vfat fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RW; } #endif #ifdef LANGUAGE_KR if(!mount(usb_part, usb_file_part, "vfat", MS_SYNCHRONOUS, "codepage=949,iocharset=cp949")) { umask(0022); sprintf(msg, "vfat fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("vfat fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RW; } #endif #ifdef LANGUAGE_JP if(!mount(usb_part, usb_file_part, "vfat", MS_SYNCHRONOUS, "codepage=932,iocharset=cp932")) { umask(0022); sprintf(msg, "vfat fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("vfat fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RW; } #endif */ // added by Jiahao for WL500gP //if(!mount(usb_part, usb_file_part, "vfat", MS_SYNCHRONOUS, "utf8=1,umask=0000,mode=0777")) if(!mount(usb_part, usb_file_part, "vfat", MS_NOSUID&MS_NODEV&MS_SYNCHRONOUS, "utf8=1,umask=0000,mode=0777")) { sprintf(msg, "vfat fs mounted to %s\n", usb_file_part); #ifdef DLM logmessage("USB storage", msg); #endif // DLM printf("vfat fs mounted to %s\n", usb_file_part); eval("/sbin/test_of_var_files_in_mount_path", usb_file_part); // 2007.12. James. return MOUNT_VAL_RW; } if(!mount(usb_part, usb_file_part, "msdos", MS_SYNCHRONOUS, "utf8=1,umask=0000,mode=0777")) { sprintf(msg, "msdos fs mounted to %s\n", usb_file_part); #ifdef DLM logmessage("USB storage", msg); #endif // DLM printf("msdoc fs mounted to %s\n", usb_file_part); eval("/sbin/test_of_var_files_in_mount_path", usb_file_part); // 2007.12. James. return MOUNT_VAL_RW; } if(!mount(usb_part, usb_file_part, "ntfs", MS_SYNCHRONOUS, "utf8=1,umask=0000")) { sprintf(msg, "ntfs(ro) fs mounted to %s\n", usb_file_part); #ifdef DLM logmessage("USB storage", msg); #endif // DLM printf("ntfs fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RONLY; } /* marked by Jiahao for WL500gP #ifdef LANGUAGE_EN if(!mount(usb_part, usb_file_part, "ntfs", MS_SYNCHRONOUS, NULL)) { sprintf(msg, "ntfs(ro) fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("ntfs fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RONLY; } #endif #ifdef LANGUAGE_TW if(!mount(usb_part, usb_file_part, "ntfs", MS_SYNCHRONOUS, "iocharset=cp932")) { sprintf(msg, "ntfs(ro) fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("ntfs fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RONLY; } #endif #ifdef LANGUAGE_CN if(!mount(usb_part, usb_file_part, "ntfs", MS_SYNCHRONOUS, "iocharset=cp936")) { sprintf(msg, "ntfs(ro) fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("ntfs fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RONLY; } #endif #ifdef LANGUAGE_KR if(!mount(usb_part, usb_file_part, "ntfs", MS_SYNCHRONOUS, "iocharset=cp949")) { sprintf(msg, "ntfs(ro) fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("ntfs fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RONLY; } #endif #ifdef LANGUAGE_JP if(!mount(usb_part, usb_file_part, "ntfs", MS_SYNCHRONOUS, "iocharset=cp950")) { sprintf(msg, "ntfs(ro) fs mounted to %s\n", usb_file_part); logmessage("USB storage", msg); printf("ntfs fs mounted to %s\n", usb_file_part); return MOUNT_VAL_RONLY; } #endif */ return MOUNT_VAL_FAIL; } #ifdef DLM int calc_crc32( const char *fname, unsigned long *crc ) { FILE *in; /* input file */ unsigned char buf[BUFSIZ]; /* pointer to the input buffer */ size_t i, j; /* buffer positions*/ int k; /* generic integer */ unsigned long tmpcrc=0xFFFFFFFF; /* open file */ if((in = fopen(fname, "rb")) == NULL) return -1; /* loop through the file and calculate CRC */ while( (i=fread(buf, 1, BUFSIZ, in)) != 0 ){ for(j=0; j> 8) & 0x00FFFFFFL) ^ crcs[k]; } } fclose(in); *crc=~tmpcrc; /* postconditioning */ return 0; } // judge if the existed application files are correct. int ckeck_apps_completeness(const char *dirname) { FILE *fp=NULL; FILE *fp2=NULL; char line[256]; char line2[256]; char listfilename[64]="/apps/list"; char crcfilename[64]="/apps/crc"; char appsdir[64]; char tmp[256]; char crc_str[9]; unsigned long crc; memset(appsdir, 0, sizeof(appsdir)); sprintf(appsdir, "%s%s", dirname, "/.apps"); if ((fp=fopen(listfilename, "r"))==NULL) { printf("Cannot find %s.\n", listfilename); printf("Make sure it's available.\n"); return 0; } if ((fp2=fopen(crcfilename, "r"))==NULL) { printf("Cannot find %s.\n", crcfilename); printf("Make sure it's available.\n"); fclose(fp); return 0; } printf("starting to check apps files.\n"); while (!feof(fp)) { if (fgets(line,sizeof(line),fp)==NULL) break; /* end-of-file */ if (strlen(line)<3) continue; /* line empty */ memset(tmp, 0, sizeof(tmp)); sprintf(tmp, "%s%s", appsdir, line+1); /* file path */ tmp[strlen(tmp)-1]='\0'; printf("FILE: %s\n", tmp); if(calc_crc32(tmp, &crc) != 0) { printf("Error reading file %s.\n", tmp); sprintf(tmp, "rm -rf %s", appsdir); system(tmp); fclose(fp); fclose(fp2); return 0; } if (fgets(line2,sizeof(line2),fp2)==NULL) { sprintf(tmp, "rm -rf %s", appsdir); system(tmp); fclose(fp); fclose(fp2); return 0; } memset(crc_str, 0, sizeof(crc_str)); sprintf(crc_str, "%08lX", crc); printf("CRC32 now: %s\n", crc_str); line2[strlen(line2)-1]='\0'; printf("CRC32 org: %s\n", line2); if(strcmp(crc_str, line2)!=0) { sprintf(tmp, "rm -rf %s", appsdir); system(tmp); fclose(fp); fclose(fp2); return 0; } } fclose(fp); fclose(fp2); return 1; } // judge if there are application files. int ckeck_apps_completeness_pre(const char *dirname) { FILE *fp=NULL; FILE *fp2=NULL; char line[256]; char line2[256]; char listfilename[64]="/apps/list"; char crcfilename[64]="/apps/crc"; char appsdir[64]; char tmp[256]; unsigned long crc; memset(appsdir, 0, sizeof(appsdir)); sprintf(appsdir, "%s%s", dirname, "/.apps"); if ((fp=fopen(listfilename, "r"))==NULL) { printf("Cannot find %s.\n", listfilename); printf("Make sure it's available.\n"); return 0; } while (!feof(fp)) { if (fgets(line,sizeof(line),fp)==NULL) break; /* end-of-file */ if (strlen(line)<3) continue; /* line empty */ sprintf(tmp, "%s%s", appsdir, line+1); /* file path */ tmp[strlen(tmp)-1]='\0'; if((fp2 = fopen(tmp, "rb")) == NULL) { printf("Error reading file %s.\n", tmp); memset(tmp, 0, sizeof(tmp)); sprintf(tmp, "rm -rf %s", appsdir); system(tmp); fclose(fp); return 0; } fclose(fp2); } fclose(fp); return 1; } #endif // DLM #ifdef WCN char ibuf2[8192]; int channels_in_country(char *abbrev, int channels[]) { int i, j, unit; wl_channels_in_country_t *cic = (wl_channels_in_country_t *)ibuf2; char tmp[100], prefix[] = "wlXXXXXXXXXX_"; char *name; channel_info_t ci; if ((unit = atoi(nvram_safe_get("wl_unit"))) < 0) return -1; snprintf(prefix, sizeof(prefix), "wl%d_", unit); name = nvram_safe_get(strcat_r(prefix, "ifname", tmp)); i = 0; channels[i++] = 0; channels[i] = -1; if (strlen(abbrev)==0) return 0; cic->buflen = sizeof(ibuf2); strcpy(cic->country_abbrev, abbrev); cic->band = WLC_BAND_2G; cic->count = 0; if (wl_ioctl(name, WLC_GET_CHANNELS_IN_COUNTRY, cic, cic->buflen) == 0) { if (cic->count == 0) return 0; for(j = 0; j < cic->count; j++) { channels[i++] = cic->channel[j]; } channels[i] = -1; } return cic->count; } int channels_in_country_asus(char *abbrev, int channels[]) { int i, j; wl_channels_in_country_t *cic = (wl_channels_in_country_t *)ibuf2; char var[256], *next; int log_level, log_drop, log_accept; i=0; if (nvram_match("wl_chan_list", "")) { for(i=0;i<14;i++) { channels[i] = i+1; channels[i+1] = -1; } } else { foreach(var, nvram_safe_get("wl_chan_list"), next) { channels[i]=atoi(var); channels[i+1]=-1; i++; } } return i; } int get_wl_channels() { int i, channels[32]; if (!channels_in_country(nvram_safe_get("wl_country_code"), channels)) { channels_in_country_asus(nvram_safe_get("wl_country_code"), channels); } i = 0; while(channels[i]!=-1) i++; return i-1; } int parseXMLtext(char *dst, const char *src) { char tmpstr[6]; int len=0; int i=0; int dstlen=0; memset(dst, 0, sizeof(dst)); len=strlen(src); for( i=0; i=4 ) { memset(tmpstr, 0, sizeof(tmpstr)); memcpy(tmpstr, src+i, 4); if ( memcmp(tmpstr, ">", 4)==0 ) // '>' { memset(dst+dstlen, 62, 1); dstlen++; i+=3; continue; } else if ( memcmp(tmpstr, "<", 4)==0 ) // '<' { memset(dst+dstlen, 60, 1); dstlen++; i+=3; continue; } } if ( (len-i)>=5 ) { memset(tmpstr, 0, sizeof(tmpstr)); memcpy(tmpstr, src+i, 5); if ( memcmp(tmpstr, "&", 5)==0 ) // '&' { memset(dst+dstlen, 38, 1); dstlen++; i+=4; continue; } } memset(dst+dstlen, src[i], 1); dstlen++; } dst[dstlen]=0; return dstlen; } #define TYPE_configId 1 #define TYPE_configAuthorId 2 #define TYPE_configAuthor 3 #define TYPE_ssid 4 #define TYPE_connectionType 5 #define TYPE_authentication 6 #define TYPE_encryption 7 #define TYPE_networkKey 8 #define TYPE_keyProvidedAutomatically 9 #define TYPE_ieee802Dot1xEnabled 10 #define TYPE_eapMethod 11 #define TYPE_channel2Dot4 12 #define TYPE_channel5Dot0 13 #define TYPE_deviceMode 14 #define TYPE_timeToLive 15 #define TYPE_configHash 16 #define TYPE_keyIndex 17 void wfc_parser(const char *run_path) { // if (nvram_invmatch("wcn_enable_x", "1")) // return; if (strcmp(run_path, "")==0) return; char *p_Value = NULL; int p_ValueLength = 0; int bufferLength = 0; char wfc_path[64]; memset(wfc_path, 0, sizeof(wfc_path)); sprintf(wfc_path, "%s/SMRTNTKY/WSETTING.WFC", run_path); if (check_if_file_exist(wfc_path)==0) return; char *buffer = ILibReadFileFromDisk(wfc_path, &bufferLength); int offset = 0; struct ILibXMLNode *xnode = ILibParseXML(buffer,offset,bufferLength); struct ILibXMLNode *root = xnode; int i=0; int t_configId=0; int t_configAuthorId=0; int t_configAuthor=0; int t_ssid=0; int t_connectionType=0; int t_authentication=0; int t_encryption=0; int t_networkKey=0; int t_keyProvidedAutomatically=0; int t_ieee802Dot1xEnabled=0; int t_eapMethod=0; int t_channel2Dot4=0; int t_channel5Dot0=0; int t_deviceMode=0; int t_timeToLive=0; int t_configHash=0; int t_keyIndex=0; int t_primaryProfile=0; int t_optionalProfile=0; int elementType=0; char str_configError[256+1]; char str_configId[36+1]; char str_configAuthorId[36+1]; char str_configAuthor[128+1]; char str_ssid[32*5+1]; char str_connectionType[4+1]; char str_authentication[8+1]; char str_encryption[4+1]; char str_networkKey[63*5+1]; char str_keyProvidedAutomatically[1+1]; char str_ieee802Dot1xEnabled[1+1]; char str_eapMethod[17+1]; char str_channel2Dot4[2+1]; char str_channel5Dot0[3+1]; char str_deviceMode[14+1]; char str_timeToLive[5+1]; char str_configHash[20+1]; char str_keyIndex[1+1]; long int long_temp=0; char **endptr=NULL; char tmpstr[3]; char tmpstr2[27]; char tmpstr3[32*3+1]; int tmp=0; int tmp2=0; int wep_type=0; FILE *fp=NULL; char MACpostfix[8+1]; char deviceCFG_path[64]; int reboot_wcn=0; memset(str_configError, 0, sizeof(str_configError)); memset(str_configId, 0, sizeof(str_configId)); memset(str_configAuthorId, 0, sizeof(str_configAuthorId)); memset(str_configAuthor, 0, sizeof(str_configAuthor)); memset(str_ssid, 0, sizeof(str_ssid)); memset(str_connectionType, 0, sizeof(str_connectionType)); memset(str_authentication, 0, sizeof(str_authentication)); memset(str_encryption, 0, sizeof(str_encryption)); memset(str_networkKey, 0, sizeof(str_networkKey)); memset(str_keyProvidedAutomatically, 0, sizeof(str_keyProvidedAutomatically)); memset(str_ieee802Dot1xEnabled, 0, sizeof(str_ieee802Dot1xEnabled)); memset(str_eapMethod, 0, sizeof(str_eapMethod)); memset(str_channel2Dot4, 0, sizeof(str_channel2Dot4)); memset(str_channel5Dot0, 0, sizeof(str_channel5Dot0)); memset(str_deviceMode, 0, sizeof(str_deviceMode)); memset(str_timeToLive, 0, sizeof(str_timeToLive)); memset(str_configHash, 0, sizeof(str_configHash)); memset(str_keyIndex, 0, sizeof(str_keyIndex)); if(ILibProcessXMLNodeList(root)!=0) { /* The XML is not well formed! */ strcpy(str_configError, "Invalid WCN-UFD XML"); printf("%s\n", str_configError); logmessage("WCN-UFD", str_configError); goto end1; } while(xnode!=NULL) { if( xnode->StartTag!=0 ) { if(xnode->NameLength==8 && memcmp("configId", xnode->Name, xnode->NameLength)==0) // type="fc:str36" { elementType=TYPE_configId; if (++t_configId>1) goto end2; } else if(xnode->NameLength==14 && memcmp("configAuthorId", xnode->Name, xnode->NameLength)==0) // type="fc:str36" { elementType=TYPE_configAuthorId; if (++t_configAuthorId>1) goto end2; } else if(xnode->NameLength==12 && memcmp("configAuthor", xnode->Name, xnode->NameLength)==0) // type="fc:strMax128" { elementType=TYPE_configAuthor; if (++t_configAuthor>1) goto end2; } else if(xnode->NameLength==4 && memcmp("ssid", xnode->Name, xnode->NameLength)==0) // type="fc:strMax32" { elementType=TYPE_ssid; if (++t_ssid>1) goto end2; } else if(xnode->NameLength==14 && memcmp("connectionType", xnode->Name, xnode->NameLength)==0) // base="xs:string" { elementType=TYPE_connectionType; if (++t_connectionType>1) goto end2; } else if(xnode->NameLength==14 && memcmp("authentication", xnode->Name, xnode->NameLength)==0) // base="xs:string" { elementType=TYPE_authentication; if (++t_authentication>1) goto end2; } else if(xnode->NameLength==10 && memcmp("encryption", xnode->Name, xnode->NameLength)==0) // base="xs:string" { elementType=TYPE_encryption; if (++t_encryption>1) goto end2; } else if(xnode->NameLength==10 && memcmp("networkKey", xnode->Name, xnode->NameLength)==0) // type="fc:strMin5Max64" { elementType=TYPE_networkKey; if (++t_networkKey>1) goto end2; } else if(xnode->NameLength==24 && memcmp("keyProvidedAutomatically", xnode->Name, xnode->NameLength)==0) // type="xs:boolean" { elementType=TYPE_keyProvidedAutomatically; if (++t_keyProvidedAutomatically>1) goto end2; } else if(xnode->NameLength==19 && memcmp("ieee802Dot1xEnabled", xnode->Name, xnode->NameLength)==0) // type="xs:boolean" { elementType=TYPE_ieee802Dot1xEnabled; if (++t_ieee802Dot1xEnabled>1) goto end2; } /* The following elements are included in the schema but are not supported in the Windows XP SP2 release of the wizard. */ else if(xnode->NameLength==9 && memcmp("eapMethod", xnode->Name, xnode->NameLength)==0) // base="xs:string" { elementType=TYPE_eapMethod; if (++t_eapMethod>1) goto end2; } else if(xnode->NameLength==12 && memcmp("channel2Dot4", xnode->Name, xnode->NameLength)==0) // type="xs:positiveInteger" { elementType=TYPE_channel2Dot4; if (++t_channel2Dot4>1) goto end2; } else if(xnode->NameLength==12 && memcmp("channel5Dot0", xnode->Name, xnode->NameLength)==0) // type="xs:positiveInteger" { elementType=TYPE_channel5Dot0; if (++t_channel5Dot0>1) goto end2; } else if(xnode->NameLength==10 && memcmp("deviceMode", xnode->Name, xnode->NameLength)==0) // base="xs:string" { elementType=TYPE_deviceMode; if (++t_deviceMode>1) goto end2; } else if(xnode->NameLength==10 && memcmp("timeToLive", xnode->Name, xnode->NameLength)==0) // type="xs:positiveInteger" { elementType=TYPE_timeToLive; if (++t_timeToLive>1) goto end2; } else if(xnode->NameLength==10 && memcmp("configHash", xnode->Name, xnode->NameLength)==0) // type="fc:str20" { elementType=TYPE_configHash; if (++t_configHash>1) goto end2; } else if(xnode->NameLength==8 && memcmp("keyIndex", xnode->Name, xnode->NameLength)==0) // type="xs:positiveInteger" { elementType=TYPE_keyIndex; if (++t_keyIndex>1) goto end2; } else if(xnode->NameLength==14 && memcmp("primaryProfile", xnode->Name, xnode->NameLength)==0) // type="fc:profileInstance" { if (++t_primaryProfile>1) goto end2; else goto next_loop; } else if(xnode->NameLength==15 && memcmp("optionalProfile", xnode->Name, xnode->NameLength)==0) // type="fc:profileInstance" { if (++t_optionalProfile>32) goto end2; else goto next_loop; } else { goto next_loop; } // printf("%d\n", ++i); xnode->Name[xnode->NameLength]=0; printf("Name: %s\n", xnode->Name); p_ValueLength = ILibReadInnerXML(xnode,&p_Value); p_Value[p_ValueLength]=0; printf("Value %s\n\n", p_Value); if (elementType==TYPE_configId) { if (p_ValueLength!=36) goto end2; for( i=0; i'~') goto end2; if (strcasecmp(nvram_safe_get("wl_configId"), p_Value)==0) { printf("have been configured using this WCN-UFD configuration file already\n"); logmessage("WCN-UFD", "have been configured using this WCN-UFD configuration file already"); goto end0; } strcpy(str_configId, p_Value); } else if (elementType==TYPE_configAuthorId) { if (p_ValueLength!=36) goto end2; for( i=0; i'~') goto end2; strcpy(str_configAuthorId, p_Value); } else if (elementType==TYPE_configAuthor) { if (p_ValueLength>128 || p_ValueLength==0) goto end2; for( i=0; i'~') goto end2; strcpy(str_configAuthor, p_Value); } else if (elementType==TYPE_ssid) { if (p_ValueLength>32*5 || p_ValueLength==0) goto end2; for( i=0; i'~') goto end2; tmp=parseXMLtext(tmpstr3, p_Value); if (tmp>32 || tmp==0) goto end2; strcpy(str_ssid, tmpstr3); } else if (elementType==TYPE_connectionType) { if (p_ValueLength==4 && strncasecmp("IBSS", p_Value, 4)==0) strcpy(str_connectionType, "IBSS"); else if (p_ValueLength==3 && strncasecmp("ESS", p_Value, 3)==0) strcpy(str_connectionType, "ESS"); else goto end2; } else if (elementType==TYPE_authentication) { if (p_ValueLength==4 && strncasecmp("open", p_Value, 4)==0) strcpy(str_authentication, "open"); else if (p_ValueLength==6 && strncasecmp("shared", p_Value, 6)==0) strcpy(str_authentication, "shared"); else if (p_ValueLength==8 && strncasecmp("WPA-NONE", p_Value, 8)==0) { // strcpy(str_authentication, "WPA-NONE"); printf("aaa\n"); goto end3; } else if (p_ValueLength==3 && strncasecmp("WPA", p_Value, 3)==0) strcpy(str_authentication, "WPA"); else if (p_ValueLength==6 && strncasecmp("WPAPSK", p_Value, 6)==0) strcpy(str_authentication, "WPAPSK"); else if (p_ValueLength==4 && strncasecmp("WPA2", p_Value, 4)==0) strcpy(str_authentication, "WPA2"); else if (p_ValueLength==7 && strncasecmp("WPA2PSK", p_Value, 7)==0) strcpy(str_authentication, "WPA2PSK"); else goto end2; } else if (elementType==TYPE_encryption) { if ( p_ValueLength!=3 && p_ValueLength!=4 ) goto end2; if (p_ValueLength==4 && strncasecmp("none", p_Value, 4)==0) strcpy(str_encryption, "none"); else if (p_ValueLength==3 && strncasecmp("WEP", p_Value, 3)==0) strcpy(str_encryption, "WEP"); else if (p_ValueLength==4 && strncasecmp("TKIP", p_Value, 4)==0) strcpy(str_encryption, "TKIP"); else if (p_ValueLength==3 && strncasecmp("AES", p_Value, 3)==0) strcpy(str_encryption, "AES"); else goto end2; } else if (elementType==TYPE_networkKey) { if (p_ValueLength>63*5 || (p_ValueLength<5 && p_ValueLength!=0)) goto end2; for( i=0; i'~') goto end2; tmp=parseXMLtext(tmpstr3, p_Value); if (tmp>64 || (tmp<5 && tmp!=0)) goto end2; strcpy(str_networkKey, tmpstr3); } else if (elementType==TYPE_keyProvidedAutomatically) { if (p_ValueLength==1 && strncasecmp("0", p_Value, 1)==0) strcpy(str_keyProvidedAutomatically, "0"); else if (p_ValueLength==1 && strncasecmp("1", p_Value, 1)==0) strcpy(str_keyProvidedAutomatically, "1"); else goto end2; } else if (elementType==TYPE_ieee802Dot1xEnabled) { if (p_ValueLength==1 && strncasecmp("0", p_Value, 1)==0) strcpy(str_ieee802Dot1xEnabled, "0"); else if (p_ValueLength==1 && strncasecmp("1", p_Value, 1)==0) strcpy(str_ieee802Dot1xEnabled, "1"); else goto end2; } else if (elementType==TYPE_eapMethod) { if (p_ValueLength==7 && strncasecmp("EAP-TLS", p_Value, 7)==0) strcpy(str_eapMethod, "EAP-TLS"); else if (p_ValueLength==12 && strncasecmp("PEAP-EAP-TLS", p_Value, 12)==0) strcpy(str_eapMethod, "PEAP-EAP-TLS"); else if (p_ValueLength==17 && strncasecmp("PEAP-EAP-MSCHAPv2", p_Value, 17)==0) strcpy(str_eapMethod, "PEAP-EAP-MSCHAPv2"); else goto end2; } else if (elementType==TYPE_channel2Dot4) { if (p_ValueLength==1 && strncasecmp("0", p_Value, 1)==0) strcpy(str_channel2Dot4, "0"); else if (p_ValueLength==1 && strncasecmp("1", p_Value, 1)==0) strcpy(str_channel2Dot4, "1"); else if (p_ValueLength==1 && strncasecmp("2", p_Value, 1)==0) strcpy(str_channel2Dot4, "2"); else if (p_ValueLength==1 && strncasecmp("3", p_Value, 1)==0) strcpy(str_channel2Dot4, "3"); else if (p_ValueLength==1 && strncasecmp("4", p_Value, 1)==0) strcpy(str_channel2Dot4, "4"); else if (p_ValueLength==1 && strncasecmp("5", p_Value, 1)==0) strcpy(str_channel2Dot4, "5"); else if (p_ValueLength==1 && strncasecmp("6", p_Value, 1)==0) strcpy(str_channel2Dot4, "6"); else if (p_ValueLength==1 && strncasecmp("7", p_Value, 1)==0) strcpy(str_channel2Dot4, "7"); else if (p_ValueLength==1 && strncasecmp("8", p_Value, 1)==0) strcpy(str_channel2Dot4, "8"); else if (p_ValueLength==1 && strncasecmp("9", p_Value, 1)==0) strcpy(str_channel2Dot4, "9"); else if (p_ValueLength==2 && strncasecmp("10", p_Value, 2)==0) strcpy(str_channel2Dot4, "10"); else if (p_ValueLength==2 && strncasecmp("11", p_Value, 2)==0) strcpy(str_channel2Dot4, "11"); else if (p_ValueLength==2 && strncasecmp("12", p_Value, 2)==0) strcpy(str_channel2Dot4, "12"); else if (p_ValueLength==2 && strncasecmp("13", p_Value, 2)==0) strcpy(str_channel2Dot4, "13"); else if (p_ValueLength==2 && strncasecmp("14", p_Value, 2)==0) strcpy(str_channel2Dot4, "14"); else goto end2; } else if (elementType==TYPE_channel5Dot0) { if (p_ValueLength==1 && strncasecmp("0", p_Value, 1)==0) strcpy(str_channel5Dot0, "0"); else if (p_ValueLength==2 && strncasecmp("36", p_Value, 2)==0) strcpy(str_channel5Dot0, "36"); else if (p_ValueLength==2 && strncasecmp("40", p_Value, 2)==0) strcpy(str_channel5Dot0, "40"); else if (p_ValueLength==2 && strncasecmp("44", p_Value, 2)==0) strcpy(str_channel5Dot0, "44"); else if (p_ValueLength==2 && strncasecmp("48", p_Value, 2)==0) strcpy(str_channel5Dot0, "48"); else if (p_ValueLength==2 && strncasecmp("52", p_Value, 2)==0) strcpy(str_channel5Dot0, "52"); else if (p_ValueLength==2 && strncasecmp("56", p_Value, 2)==0) strcpy(str_channel5Dot0, "56"); else if (p_ValueLength==2 && strncasecmp("60", p_Value, 2)==0) strcpy(str_channel5Dot0, "60"); else if (p_ValueLength==3 && strncasecmp("149", p_Value, 3)==0) strcpy(str_channel5Dot0, "149"); else if (p_ValueLength==3 && strncasecmp("153", p_Value, 3)==0) strcpy(str_channel5Dot0, "153"); else if (p_ValueLength==3 && strncasecmp("157", p_Value, 3)==0) strcpy(str_channel5Dot0, "157"); else if (p_ValueLength==3 && strncasecmp("161", p_Value, 3)==0) strcpy(str_channel5Dot0, "161"); else goto end2; } else if (elementType==TYPE_deviceMode) { if (p_ValueLength==14 && strncasecmp("infrastructure", p_Value, 14)==0) strcpy(str_deviceMode, "infrastructure"); else if (p_ValueLength==6 && strncasecmp("bridge", p_Value, 6)==0) strcpy(str_deviceMode, "bridge"); else if (p_ValueLength==8 && strncasecmp("repeater", p_Value, 8)==0) strcpy(str_deviceMode, "repeater"); else if (p_ValueLength==7 && strncasecmp("station", p_Value, 7)==0) strcpy(str_deviceMode, "station"); else goto end2; } else if (elementType==TYPE_timeToLive) { if (p_ValueLength>5 || p_ValueLength==0) goto end2; long_temp=strtol(p_Value, endptr, 10); if ( (long_temp>(long int)86400) || (long_temp<(long int)0) || (long_temp==LONG_MAX) || (long_temp==LONG_MIN) || (endptr!=NULL) ) goto end2; else sprintf(str_timeToLive, "%d", (int)long_temp); } else if (elementType==TYPE_configHash) { if (p_ValueLength!=20) goto end2; for( i=0; i'9' && p_Value[i]<'A') || (p_Value[i]>'F' && p_Value[i]<'a') || p_Value[i] >'f' ) goto end2; strcpy(str_configHash, p_Value); } else if (elementType==TYPE_keyIndex) { if (p_ValueLength!=1) goto end2; if (p_ValueLength==1 && strncasecmp("1", p_Value, 1)==0) strcpy(str_keyIndex, "1"); else if (p_ValueLength==1 && strncasecmp("2", p_Value, 1)==0) strcpy(str_keyIndex, "2"); else if (p_ValueLength==1 && strncasecmp("3", p_Value, 1)==0) strcpy(str_keyIndex, "3"); else if (p_ValueLength==1 && strncasecmp("4", p_Value, 1)==0) strcpy(str_keyIndex, "4"); else goto end2; } else goto end2; } next_loop: // xnode = xnode->Peer; xnode = xnode->Next; } if( t_configId==0 || t_configAuthorId==0 || t_configAuthor==0 || t_ssid==0 || t_connectionType==0 || t_authentication==0 || t_encryption==0 || t_networkKey==0 || t_keyProvidedAutomatically==0 || t_ieee802Dot1xEnabled==0 || t_primaryProfile==0 ) { strcpy(str_configError, "lack essential WCN-UFD XML element"); printf("%s\n", str_configError); logmessage("WCN-UFD", str_configError); goto end1; } if (t_channel5Dot0==1 && strcmp(str_channel5Dot0, "0")!=0) { printf("xxx\n"); goto end3; } if (atoi(str_channel2Dot4) > get_wl_channels()) { printf("yyy\n"); goto end3; } if (strcmp(str_encryption, "none")==0 && strcmp(str_authentication, "open")!=0) { printf("bbb\n"); goto end3; } if (strcmp(str_keyProvidedAutomatically, "0")==0) { if ( strcmp(str_authentication, "WPA")==0 || strcmp(str_authentication, "WPA2")==0 ) { printf("ccc1\n"); goto end3; } } else { if ( strcmp(str_ieee802Dot1xEnabled, "1")==0 || strcmp(str_encryption, "WEP")!=0 ) printf("ccc2\n"); goto end3; } if (strcmp(str_ieee802Dot1xEnabled, "1")==0) { if ( strcmp(str_encryption, "WEP")!=0 || (strcmp(str_encryption, "WEP")==0 && (strcmp(str_keyIndex, "1")==0 || strcmp(str_keyIndex, "4")==0)) || (strcmp(str_authentication, "WPA")!=0 && strcmp(str_authentication, "WPA2")!=0) ) { printf("ddd\n"); goto end3; } } if (strcmp(str_encryption, "none")==0 || strcmp(str_encryption, "WEP")==0) { if ( strcmp(str_authentication, "WPAPSK")==0 || strcmp(str_authentication, "WPA2PSK")==0 || strcmp(str_authentication, "WPA")==0 || strcmp(str_authentication, "WPA2")==0 ) { printf("eee\n"); goto end3; } } if (strcmp(str_encryption, "TKIP")==0 || strcmp(str_encryption, "AES")==0) { if ( strcmp(str_authentication, "open")==0 || strcmp(str_authentication, "shared")==0 || strcmp(str_ieee802Dot1xEnabled, "1")==0 ) { printf("fff\n"); goto end3; } } if ( //(strcmp(str_authentication, "WPAPSK")==0 && strcmp(str_encryption, "AES")==0) || //(strcmp(str_authentication, "WPA2PSK")==0 && strcmp(str_encryption, "TKIP")==0) || (strcmp(str_authentication, "WPA")==0 && strcmp(str_encryption, "AES")==0) || (strcmp(str_authentication, "WPA2")==0 && strcmp(str_encryption, "TKIP")==0) ) { printf("ggg\n"); goto end3; } if ( strcmp(str_authentication, "shared")==0 || strcmp(str_authentication, "WPAPSK")==0 || strcmp(str_authentication, "WPA2PSK")==0 || strcmp(str_authentication, "WPA")==0 || strcmp(str_authentication, "WPA2")==0 || strcmp(str_ieee802Dot1xEnabled, "1")==0 || (strcmp(str_authentication, "open")==0 && strcmp(str_encryption, "WEP")==0) ) { if (strlen(str_networkKey)==0) { printf("no network key\n"); logmessage("WCN-UFD", "no network key"); goto end1; } } if ( (strcmp(str_authentication, "open")==0 && strcmp(str_encryption, "WEP")==0) || strcmp(str_authentication, "shared")==0 || strcmp(str_ieee802Dot1xEnabled, "1")==0 ) { if ( strlen(str_networkKey)==10 || strlen(str_networkKey)==26 ) { for( i=0; i'9' && str_networkKey[i]<'A') || (str_networkKey[i]>'F' && str_networkKey[i]<'a') || str_networkKey[i]>'f' ) { strcpy(str_configError, "invalid wireless network key"); printf("%s\n", str_configError); logmessage("WCN-UFD", str_configError); goto end1; } for( i=0; i'9' && str_networkKey[i]<'A') || (str_networkKey[i]>'F' && str_networkKey[i]<'a') || str_networkKey[i]>'f' ) { strcpy(str_configError, "invalid wireless network key"); printf("%s\n", str_configError); logmessage("WCN-UFD", str_configError); goto end1; } for( i=0; i\n"); fprintf(fp, "\n"); fprintf(fp, "\t%s\n", str_configId); if (strlen(str_configError)!=0) fprintf(fp, "\t%s\n", str_configError); fprintf(fp, "\tASUSTeK\n"); fprintf(fp, "\thttp://www.asus.com/\n"); fprintf(fp, "\t%s\n", nvram_safe_get("productid")); memset(tmpstr2, 0, sizeof(tmpstr2)); strcpy(tmpstr2, nvram_safe_get("et0macaddr")); for( i=0; i%s\n", tmpstr2); fprintf(fp, "\t%s\n", nvram_safe_get("firmver")); fprintf(fp, "\tAccess_Point\n"); fprintf(fp, "\n"); fclose(fp); } end0: ILibDestructXMLNodeList(root); // 2007.12 James { //umount_disc_parts_rc(0); //umount_disc_parts_rc(1); // 2007.12 James } if (reboot_wcn==1){ nvram_set("reboot_WCN", "2"); nvram_set("x_Setting", "1");/* Cherry Cho added in 2007/4/13. */ system("killall wsccmd"); } } void char_to_ascii(char *output, char *input)// Transfer Char to ASCII { // Cherry_Cho added in 2006/9/29 int i; char tmp[10]; char *ptr; ptr = output; for( i=0; i='0' && input[i] <='9') ||(input[i]>='A' && input[i]<='Z') ||(input[i] >='a' && input[i]<='z') || input[i] == '!' || input[i] == '*' || input[i] == '(' || input[i] == ')' || input[i] == '_' || input[i] == '-' || input[i] == "'" || input[i] == '.') { *ptr = input[i]; ptr ++; } else { sprintf(tmp, "%%%.02X", input[i]); strcpy(ptr, tmp); ptr += 3; } } *ptr = '\0'; } #endif // WCN /* insert usb mass storage */ int hotplug_usb_mass(char *product) // modified by Jiahao for WL500gP { DIR *dir_to_open, *dir_of_usb, *usb_dev_disc, *usb_dev_part; char usb_disc[128], usb_part[128], usb_file_part[128]; char usb_disc_mount_path[128], usb_disc_mount_path2[128], tmp[32]; char usb_disc_fs_path[128]; int n=0, m=0, p=0; struct dirent *dp, *dp_disc, **dpopen; char tmpstr[128], test_path[128]; int i, j; FILE *fp; int ret=0; int apps_comp=0; int apps_status=0; int apps_disk_free=0; int apps_comp_pre=0; int new_disc[2]; new_disc[0]=0; new_disc[1]=0; #ifdef DLM char *buf=NULL; int buflen=0; struct sysinfo info; #endif // DLM char dev_real_path[PATH_MAX]; // 2007.11 James. nvram_set("usb_storage_device", ""); // 2007.12 James. #ifdef CDMA if(nvram_match("hsdpa_enable", "1") && eject_scsi("/dev/cdroms/cdrom0")){ logmessage("USB Storage", "Succeed to remove the CD-ROM device."); return 0; } else logmessage("USB Storage", "Fail to remove the CD-ROM device."); #endif dir_to_open=dir_of_usb=usb_dev_disc=usb_dev_part=NULL; strcpy(tmp, ""); #ifdef DLM nvram_set("usb_storage_busy", "1"); nvram_set("apps_status_checked", "0"); if ( nvram_match("eject_from_web", "1") && (nvram_invmatch("usb_disc0_dev", "") || nvram_invmatch("usb_disc1_dev", "")) ) goto eject; #endif // DLM if (nvram_match("usb_ftpenable_x", "0")) return 0; // Mount USB to system if((usb_dev_disc = opendir("/dev/discs"))) { while(usb_dev_disc && (dp=readdir(usb_dev_disc))) { if(!strncmp(dp->d_name, "..", NAME_MAX) || !strncmp(dp->d_name, ".", NAME_MAX) /*|| !strncmp(dp->d_name, "disc0", NAME_MAX)*/) continue; sprintf(usb_disc, "/dev/discs/%s", dp->d_name); // 2007.11 James { realpath(usb_disc, dev_real_path); memset(usb_disc, 0, sizeof(usb_disc)); strcpy(usb_disc, dev_real_path); // 2007.11 James } if (nvram_match("usb_disc0_dev", usb_disc)) continue; if (nvram_match("usb_disc1_dev", usb_disc)) continue; //logs(usb_disc); if((usb_dev_part = opendir(usb_disc))) { m = 0; // part count of each disc while(usb_dev_part && (dp_disc=readdir(usb_dev_part)) && (m<7)) { //logs(dp_disc->d_name); if( !strncmp(dp_disc->d_name, "..", NAME_MAX) || !strncmp(dp_disc->d_name, ".", NAME_MAX) || !strncmp(dp_disc->d_name, "disc", NAME_MAX) || !strncmp(dp_disc->d_name, "generic", NAME_MAX) ) continue; if (m==0) { sprintf(tmpstr, nvram_get("usb_disc1_dev")); sprintf(test_path, nvram_get("usb_disc0_dev")); if (nvram_match("usb_disc0_dev", "") && strcmp(usb_disc, tmpstr)!=0) { nvram_set("usb_disc0_dev", usb_disc); nvram_set("usb_disc0_safely_removed", "0"); // 2008.06 James. new_disc[0]=1; } else if (nvram_match("usb_disc1_dev", "") && strcmp(usb_disc, test_path)!=0) { nvram_set("usb_disc1_dev", usb_disc); nvram_set("usb_disc1_safely_removed", "0"); // 2008.06 James. new_disc[1]=1; } } sprintf(usb_part, "/dev/discs/%s/%s", dp->d_name, dp_disc->d_name); realpath(usb_part, dev_real_path); // 2007.11 James. if (n==0) { sprintf(usb_file_part, "/tmp/harddisk"); mkdir_if_none(usb_file_part); } sprintf(usb_file_part, "/tmp/harddisk/part%d", n); while (check_if_dir_exist(usb_file_part)==1) sprintf(usb_file_part, "/tmp/harddisk/part%d", ++n); mkdir_if_none(usb_file_part); #ifdef MOUNTALL //eval("mount", usb_part, usb_file_part); eval("mount", dev_real_path, usb_file_part); // 2007.11 James. printf("mountall\n"); #else // MOUNTALL //if (mount_r(usb_part, usb_file_part)) if(mount_r(dev_real_path, usb_file_part)) // 2007.11 James. { if (strcmp(usb_disc, nvram_safe_get("usb_disc0_dev"))==0) { j=atoi(nvram_safe_get("usb_disc0_index")); sprintf(usb_disc_mount_path, "usb_disc0_path%d", j); sprintf(usb_disc_mount_path2, "usb_disc0_index"); sprintf(usb_disc_fs_path, "usb_disc0_fs_path%d", j); } else if (strcmp(usb_disc, nvram_safe_get("usb_disc1_dev"))==0) { j=atoi(nvram_safe_get("usb_disc1_index")); sprintf(usb_disc_mount_path, "usb_disc1_path%d", j); sprintf(usb_disc_mount_path2, "usb_disc1_index"); sprintf(usb_disc_fs_path, "usb_disc1_fs_path%d", j); } nvram_set(usb_disc_mount_path, usb_file_part); //nvram_set(usb_disc_fs_path, usb_part); nvram_set(usb_disc_fs_path, dev_real_path); // 2007.11 James. sprintf(usb_disc_mount_path, "%d", ++j); nvram_set(usb_disc_mount_path2, usb_disc_mount_path); n++; m++; p++; } else { rmdir(usb_file_part); //printf("mount %s failed\n", usb_part); printf("mount %s failed\n", dev_real_path); // 2007.11 James. } #endif // MOUNTALL } if (!m) // There is no other partition { sprintf(usb_part, "/dev/discs/%s/disc", dp->d_name); realpath(usb_part, dev_real_path); // 2007.11 James. if (n==0) { sprintf(usb_file_part, "/tmp/harddisk"); mkdir_if_none(usb_file_part); } sprintf(usb_file_part, "/tmp/harddisk/part%d", n); while (check_if_dir_exist(usb_file_part)==1) sprintf(usb_file_part, "/tmp/harddisk/part%d", ++n); mkdir_if_none(usb_file_part); #ifdef MOUNTALL //eval("mount", usb_part, usb_file_part); eval("mount", dev_real_path, usb_file_part); // 2007.11 James. #else // MOUNTALL //if(mount_r(usb_part, usb_file_part)) if(mount_r(dev_real_path, usb_file_part)) // 2007.11 James. { sprintf(tmpstr, nvram_get("usb_disc1_dev")); sprintf(test_path, nvram_get("usb_disc0_dev")); if (nvram_match("usb_disc0_dev", "") && strcmp(usb_disc, tmpstr)!=0) { nvram_set("usb_disc0_dev", usb_disc); new_disc[0]=1; } else if (nvram_match("usb_disc1_dev", "") && strcmp(usb_disc, test_path)!=0) { nvram_set("usb_disc1_dev", usb_disc); new_disc[1]=1; } //if (strncmp(usb_part, nvram_safe_get("usb_disc0_dev"), 16)==0) if(!strncmp(usb_part, nvram_safe_get("usb_disc0_dev"), 33)) // 2007.11 James. { nvram_set("usb_disc0_path0", usb_file_part); //nvram_set("usb_disc0_fs_path0", usb_part); nvram_set("usb_disc0_fs_path0", dev_real_path); // 2007.11 James. nvram_set("usb_disc0_index", "1"); } //else if (strncmp(usb_part, nvram_safe_get("usb_disc1_dev"), 16)==0) else if(!strncmp(usb_part, nvram_safe_get("usb_disc1_dev"), 33)) // 2007.11 James. { nvram_set("usb_disc1_path0", usb_file_part); //nvram_set("usb_disc1_fs_path0", usb_part); nvram_set("usb_disc1_fs_path0", dev_real_path); // 2007.11 James. nvram_set("usb_disc1_index", "1"); } n++; p++; } else { rmdir(usb_file_part); //printf("mount %s failed\n", usb_part); printf("mount %s failed\n", dev_real_path); // 2007.11 James. } #endif // MOUNTALL } printf("\n\n**********************************************\n"); write_disc_status(); printf("**********************************************\n\n"); } } } #ifdef DLM eject: if(p || (nvram_match("eject_from_web", "1") && (nvram_invmatch("usb_disc0_dev", "") || nvram_invmatch("usb_disc1_dev", ""))) )// if any usb mass storage device newly mounted at this time { nvram_set("eject_from_web", "0"); strcpy(test_path, ""); if(nvram_invmatch("usb_disc0_dev", "") && (nvram_match("apps_dlx", "0") || check_disk_free_GE_1G(nvram_safe_get("usb_disc0_path0")) == 2)) { strcpy(test_path, nvram_safe_get("usb_disc0_path0")); } else if ( nvram_invmatch("usb_disc1_dev", "") && (nvram_match("apps_dlx", "0")||check_disk_free_GE_1G(nvram_safe_get("usb_disc1_path0"))==2) ) { strcpy(test_path, nvram_safe_get("usb_disc1_path0")); } else if ( nvram_invmatch("usb_disc0_dev", "") ) { strcpy(test_path, nvram_safe_get("usb_disc0_path0")); } else if ( nvram_invmatch("usb_disc1_dev", "") ) { strcpy(test_path, nvram_safe_get("usb_disc1_path0")); } strcpy(tmp, test_path); if(nvram_match("swap_on", "0") && nvram_match("apps_dlx", "1") && (apps_comp_pre = ckeck_apps_completeness_pre(tmp)) == 1) { if(strcmp(test_path, "") != 0) { memset(tmpstr, 0, sizeof(tmpstr)); sprintf(tmpstr, "%s/swap", test_path); unlink(tmpstr); memset(tmpstr, 0, sizeof(tmpstr)); sprintf(tmpstr, "%s/.swap", test_path); unlink(tmpstr); ret = check_disk_free_GE_1G(test_path); if(ret==2) { if(strcmp(test_path, nvram_safe_get("usb_disc0_path0")) == 0) nvram_set("apps_dms_usb_port_x2", nvram_safe_get("usb_disc0_port")); else if (strcmp(test_path, nvram_safe_get("usb_disc1_path0")) == 0) nvram_set("apps_dms_usb_port_x2", nvram_safe_get("usb_disc1_port")); sysinfo(&info); if((info.freeram+info.bufferram) >= 1024*1024*2) buflen = 1024*1024*2; else if((info.freeram+info.bufferram) >= 1024*1024*1.6) buflen = 1024*1024*1.6; else if((info.freeram+info.bufferram) >= 1024*1024*1) buflen = 1024*1024*1; else if((info.freeram+info.bufferram) >= 1024*1024*0.8) buflen = 1024*1024*0.8; else buflen = 1024*1024*0.5; buf = malloc(buflen); for(i = 0; i < buflen; i++) buf[i]='\n'; fp = fopen(tmpstr, "a"); if(fp != NULL) { for(i = 0; i < (1024*1024*32/buflen); i++) fprintf(fp, "%s", buf); free(buf); fclose(fp); /*memset(test_path, 0, sizeof(test_path)); sprintf(test_path, "mkswap %s", tmpstr); system(test_path); memset(test_path, 0, sizeof(test_path)); sprintf(test_path, "swapon %s", tmpstr); system(test_path);//*/ eval("/sbin/mkswap", tmpstr); swapon(tmpstr, 0); // 2008.04 James. logmessage("USB storage", "32MB swap file is added"); nvram_set("swap_on", "1"); nvram_set("swap_file", tmpstr); // 2008.06 James. } } else if (ret==1) logmessage("USB storage", "The swap file is not added for free space is less than 33MB"); else if (ret==3) logmessage("USB storage", "The swap file is not added for partition size is less than 1024MB"); else if (ret==0) logmessage("USB storage", "The swap file is not added for unknown reasons"); } } start_script(new_disc); // Move ahead to speed up WCN if(!nvram_match("reboot_WCN", "2")) run_ftpsamba(); // if (nvram_match("apps_dmsx", "1")) // exec_dms(); apps_disk_free = check_disk_free_apps(tmp, apps_comp); if(apps_disk_free == 1) nvram_set("apps_disk_free", "1"); else nvram_set("apps_disk_free", "0"); /* if((apps_comp_pre==1) && nvram_match("apps_running", "0") && (nvram_match("apps_dlx", "1")||nvram_match("apps_dmsx", "1")) ) */ //if(nvram_match("apps_running", "0") && if(strcmp(nvram_safe_get("apps_running"), "1") != 0 && !nvram_match("reboot_WCN", "2") && ((apps_comp_pre == 1 && nvram_match("apps_dlx", "1")) || nvram_match("apps_dmsx", "1")) ) { if (strcmp(tmp, "")!=0) { apps_comp=ckeck_apps_completeness(tmp); if (apps_comp==1) nvram_set("apps_comp", "1"); else { nvram_set("apps_comp", "0"); if ( strcmp(nvram_get("swap_on"), "1")==0) { printf("try to swapoff swap file.\n"); if (strcmp(tmp, "")!=0) { memset(tmpstr, 0, sizeof(tmpstr)); sprintf(tmpstr, "%s/.swap", tmp); swapoff(tmpstr); sleep(1); if (swap_check()==1) { logmessage("USB storage", "swapoff unsuccessfully"); nvram_set("swapoff_failed", "1"); unlink(tmpstr); nvram_set("reboot", "1"); } else { logmessage("USB storage", "swapoff successfully"); nvram_set("swap_on", "0"); nvram_set("swap_file", ""); // 2008.06 James. nvram_set("swapoff_failed", "0"); nvram_set("apps_dms_usb_port_x2", "-1"); unlink(tmpstr); } } } } if (nvram_match("apps_dlx", "0") || (nvram_match("apps_dlx", "1") && ret==2) || (nvram_match("apps_dmsx", "1") && !(nvram_match("apps_dlx", "1") && ret==2)) ) { if ((apps_comp==1 && apps_disk_free==1) || nvram_match("apps_dmsx", "1")) { if (strcmp(tmp, nvram_safe_get("usb_disc0_path0"))==0) nvram_set("apps_dms_usb_port_x", nvram_safe_get("usb_disc0_port")); else if (strcmp(tmp, nvram_safe_get("usb_disc1_path0"))==0) nvram_set("apps_dms_usb_port_x", nvram_safe_get("usb_disc1_port")); start_apps(); //nvram_set("apps_running", "1"); } } else { fprintf(stderr, "skip running DMS & DM for no swap file\n"); logmessage("Media Server", "daemon is not started for no swap file"); logmessage("Download Master", "daemon is not started for no swap file"); } } else fprintf(stderr, "skip running DMS & DM for mismatching\n"); } else fprintf(stderr, "skip running DMS & DM\n"); } nvram_set("usb_storage_busy", "0"); nvram_set("apps_status_checked", "1"); #else // DLM if (p) // if any usb mass storage device newly mounted at this time { start_script(new_disc); } #endif // DLM #ifdef USBCOPY_SUPPORT n = 1; if((dir_to_open = opendir("/tmp/harddisk"))) { while(dir_to_open && (dp=readdir(dir_to_open))) { if(!strncmp(dp->d_name, "..", NAME_MAX) || !strncmp(dp->d_name, ".", NAME_MAX) || !strncmp(dp->d_name, "part", 4)) continue; sprintf(usb_part, "/tmp/harddisk/%s", dp->d_name); if(scandir(usb_part, &dpopen, 0, alphasort) <= 2) continue; while(1) { sprintf(path_copy_to, "/tmp/harddisk/part1/USBpart%03d", n); if(!opendir(path_copy_to)) { if(mkdir(path_copy_to, 0777)) { perror("error on creating usb directory"); } eval("echo", path_copy_to); break; } else n++; } if((dir_of_usb = opendir(usb_part))) { while(dir_of_usb && (dp_disc=readdir(dir_of_usb))) { if(!strncmp(dp_disc->d_name, "..", NAME_MAX) || !strncmp(dp_disc->d_name, ".", NAME_MAX)) continue; sprintf(path_to_copy, "/tmp/harddisk/%s/%s", dp->d_name, dp_disc->d_name); eval("cp", "-Rf", path_to_copy, path_copy_to); sync(); } } n++; } } #endif // USBCOPY_SUPPORT if(usb_dev_disc) closedir(usb_dev_disc); if(usb_dev_part) closedir(usb_dev_part); if(dir_to_open) closedir(dir_to_open); return 0; } #ifdef CDMA // HSDPA { int hsdpa_detect(void) { int f; int ret=-1; extern int errno; if((f=open("/dev/ttyACM0", O_WRONLY))!=-1) { csprintf("--- hsdpa_detect: Detect as ACM! ---\n"); close(f); ret=0; } else if((f=open("/dev/ttyUSB0", O_WRONLY))!=-1) { csprintf("--- hsdpa_detect: Detect as USB! ---\n"); close(f); ret=1; } else { csprintf("--- hsdpa_detect: Detect as not HSDPA! ---\n"); } return ret; } int hotplug_hsdpa(char *product) { char tmp[100]; char vid[32]; char pid[32]; char *ptr1, *ptr2; int combo; strcpy(tmp, product); ptr1=strchr(tmp, '/'); *ptr1=0; sprintf(vid, "vendor=0x%s", tmp); ptr2=strchr(ptr1+1, '/'); *ptr2=0; sprintf(pid, "product=0x%s", ptr1+1); if (nvram_match("hsdpa_enable", "0")) return 0; if (nvram_match("hsdpa_product", "")) { //logmessage("HSDPA detected", product); #ifndef WCDMA eval("rmmod", "modem"); #endif eval("rmmod", "usbserial"); eval("mknod", "/dev/ttyACM0", "c", "166", "0"); eval("mknod", "/dev/ttyACM1", "c", "166", "1"); eval("mknod", "/dev/ttyUSB0", "c", "188", "0"); eval("mknod", "/dev/ttyUSB1", "c", "188", "1"); eval("mknod", "/dev/ttyUSB2", "c", "188", "2"); eval("mknod", "/dev/ttyUSB3", "c", "188", "3"); #ifdef WCDMA eval("insmod", "usbserial.o", vid, pid); #else eval("insmod", "usbserial"); eval("insmod", "modem"); #endif if(!strncmp(product, "1a8d/", 5)){ logmessage("Add USB Modem", product); nvram_set("hsdpa_product", product); nvram_set("hsdpa_combo", "1"); nvram_set("got_HSDPA", "1"); nvram_set("hsdpa_ttyUSB_num", "1"); nvram_set("cdma_down", "1"); return 1; } else if(!strcmp(product, "805/480f/0")){ logmessage("Add USB Modem", product); nvram_set("hsdpa_product", product); nvram_set("hsdpa_combo", "1"); nvram_set("got_HSDPA", "1"); nvram_set("hsdpa_ttyUSB_num", "3"); nvram_set("cdma_down", "1"); return 1; } else if(!strcmp(product, "12d1/1001/0") || !strcmp(product, "12d1/1003/0") ){ logmessage("Add USB Modem", product); nvram_set("hsdpa_product", product); nvram_set("hsdpa_combo", "1"); nvram_set("got_HSDPA", "1"); nvram_set("hsdpa_ttyUSB_num", "0"); nvram_set("cdma_down", "1"); return 1; } else if((combo = hsdpa_detect()) != -1) { logmessage("Add USB Modem", product); nvram_set("hsdpa_product", product); if(combo){ nvram_set("hsdpa_combo", "1"); //nvram_set("got_HSDPA", "0"); nvram_set("hsdpa_ttyUSB_num", ""); } else nvram_set("hsdpa_combo", "0"); // start cdma nvram_set("cdma_down", "1"); return 1; } /*else{ eval("rmmod", "usbserial"); csprintf("test 1: vid=%s, pid=%s. ---\n", vid, pid); nvram_set("hsdpa_combo", "-1"); }//*/ } // skip other interface on the same device if(nvram_match("hsdpa_product", product)){ csprintf("--- hotplug_hsdpa: Found other interface of the HSDPA card! ---\n"); return 1; } return 0; } int unplug_hsdpa(char *product) { char tmp[100]; char vid[32]; char pid[32]; char *ptr1, *ptr2; strcpy(tmp, product); ptr1=strchr(tmp, '/'); *ptr1=0; sprintf(vid, "vendor=0x%s", tmp); ptr2=strchr(ptr1+1, '/'); *ptr2=0; sprintf(pid, "product=0x%s", ptr1+1); //logmessage("Remove USB Device VID", vid); //logmessage("Remove USB Device PID", pid); //if(interface) // logmessage("Remove USB Device INTERFACE", interface); if (nvram_match("hsdpa_enable", "0")) return 0; if (nvram_match("hsdpa_product", product)) { logmessage("Remove USB Modem", product); nvram_set("hsdpa_product", ""); nvram_set("hsdpa_combo", "-1"); // stop cdma nvram_set("cdma_down", "99"); nvram_set("got_HSDPA", "0"); return 1; } return 0; } #endif // CDMA // HSDPA } /* plugging or removing usb device */ /* usbcore, usb-ohci, usb-ehci, printer are always there */ /* usb-storage, sd_mod, scsi_mod, videodev are there if functions are enabled */ /* pwc, ov511 i2c, depends on current status */ int hotplug_usb(void) { char *action, *interface, *product, *usb_path; // 2009.05 James. HSDPA { char *num_interfaces; int numOfInterfaces; int isPrinter; // 2009.05 James. HSDPA } int isweb; char flag[6]; #ifdef U2EC int u2ec_fifo; #endif // U2EC char usbpath_nvram[16]; char temp_usbpath_device[16]; action = getenv("ACTION"); interface = getenv("INTERFACE"); product = getenv("PRODUCT"); usb_path = getenv("USBDEVICE_PATH"); // 2009.05 James. HSDPA { num_interfaces = getenv("NUM_INTERFACES"); num_interfaces = (num_interfaces == NULL || strlen(num_interfaces) <= 0)?"0":num_interfaces; numOfInterfaces = atoi(num_interfaces); isPrinter = atoi(getenv("ISPRINTER")); // 2009.05 James. HSDPA } #ifdef CDMA // HSDPA { if( !action) #else // CDMA if( !action || !interface) #endif // CDMA // HSDPA } { return EINVAL; } //nvram_set("usb_vidpid", product); if(usb_path){ nvram_set("usb_path", usb_path); memset(usbpath_nvram, 0, 16); sprintf(usbpath_nvram, "usb_path%s", usb_path); memset(temp_usbpath_device, 0, 16); strcpy(temp_usbpath_device, nvram_safe_get(usbpath_nvram)); } //if(product && strncmp(product, "0/", 2)) if(product // 2009.06 James. { #ifdef WL500GPV2 && (!strcmp(usb_path, "1.1") || !strcmp(usb_path, "1.2")) #elif WL520GU && !strcmp(usb_path, "1") #else && strncmp(product, "0/", 2) #endif // 2009.06 James. } ) { isweb = WEB_NONE; #ifdef CDMA // HSDPA { if(!interface) goto usbhandler; #endif // CDMA // HSDPA } if(!strncmp(interface, "8/", 2) && isPrinter != 1) { //logmessage("USB mass storage", "attached"); isweb = MASS_STORAGE; goto usbhandler; } else if(!strncmp(interface, "7/", 2)) //2008.03.13 Yau add printer log { // 2008.05 James. { //logmessage("USB printer", "attached"); isweb = USB_PRINTER; goto usbhandler; // 2008.05 James. } } else if(!strncmp(interface, "1/1", 3)) { // if the audio device is the same with web cam, // just skip it if(nvram_match("usb_web_device", product)) return 0; isweb = WEB_AUDIO; goto usbhandler; } else if(!strncmp(interface, "1/", 2)) { return 0; } int i; i = 0; while(PWCLIST[i] != NULL) { if(strstr(product, PWCLIST[i])) { isweb = WEB_PWCWEB; goto usbhandler; } ++i; } i = 0; while(OVLIST[i] != NULL) { if(strstr(product, OVLIST[i])) { isweb = WEB_OVWEB; goto usbhandler; } ++i; } } else return EINVAL; usbhandler: csprintf("- hotplug(%d): action=%s, interface=%s, product=%s, usb_path=%s, isPrinter=%d. -\n" , isweb , action , interface , product , usb_path , isPrinter ); if (strstr(action, "add")) { logmessage("Add device", "interface=%s, product=%s, usb_path=%s, isPrinter=%d, numOfInterfaces=%d." , interface , product , usb_path , isPrinter , numOfInterfaces ); if(isweb == MASS_STORAGE) { #ifdef CDMA // HSDPA if((numOfInterfaces == 1 || numOfInterfaces == 2) && (!strcmp(product, "12d1/1001/0") || !strcmp(product, "12d1/1003/0")) ){ logmessage("Remove module", "ehci-hcd."); eval("rmmod", "ehci-hcd"); logmessage("insert module", "ehci-hcd."); eval("insmod", "ehci-hcd"); return 0; } else #endif // HSDPA if(usb_path && strlen(temp_usbpath_device) <= 0){ nvram_set("asus_mfg_flash", "1"); // 2008.06 James. { if(strlen(nvram_safe_get("usb_disc0_pid")) <= 0){ nvram_set("usb_disc0_pid", product); nvram_set("usb_disc0_port", usb_path); } else if(strlen(nvram_safe_get("usb_disc1_pid")) <= 0){ nvram_set("usb_disc1_pid", product); nvram_set("usb_disc1_port", usb_path); } // 2008.06 James. } nvram_set("usb_storage_device", product); //watchdog will call hotplug_usb_mass if set nvram_set(usbpath_nvram, "storage"); logmessage("USB storage", "\"%s\" was plugged in.", product); // 2008.02 James. } } // 2008.05 James. { else if(isweb == USB_PRINTER) { nvram_set("asus_mfg_printer", "1"); if(nvram_match("usb_printer_device", "")) logmessage("USB printer", "\"%s\" was plugged in.", product); nvram_set("usb_printer_device", product); if(usb_path){ nvram_set(usbpath_nvram, "printer"); nvram_set("usb_path_printer", usb_path); } } // 2008.05 James. } else if(isweb == WEB_AUDIO) { #ifdef AUDIO_SUPPORT nvram_set("asus_mfg_audio", "1"); if (nvram_match("usb_audio_device", "")) logmessage("USB audio", "attached"); nvram_set("usb_audio_device", product); if(usb_path){ nvram_set(usbpath_nvram, "audio"); nvram_set("usb_path_audio", usb_path); } refresh_wave(); #else ; #endif // AUDIO_SUPPORT } else if(isweb == WEB_PWCWEB || isweb == WEB_OVWEB) { #ifdef WEBCAM_SUPPORT nvram_set("asus_mfg_webcam", "1"); if (nvram_match("usb_web_device", "")) logmessage("USB webcam", "attached"); sprintf(flag, "%d", isweb); nvram_set("usb_web_device", product); nvram_set("usb_web_flag", flag); nvram_set("usb_webdriver_x", ""); if(usb_path){ nvram_set(usbpath_nvram, "webcam"); nvram_set("usb_path_webcam", usb_path); } #else ; #endif // WEBCAM_SUPPORT } //else{ else if(isPrinter != 1 && (strlen(temp_usbpath_device) <= 0 || !strcmp(temp_usbpath_device, "storage")) //&& !strcmp(nvram_safe_get("hsdpa_product"), "") && strcmp(product, "0/0/0") ){ #ifdef CDMA // HSDPA { if(hotplug_hsdpa(product)){ nvram_set("usb_hsdpa_device", product); if(usb_path){ nvram_set(usbpath_nvram, "HSDPA"); nvram_set("usb_path_hsdpa", usb_path); } //return 0; } #else ; #endif // HSDPA } } #ifdef U2EC u2ec_fifo = open("/tmp/u2ec_fifo", O_WRONLY|O_NONBLOCK); write(u2ec_fifo, "a", 1); close(u2ec_fifo); #endif // U2EC } else //USB device removed { logmessage("Remove device", "interface=%s, product=%s, usb_path=%s, isPrinter=%d." , interface , product , usb_path , isPrinter ); if(isweb == MASS_STORAGE // 2008.02 James. && numOfInterfaces == 1 // 2009.05 James. HSDPA && !strcmp(temp_usbpath_device, "storage") ) { // 2009.05 James. { #ifdef CDMA // HSDPA { if(!strncmp(product, "1a8d/", 5) || !strncmp(product, "12d1/", 5) ) ; else{ #endif // HSDPA } // 2009.05 James. } logmessage("USB device", "\"%s\" was removed.", product); // 2008.02 James. // 2008.06 James. { if(!strcmp(nvram_safe_get("usb_disc0_pid"), product) && !strcmp(nvram_safe_get("usb_disc0_safely_removed"), "1") && strlen(nvram_safe_get("usb_disc1_pid")) <= 0){ nvram_set("usb_disc0_pid", ""); nvram_set("usb_disc0_safely_removed", "0"); //return 0; } else if(!strcmp(nvram_safe_get("usb_disc1_pid"), product) && !strcmp(nvram_safe_get("usb_disc1_safely_removed"), "1") && strlen(nvram_safe_get("usb_disc0_pid")) <= 0){ nvram_set("usb_disc1_pid", ""); nvram_set("usb_disc1_safely_removed", "0"); //return 0; } // 2008.06 James. } // 2007.12 James { //remove_usb_mass(product); nvram_set("usb_storage_device_remove", product); // 2007.12 James } // 2009.05 James. { #ifdef CDMA // HSDPA { } #endif // HSDPA } // 2009.05 James. } } else if(isweb == USB_PRINTER) { logmessage("USB printer", "\"%s\" was removed.", product); nvram_set("usb_printer_device", ""); nvram_set("usb_path_printer", ""); } else if(isweb == WEB_AUDIO) { #ifdef AUDIO_SUPPORT logmessage("USB audio", "\"%s\" was removed.", product); remove_usb_audio(product); nvram_set("usb_audio_device", ""); nvram_set("usb_path_audio", ""); #else ; #endif // AUDIO_SUPPORT } else if(isweb == WEB_PWCWEB || isweb == WEB_OVWEB) { #ifdef WEBCAM_SUPPORT if (nvram_invmatch("usb_web_device", "")) { logmessage("USB webcam", "\"%s\" was removed.", product); remove_usb_webcam(product, isweb); nvram_set("usb_web_device", ""); nvram_set("usb_web_flag", ""); nvram_set("usb_path_webcam", ""); } #else ; #endif // WEBCAM_SUPPORT } //else{ else if(!strcmp(temp_usbpath_device, "HSDPA")){ #ifdef CDMA // HSDPA { if(unplug_hsdpa(product)){ nvram_set("usb_hsdpa_device", ""); nvram_set("usb_path_hsdpa", ""); //return 0; } #else ; #endif // HSDPA } } #ifdef U2EC u2ec_fifo = open("/tmp/u2ec_fifo", O_WRONLY|O_NONBLOCK); write(u2ec_fifo, "r", 1); close(u2ec_fifo); #endif // U2EC if(usb_path) nvram_set(usbpath_nvram, ""); } return 0; } #endif // USB_SUPPORT /* stop necessary services for firmware upgrade */ /* stopservice: for firmware upgarde */ /* stopservice 1: for button setup */ int stop_service_main(int type) { if (type==1) { //stop_misc(); //stop_logger(); stop_usb(); stop_nas(); stop_upnp(); //stop_dhcpd(); stop_dns(); stop_httpd(); eval("killall", "udhcpc"); //eval("killall", "infosvr"); } else { if(type==99) stop_misc_no_watchdog(); else stop_misc(); stop_logger(); stop_usb(); //stop_nas(); // mark this for upgrade firmware with wireless. stop_upnp(); stop_dhcpd(); stop_dns(); } dprintf("done\n"); return 0; } int service_handle(void) { char *service; char tmp[100], *str; int pid; char *ping_argv[] = { "ping", "140.113.1.1", NULL}; FILE *fp; service = nvram_get("rc_service"); if(!service) kill(1, SIGHUP); if(strstr(service,"wan_disconnect")!=NULL) { cprintf("wan disconnect\n"); logmessage("WAN Connection", "Disconnected manually"); #ifdef CDMA // HSDPA test if(nvram_invmatch("hsdpa_product", "") && nvram_invmatch("hsdpa_combo", "-1")){ printf("--- HSDPA test: disconnect! ---\n"); nvram_set("cdma_down", "3"); } else #endif // CDMA*/ if (nvram_match("wan0_proto", "dhcp") #ifdef BIGPOND || nvram_match("wan0_proto", "bigpond") #endif // BIGPOND /*#ifdef CDMA // HSDPA test //|| nvram_match("wan0_proto_t", "cdma") || nvram_invmatch("hsdpa_combo", "-1") #endif // CDMA*/ ) { snprintf(tmp, sizeof(tmp), "/var/run/udhcpc%d.pid", 0); if ((str = file2str(tmp))) { pid = atoi(str); free(str); kill(pid, SIGUSR2); } } else { stop_wan2(); update_wan_status(0); sleep(3); } } else if (strstr(service,"wan_connect")!=NULL) { cprintf("wan connect\n"); logmessage("WAN Connection", "Connected manually"); setup_ethernet(nvram_safe_get("wan_ifname")); #ifdef CDMA // HSDPA test if(nvram_invmatch("hsdpa_product", "") && nvram_invmatch("hsdpa_combo", "-1")){ printf("--- HSDPA test: connect! ---\n"); nvram_set("cdma_down", "1"); } else #endif // CDMA*/ if (nvram_match("wan0_proto", "dhcp") #ifdef BIGPOND || nvram_match("wan0_proto", "bigpond") #endif // BIGPOND /*#ifdef CDMA // HSDPA test //|| nvram_match("wan0_proto_t", "cdma") || nvram_invmatch("hsdpa_combo", "-1") #endif // CDMA*/ ) { snprintf(tmp, sizeof(tmp), "/var/run/udhcpc%d.pid", 0); if ((str = file2str(tmp))) { pid = atoi(str); free(str); kill(pid, SIGUSR1); } } else { #ifndef REMOVE // pppoe or ppptp, check if /tmp/ppp exist if (nvram_invmatch("wan0_proto", "static") && (fp=fopen("/tmp/ppp/ip-up", "r"))!=NULL) { fclose(fp); _eval(ping_argv, NULL, 0, &pid); } else { stop_wan(); sleep(3); start_wan(); sleep(2); _eval(ping_argv, NULL, 0, &pid); } #else // REMOVE stop_wan(); sleep(2); start_wan(); /* trigger connect */ eval("ntpclient", "-h", "test", "-c", "1"); #endif // REMOVE } } #ifdef ASUS_DDNS //2007.03.26 Yau add for asus ddns else if(strstr(service,"ddns_hostname_check") != NULL) { char host[64]; char wan_ifname[16]; strcpy(host, nvram_get("ddns_hostname_x")); #ifdef CDMA // HSDPA if(strcmp(nvram_safe_get("hsdpa_product"), "") != 0) strcpy(wan_ifname, "ppp0"); else #endif if(nvram_match("wan_proto", "pppoe") || nvram_match("wan_proto", "pptp") || nvram_match("wan_proto", "l2tp")) strcpy(wan_ifname, nvram_get("wan0_pppoe_ifname")); else strcpy(wan_ifname, nvram_get("wan0_ifname")); char *ddns_argv[] = {"ez-ipupdate", "-h", host, "-s", "ns1.asuscomm.com", "-S", "dyndns", "-i", wan_ifname, "-A", "1", NULL}; pid_t pid; //Execute ez-ipupdate then die. eval("killall", "ez-ipupdate"); _eval(ddns_argv, NULL, 0, &pid); } #endif // ASUS_DDNS nvram_unset("rc_service"); return 0; } #ifdef AUDIO_SUPPORT int hotplug_usb_audio(char *product) { char *wave_argv[]={"waveserver", NULL}; pid_t pid; if (strlen(product)==0) return; return _eval(wave_argv, ">/dev/null", 0, NULL); // 2007.11 James. add "return" } int remove_usb_audio(char *product) { return eval("killall", "waveserver"); // 2007.11 James. add "return" } int start_audio(void) { char *wave_argv[] = {"waveservermain", NULL}; pid_t pid; _eval(wave_argv, NULL, 0, &pid); return 0; } int stop_audio(void) { int ret = eval("killall", "waveserver"); return ret; // 2007.11 James. } #endif // AUDIO_SUPPORT #ifdef GUEST_ACCOUNT int start_dhcpd_guest(void) { FILE *fp; char *dhcpd_argv[] = {"udhcpd", "/tmp/udhcpd1.conf", NULL, NULL}; char *slease = "/tmp/udhcpd-br1.sleases"; pid_t pid; if (nvram_match("router_disable", "1") || nvram_invmatch("wl_guest_enable", "1") || nvram_invmatch("lan1_proto", "dhcp")) return 0; dprintf("%s %s %s %s\n", nvram_safe_get("lan1_ifname"), nvram_safe_get("dhcp1_start"), nvram_safe_get("dhcp1_end"), nvram_safe_get("lan1_lease")); if (!(fp = fopen("/tmp/udhcpd-br1.leases", "a"))) { perror("/tmp/udhcpd-br1.leases"); return errno; } fclose(fp); /* Write configuration file based on current information */ if (!(fp = fopen("/tmp/udhcpd1.conf", "w"))) { perror("/tmp/udhcpd1.conf"); return errno; } fprintf(fp, "pidfile /var/run/udhcpd-br1.pid\n"); fprintf(fp, "start %s\n", nvram_safe_get("dhcp1_start")); fprintf(fp, "end %s\n", nvram_safe_get("dhcp1_end")); fprintf(fp, "interface %s\n", nvram_safe_get("lan1_ifname")); fprintf(fp, "remaining yes\n"); fprintf(fp, "lease_file /tmp/udhcpd-br1.leases\n"); fprintf(fp, "option subnet %s\n", nvram_safe_get("lan1_netmask")); fprintf(fp, "option router %s\n", nvram_safe_get("lan1_ipaddr")); if (nvram_invmatch("dhcp_dns1_x","")) fprintf(fp, "option dns %s\n", nvram_safe_get("dhcp_dns1_x")); fprintf(fp, "option dns %s\n", nvram_safe_get("lan1_ipaddr")); fprintf(fp, "option lease %s\n", nvram_safe_get("lan1_lease")); if (nvram_invmatch("dhcp_wins_x","")) fprintf(fp, "option wins %s\n", nvram_safe_get("dhcp_wins_x")); if (nvram_invmatch("lan_domain", "")) fprintf(fp, "option domain %s\n", nvram_safe_get("lan_domain")); fclose(fp); dhcpd_argv[2] = NULL; _eval(dhcpd_argv, NULL, 0, &pid); dprintf("done\n"); return 0; } int stop_dhcpd_guest(void) { char sigusr1[] = "-XX"; int ret; /* * Process udhcpd handles two signals - SIGTERM and SIGUSR1 * * - SIGUSR1 saves all leases in /tmp/udhcpd.leases * - SIGTERM causes the process to be killed * * The SIGUSR1+SIGTERM behavior is what we like so that all current client * leases will be honorred when the dhcpd restarts and all clients can extend * their leases and continue their current IP addresses. Otherwise clients * would get NAK'd when they try to extend/rebind their leases and they * would have to release current IP and to request a new one which causes * a no-IP gap in between. */ ret = eval("killall", "udhcpd"); dprintf("done\n"); return ret; } #endif // GUEST_ACCOUNT #ifdef DLM // 2007.11 James. replace this with using eval("/sbin/write_smb_conf") for new samba mode. void write_smb_conf() { struct dirent *dp; FILE *fp; DIR *dir_to_open=NULL; int n=0, sh_num=0; char *tmp1=NULL; char SHMAX[32]; char SMB_SHNAME[64]; char SHNM[16]; char SMB_SHCOMMENT[64]; char SHCM[16]; char SMB_SHPATH[104]; char SHPH[32]; char SHAU[16]; char SMB_SHRRIGHT[384]; char SHRR[384]; char SMB_SHWRIGHT[384]; char SHWR[384]; char SMB_SHACCUSER[384]; // write smb.conf if((fp=fopen("/tmp/samba/lib/smb.conf", "r"))) { fclose(fp); //eval("rm", "-f", "/tmp/samba/lib/smb.conf"); unlink("/tmp/samba/lib/smb.conf"); // 2008.08 James. } fp = fopen("/tmp/samba/lib/smb.conf", "w"); fprintf(fp, "[global]\n"); if(nvram_safe_get("st_samba_workgroup")) fprintf(fp, "workgroup = %s\n", nvram_safe_get("st_samba_workgroup")); if(nvram_safe_get("computer_name")) fprintf(fp, "netbios name = %s\n", nvram_safe_get("computer_name")); fprintf(fp, "server string = WL500g.Premium version 2\n"); eval("mkdir", "-p", "/tmp/var/log/samba"); fprintf(fp, "log file = /tmp/var/log/samba/samba.log\n"); fprintf(fp, "log level = 0\n"); fprintf(fp, "max log size = 5\n"); // share mode if(!strcmp(nvram_safe_get("st_samba_modex"), "1")) { fprintf(fp, "security = SHARE\n"); fprintf(fp, "guest ok = yes\n"); fprintf(fp, "guest only = yes\n"); } else { fprintf(fp, "security = USER\n"); fprintf(fp, "guest ok = no\n"); fprintf(fp, "map to guest = Bad User\n"); } fprintf(fp, "writeable = yes\n"); fprintf(fp, "directory mode = 0777\n"); fprintf(fp, "create mask = 0777\n"); // max users sprintf(SHMAX, "st_max_user"); if(strcmp(nvram_safe_get(SHMAX), "")!=0) fprintf(fp, "max connections = %s\n", nvram_safe_get(SHMAX)); fprintf(fp, "encrypt passwords = yes\n"); fprintf(fp, "pam password change = no\n"); fprintf(fp, "obey pam restrictions = no\n"); fprintf(fp, "socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=16384 SO_SNDBUF=16384\n"); fprintf(fp, "dns proxy = no\n"); // share if(!strcmp(nvram_safe_get("st_samba_modex"), "0") || !strcmp(nvram_safe_get("st_samba_modex"), "")) { ; } else if(!strcmp(nvram_safe_get("st_samba_modex"), "1")) { printf("samba mode: share\n"); if(!(dir_to_open = opendir("/tmp/harddisk"))) { perror("***cannot open /tmp/harddisk\n"); goto confpage; } n = 0; if(dir_to_open) { while(dp=readdir(dir_to_open)) { if(strncmp(dp->d_name, "..", NAME_MAX) != 0 && strncmp(dp->d_name, ".", NAME_MAX) != 0 ) { sprintf(SMB_SHNAME, "%s", dp->d_name); sprintf(SMB_SHCOMMENT, "%s", dp->d_name); sprintf(SMB_SHPATH, "/tmp/harddisk/%s", dp->d_name); printf("%s\n", SMB_SHPATH); fprintf(fp, "[%s]\n", SMB_SHNAME); fprintf(fp, "comment = %s\n", SMB_SHCOMMENT); fprintf(fp, "path = %s\n", SMB_SHPATH); fprintf(fp, "guest ok = yes\n"); fprintf(fp, "writeable = yes\n"); fprintf(fp, "directory mode = 0777\n"); fprintf(fp, "create mask = 0777\n"); } } } if(dir_to_open) closedir(dir_to_open); } else // st_samba_mode = 2 { printf("samba mode: user\n"); n = 0; sh_num = atoi(nvram_safe_get("sh_num")); while(n (double)512 ) return 2; else return 3; } int check_disk_free_apps(char *diskpath, int ac_flag) // added by Jiahao for WL500gP { struct statfs fsbuf; if(statfs(diskpath, &fsbuf)) { perror("*** check_disk_free_apps: statfs fail!"); return 0; } if (ac_flag==1) { if (nvram_match("apps_dlx", "0")) return 1; if ( (double)((double)((double)fsbuf.f_bfree * fsbuf.f_bsize)/(1024*1024)) < (double)1 ) return 0; else return 1; } else { if ( (double)((double)((double)fsbuf.f_bfree * fsbuf.f_bsize)/(1024*1024)) < (double)5 ) return 0; else return 1; } } #endif // DLM void get_disc_desc(char * vendor_product, int discorder, int discindex) { // added by Jiahao for WL500gP FILE* fp; DIR *dir_to_open, *dir_to_open2; struct dirent *dp, *dp2; char str_path[128]; char temp[80]; char temp2[80]; char temp3[32]; char temp4[64]; char temp5[64]; char port[128]; char tempstr[1]; char host[128]; char *p, *p2; strcpy(vendor_product, ""); if( dir_to_open = opendir("/proc/scsi") ) { while(dp=readdir(dir_to_open)) { if( !strncmp(dp->d_name, "..", NAME_MAX) || !strncmp(dp->d_name, ".", NAME_MAX) || !strncmp(dp->d_name, "sg", NAME_MAX) || !strncmp(dp->d_name, "scsi", NAME_MAX) ) continue; sprintf(str_path, "/proc/scsi/%s", dp->d_name); if (dir_to_open2 = opendir(str_path)) { while(dp2=readdir(dir_to_open2)) { if( !strncmp(dp2->d_name, "..", NAME_MAX) || !strncmp(dp2->d_name, ".", NAME_MAX) ) continue; sprintf(temp3, "/dev/discs/disc%d", discorder); sprintf(temp5, "../scsi/host%s/bus0/target0/lun0", dp2->d_name); readlink(temp3, temp4, 64); if (strncmp(temp5, temp4, 13)!=0) break; else { if (fp=fopen("/proc/scsi/scsi", "r")) { while (fgets(temp,80,fp)!=NULL) { if (p=strstr(temp, "Host: scsi")) { p+=10; sprintf(host, p); memcpy(host+1, "\0", 1); continue; } if (p=strstr(temp, "Vendor: ")) { if(!strcmp(dp2->d_name, host)) { sprintf(vendor_product, p); p2=strstr(temp, "Rev: "); memcpy(vendor_product+strlen(p)-strlen(p2)-1, "\0", 1); break; } } } fclose(fp); } sprintf(str_path, "/proc/scsi/%s/%s", dp->d_name, dp2->d_name); if (fp=fopen(str_path, "r")) { while (fgets(temp,80,fp)!=NULL) { if (strstr(temp, "Port: ")) { if (p=strstr(temp, ": ")) { #ifdef DLM p+=4; //+2 for WL500GP +4 due to Port: 1.2 #else // DLM p+=2; #endif // DLM sprintf(port, p); memcpy(port+strlen(port)-1, "\0", 1); sprintf(temp2, "usb_disc%d_port", discindex); nvram_set(temp2, port); strcpy(tempstr, port); if (strcmp(tempstr, "1")==0) sprintf(port, "[USB Lower port]\n"); else sprintf(port, "[USB Upper port]\n"); } break; } } fclose(fp); strcat(port, vendor_product); strcpy(vendor_product, port); } else strcpy(vendor_product, ""); } } closedir(dir_to_open2); } } closedir(dir_to_open); } } void write_per_disc_status(int disc_index) { FILE *fp; char usb_disc_mount_path[128], usb_disc_fs_path[128]; int i, j; char *temp=(char *)malloc(128); char disc_dev_str[32]; char disc_idx_str[32]; int disc_order[2]; disc_order[0]=atoi(nvram_get("usb_disc0_dev")+14); disc_order[1]=atoi(nvram_get("usb_disc1_dev")+14); fp = fopen("/tmp/usstatus", "a"); if (fp) { sprintf(disc_dev_str, "usb_disc%d_dev", disc_index); sprintf(disc_idx_str, "usb_disc%d_index", disc_index); if (nvram_invmatch(disc_dev_str, "") && nvram_invmatch(disc_idx_str, "0")) { get_disc_desc(temp, disc_order[disc_index], disc_index); printf("%s\n", temp); fprintf(fp, "%s\n", temp); i=atoi(nvram_safe_get(disc_idx_str)); for(j=0; j= 1024*1024*2) buflen = 1024*1024*2; else if ((info.freeram + info.bufferram) >= 1024*1024*1.6) buflen = 1024*1024*1.6; else if ((info.freeram + info.bufferram) >= 1024*1024*1) buflen = 1024*1024*1; else if ((info.freeram + info.bufferram) >= 1024*1024*0.8) buflen = 1024*1024*0.8; else buflen = 1024*1024*0.5; buf = malloc(buflen); for(i=0;i 0) return 1; else return 0; } #endif // DLM int umount_disc_parts_rc(int usb_port) { char nvramstr[32]; char nvramstr2[32]; char nvramstr3[32]; char umount_dir[32]; int disc_index, i; char tmp[2]; int dev_index=-1; int count=0; char test_path[128], tmpstr[128]; int ret=0; #ifdef DLM int sleep_flag=0; //if ( strcmp(nvram_safe_get("usb_storage_busy"), "1" )==0 ) // 2007.12 James // return; #endif // DLM sprintf(tmp, "%d", usb_port); if(!strcmp(nvram_safe_get("usb_disc0_port"), tmp)) dev_index = 0; else if(!strcmp(nvram_safe_get("usb_disc1_port"), tmp)) dev_index = 1; else return -1; #ifdef DLM #if 1 if ( (strcmp(nvram_safe_get("apps_running"), "1")==0) && (atoi(nvram_safe_get("apps_dms_usb_port_x"))==usb_port) ) { sleep_flag=1; eval("killall", "snarf"); eval("killall", "ctorrent"); eval("killall", "rtorrent"); eval("killall", "giftd"); eval("killall", "dmathined"); //eval("killall", "dms"); //nvram_set("dms_running", "0"); // 2007.11 James. nvram_set("apps_running", "0"); nvram_set("apps_installed", "0"); nvram_set("apps_dl_x", "0"); nvram_set("apps_status_checked", "0"); nvram_set("apps_disk_free", "0"); /*nvram_set("usb_storage_busy2", "1"); sleep(5); nvram_set("usb_storage_busy2", "0");*/ } #endif // 1 if(!strcmp(nvram_safe_get("samba_running"), "1")){ eval("killall", "nmbd"); eval("killall", "smbd"); nvram_set("samba_running", "0"); nvram_set("st_samba_mode_x", "0"); } if(!strcmp(nvram_safe_get("ftp_running"), "1")){ eval("killall", "vsftpd"); nvram_set("ftp_running", "0"); } // 2007.11 James. { if(!strcmp(nvram_safe_get("dms_running"), "1")){ eval("killall", "dms"); nvram_set("dms_running", "0"); } // 2007.11 James. } if(sleep_flag == 1) { nvram_set("usb_storage_busy2", "1"); for(i = 1; i <= 2; ++i){ printf("Sleep %d second%s...\n", i, ((i == 1)?"":"s")); sleep(1); } nvram_set("usb_storage_busy2", "0"); } sync(); // 2008.06 James. if(!strcmp(nvram_safe_get("swap_on"), "1") && atoi(nvram_safe_get("apps_dms_usb_port_x2")) == usb_port) { strcpy(test_path, ""); if ( strcmp(nvram_safe_get("usb_disc0_port"), nvram_safe_get("apps_dms_usb_port_x2"))==0 ) { strcpy(test_path, nvram_safe_get("usb_disc0_path0")); } else if ( strcmp(nvram_safe_get("usb_disc1_port"), nvram_safe_get("apps_dms_usb_port_x2"))==0 ) { strcpy(test_path, nvram_safe_get("usb_disc1_path0")); } if(strcmp(test_path, "") != 0) { sprintf(tmpstr, "%s/.swap", test_path); printf("try to swapoff %s.\n", tmpstr); swapoff(tmpstr); //nvram_set("usb_storage_busy2", "1"); sleep(1); //nvram_set("usb_storage_busy2", "0"); if (swap_check()==1) { logmessage("USB storage", "swapoff unsuccessfully"); nvram_set("swapoff_failed", "1"); //unlink(tmpstr); return -1; } else { logmessage("USB storage", "swapoff successfully"); nvram_set("swap_on", "0"); nvram_set("swap_file", ""); // 2008.06 James. nvram_set("swapoff_failed", "0"); nvram_set("apps_dms_usb_port_x2", "-1"); unlink(tmpstr); } } } #endif // DLM sprintf(nvramstr, "usb_disc%d_index", dev_index); disc_index=atoi(nvram_safe_get(nvramstr)); for (i=disc_index; i>0; i--) { sprintf(nvramstr2, "usb_disc%d_path%d", dev_index, i-1); sprintf(umount_dir, nvram_safe_get(nvramstr2)); sprintf(nvramstr3, "usb_disc%d_fs_path%d", dev_index, i-1); count=0; //while((ret=umount(umount_dir)) && (count<2)) while((ret=umount2(umount_dir, MS_NOEXEC | MS_NOSUID | 0x00000002)) && (count<2)) // 0x00000002: MNT_DETACH { //sync(); // 2008.04 James. count++; #ifdef DLM nvram_set("usb_storage_busy2", "1"); #endif // DLM sleep(1); #ifdef DLM nvram_set("usb_storage_busy2", "0"); #endif // DLM } if(!ret) { rmdir(umount_dir); nvram_set(nvramstr3, ""); nvram_set(nvramstr2, ""); sprintf(tmp, "%d", i-1); nvram_set(nvramstr, tmp); sprintf(tmpstr, "unmounted %s", umount_dir); logmessage("USB storage", tmpstr); } else return ret; } sprintf(nvramstr, "usb_disc%d_dev", dev_index); nvram_set(nvramstr, ""); sprintf(nvramstr, "usb_disc%d_port", dev_index); nvram_set(nvramstr, "0"); #ifdef DLM nvram_set("eject_from_web", "1"); #endif // DLM write_disc_status(); return 0; } //2008.07.17 Yau add int start_networkmap(void) { char *networkmap_argv[] = {"networkmap", NULL}; pid_t pid; _eval(networkmap_argv, NULL, 0, &pid); return 0; } #ifdef CDMA int eject_cdrom(const char *dev_name){ int stopfd; csprintf("Stopping CD-ROM(%s) ...", dev_name); if((stopfd = open(dev_name, O_RDONLY|O_NONBLOCK, 0)) >= 0){ csprintf("there was a CD-ROM device!\n"); if(ioctl(stopfd, CDROMEJECT, 0)) csprintf("Ejecting CD-ROM failed %d\n", errno); else csprintf("Ejecting CD-ROM succeeded\n"); close(stopfd); return 1; } else{ csprintf("there wasn't any CD-ROM device!\n"); return 0; } } int stop_cdrom(const char *dev_name){ int stopfd; csprintf("Stopping CD-ROM(%s) ...", dev_name); if((stopfd = open(dev_name, O_RDONLY|O_NONBLOCK, 0)) >= 0){ csprintf("there was a CD-ROM device!\n"); if(ioctl(stopfd, CDROMSTOP, 0)) csprintf("Stopping CD-ROM failed %d\n", errno); else csprintf("Stopping CD-ROM succeeded\n"); close(stopfd); return 1; } else{ csprintf("there wasn't any CD-ROM device!\n"); return 0; } }//*/ int eject_scsi(const char *dev_name){ int ejectfd; int status; struct sdata { int inlen; int outlen; char cmd[256]; } scsi_cmd; csprintf("Ejecting SCSI(%s) of CDROM ...", dev_name); if((ejectfd = open(dev_name, O_RDONLY|O_NONBLOCK)) == -1){ logmessage("USB Storage", "this was not a CD-ROM device."); csprintf("there wasn't any CD-ROM device!\n"); return 0; } logmessage("USB Storage", "this was a CD-ROM device."); csprintf("there was a CD-ROM device!\n"); /*scsi_cmd.inlen = 0; scsi_cmd.outlen = 0; scsi_cmd.cmd[0] = ALLOW_MEDIUM_REMOVAL; scsi_cmd.cmd[1] = 0; scsi_cmd.cmd[2] = 0; scsi_cmd.cmd[3] = 0; scsi_cmd.cmd[4] = 0; scsi_cmd.cmd[5] = 0; status = ioctl(ejectfd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd); if (status != 0){ csprintf("Failed to send ALLOW_MEDIUM_REMOVAL!\n"); close(ejectfd); return 0; }//*/ scsi_cmd.inlen = 0; scsi_cmd.outlen = 0; scsi_cmd.cmd[0] = START_STOP; scsi_cmd.cmd[1] = 0; scsi_cmd.cmd[2] = 0; scsi_cmd.cmd[3] = 0; scsi_cmd.cmd[4] = 1; scsi_cmd.cmd[5] = 0; status = ioctl(ejectfd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd); if (status != 0){ csprintf("Failed to send first START_STOP!\n"); close(ejectfd); return 0; } scsi_cmd.inlen = 0; scsi_cmd.outlen = 0; scsi_cmd.cmd[0] = START_STOP; scsi_cmd.cmd[1] = 0; scsi_cmd.cmd[2] = 0; scsi_cmd.cmd[3] = 0; scsi_cmd.cmd[4] = 2; scsi_cmd.cmd[5] = 0; status = ioctl(ejectfd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd); if (status != 0){ csprintf("Failed to send second START_STOP!\n"); close(ejectfd); return 0; } /* force kernel to reread partition table when new disc inserted */ /*status = ioctl(ejectfd, BLKRRPART); if (status != 0){ csprintf("Failed to send BLKRRPART!\n"); }//*/ close(ejectfd); return 1; } #endif // CDMA #endif // ASUS_EXT