Exemple #1
0
void checknas(void)		// for broadcom v24 only
{
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)

	char buf[32];
	FILE *fnas = fopen("/tmp/.nas", "r");

	if (fnas == NULL)
		return;

	fgets(buf, sizeof(buf), fnas);
	fclose(fnas);

	if (strlen(buf) != count_processes("nas"))	// restart all nas
		// processes
	{
		sysprintf("stopservice nas");
		sysprintf("startservice_f nas");
	}

	return;

#endif
#ifdef HAVE_MADWIFI
	sysprintf("startservice_f checkhostapd");
#endif
}
Exemple #2
0
int do_mon(void)
{
	struct mon *v;

	checkupgrade();
	checknas();
#ifndef HAVE_RT2880
	softcontrol_wlan_led();
#endif
	for (v = mons; v < &mons[sizeof(mons) / sizeof(struct mon)]; v++) {
		if (v->name == NULL)
			break;
		if (v->nvvalue && v->nvmatch) {
			if (!nvram_match(v->nvvalue, v->nvmatch))
				continue;	// service not enabled. no need to check
		}
		printf("checking %s\n", v->name);

		if (v->type == M_WAN)
			if (!check_wan_link(0)) {
				printf("process is wan, but wan is not up\n");
				continue;
			}
		if (!search_process(v->name, v->count)) {

			printf("Maybe %s had died, we need to re-exec it\n", v->name);
			sysprintf("stopservice %s", v->name);
			killall(v->name, SIGKILL);
			sysprintf("startservice_f %s", v->name);
		}
		printf("checking for %s done\n", v->name);
	}

	return 1;
}
Exemple #3
0
int archreader_open(carchreader *ai)
{   
    struct stat64 st;
    char volhead[64];
    int magiclen;
    
    assert(ai);
    
    // on the archive volume
    ai->archfd=open64(ai->volpath, O_RDONLY|O_LARGEFILE);
    if (ai->archfd<0)
    {   sysprintf ("cannot open archive %s\n", ai->volpath);
        return -1;
    }
    
    // check the archive volume is a regular file
    if (fstat64(ai->archfd, &st)!=0)
    {   sysprintf("fstat64(%s) failed\n", ai->volpath);
        return -1;
    }
    if (!S_ISREG(st.st_mode))
    {   errprintf("%s is not a regular file, cannot continue\n", ai->volpath);
        close(ai->archfd);
        return -1;
    }
    
    // read file format version and rewind to beginning of the volume
    if (read(ai->archfd, volhead, sizeof(volhead))!=sizeof(volhead))
    {   sysprintf("cannot read magic from %s\n", ai->volpath);
        close(ai->archfd);
        return -1;
    }
    if (lseek64(ai->archfd, 0, SEEK_SET)!=0)
    {   sysprintf("cannot rewind volume %s\n", ai->volpath);
        close(ai->archfd);
        return -1;
    }
    
    // interpret magic an get file format version
    magiclen=strlen(FSA_FILEFORMAT);
    if ((memcmp(volhead+40, "FsArCh_001", magiclen)==0) || (memcmp(volhead+40, "FsArCh_00Y", magiclen)==0))
    {
        ai->filefmtver=1;
    }
    else if (memcmp(volhead+42, "FsArCh_002", magiclen)==0)
    {
        ai->filefmtver=2;
    }
    else
    {
        errprintf("%s is not a supported fsarchiver file format\n", ai->volpath);
        close(ai->archfd);
        return -1;
    }
    
    msgprintf(MSG_VERB2, "Detected fileformat=%d in archive %s\n", (int)ai->filefmtver, ai->volpath);
    
    return 0;
}
Exemple #4
0
static void setEthLED(int gpio, char *eth)
{
	sysprintf("echo netdev > /sys/class/leds/generic_%d/trigger", gpio);
	sysprintf("echo %s > /sys/class/leds/generic_%d/device_name", eth,
		  gpio);
	sysprintf("echo \"link tx rx\" > /sys/class/leds/generic_%d/mode",
		  gpio);
}
Exemple #5
0
int main(int argc, char *argv[]) {

	//define qapplication class
	QApplication app(argc, argv);

	//make string variable
	char str[STRLEN];

	//make file object
	FILE *file;

	//quit if it is not the only Yellowcot instance
	memset(str, 0, STRLEN);
	sprintf(str, "%s", TMPDIR);
	if ((file = fopen(str, "r"))) {
		memset(str, 0, STRLEN);
		sprintf(str, "Multiple, simultaneous instances of Yellowcot is not yet a supported feature. If you are certain another instance is not running, you may execute \"sudo rm -r %s\".", TMPDIR);
		QMessageBox::critical(0, QString("Fatal Error"), QString(str));
		return 1;
		fclose (file);
	}

	//create temporary directory for yellowcot quiz
	sysprintf("mkdir %s", TMPDIR);

	//create config file if it doesn't already exist
	sysprintf("cp ~/.yellowcot/config %s/config > /dev/null 2>&1", TMPDIR);
	memset(str, 0, STRLEN);
	sprintf(str, "%s/config", TMPDIR);
	if ((file = fopen(str, "r"))) {
		fclose(file);
		remove(str);
	}
	else {
		sysprintf("echo -e \"# Yellowcot configuration file\n#\n# If you'd like to use a font other than the default, specify\n# its path (e.g. /usr/local/share/fonts/c/code2000.ttf) here.\n#font=\n# Specify the font size here.\nfontsize=24\" > %s/config", TMPDIR);
		sysprintf("mkdir ~/.yellowcot");
		sysprintf("mv %s/config ~/.yellowcot/config", TMPDIR);
	}

	//start translator
	QTranslator translator;
	translator.load(QString("yellowcot_") + QLocale::system().name());
	app.installTranslator(&translator);

	//create and show main window
	MainWindow mainWindow;
	mainWindow.show();

	//delete temporary file when yellowcot is about to quit
	QObject::connect(&app, SIGNAL(aboutToQuit()), &mainWindow, SLOT(removeTempFiles()));

	//pass control to qt
	return app.exec();
}
Exemple #6
0
void start_powersafe(void)
{
	if (nvram_match("powersave", "1")) {
		dd_syslog(LOG_INFO, "powersave : Ondemand CPUFrequency scaler Enabled\n");
		sysprintf("echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor");
	} else {
		dd_syslog(LOG_INFO, "powersave : Performance CPUFrequency scaler Enabled\n");
		sysprintf("echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor");
	}
	return;
}
Exemple #7
0
void start_hwmon(void)
{
	int temp_max = atoi(nvram_safe_get("hwmon_temp_max")) * TEMP_MUL;
	int temp_hyst = atoi(nvram_safe_get("hwmon_temp_hyst")) * TEMP_MUL;

	sysprintf("/bin/echo %d > %s/%s_max", temp_max, TEMP_PATH, TEMP_PREFIX);
	sysprintf("/bin/echo %d > %s/%s_max_hyst", temp_hyst, TEMP_PATH, TEMP_PREFIX);
#ifdef TEMP2_PATH
	sysprintf("/bin/echo %d > %s/%s_max", temp_max, TEMP2_PATH, TEMP2_PREFIX);
	sysprintf("/bin/echo %d > %s/%s_max_hyst", temp_hyst, TEMP2_PATH, TEMP2_PREFIX);
#endif
	dd_syslog(LOG_INFO, "hwmon successfully started\n");
}
Exemple #8
0
void addpppoetime_main(int argc, char *argv[])
{
	static int lock = 0;

	while (lock) {
		usleep(100);
	}

	lock = 1;
	sysprintf("grep -v %s /tmp/pppoe_peer.db > /tmp/pppoe_peer.db.tmp", argv[1]);
	sysprintf("mv /tmp/pppoe_peer.db.tmp /tmp/pppoe_peer.db");
	sysprintf("echo \"%s\t\t%s\t\t%s\t\t%s\" >> /tmp/pppoe_peer.db", argv[2], argv[3], argv[4], argv[1]);
	lock = 0;
}
Exemple #9
0
void start_privoxy(void)
{
	if (!nvram_match("privoxy_enable", "1"))
		return;

	int mode = 0;
	char *ip = nvram_safe_get("lan_ipaddr");

	sysprintf("grep -q nobody /etc/passwd || echo \"nobody:*:65534:65534:nobody:/var:/bin/false\" >> /etc/passwd");
	mkdir("/var/log/privoxy", 0777);
	
	char *wan = get_wan_ipaddr();
	if (nvram_match("privoxy_transp_enable", "1")) {
		sysprintf("iptables -t nat -D PREROUTING -p tcp -d ! %s --dport 80 -j REDIRECT --to-port 8118", wan);
		sysprintf("iptables -t nat -I PREROUTING -p tcp -d ! %s --dport 80 -j REDIRECT --to-port 8118", wan);
		mode = 1;
	}

	FILE *fp = fopen("/tmp/privoxy.conf", "wb");

	if (nvram_match("privoxy_advanced", "1") && nvram_invmatch("privoxy_conf", "")) {
		fprintf(fp, "%s", nvram_safe_get("privoxy_conf"));
	} else {
		fprintf(fp, "confdir /etc/privoxy\n"
			"logdir /var/log/privoxy\n"
			"actionsfile match-all.action\n"
			"actionsfile default.action\n"
			"actionsfile user.action\n"
			"filterfile default.filter\n"
			"logfile logfile\n"
			"listen-address  %s:8118\n"
			"toggle  1\n"
			"enable-remote-toggle  0\n"
			"enable-remote-http-toggle  0\n"
			"enable-edit-actions 0\n"
			"buffer-limit 4096\n"
			"accept-intercepted-requests %d\n" 
			"split-large-forms 0\n" 
			"keep-alive-timeout 5\n" 
			"socket-timeout 300\n" 
			"max-client-connections 64\n" 
			"handle-as-empty-doc-returns-ok 1\n", ip, mode);
	}
	fclose(fp);
	eval("privoxy", "/tmp/privoxy.conf");
	syslog(LOG_INFO, "Privoxy : privoxy started\n");
	return;
}
Exemple #10
0
void start_radius(char *prefix)
{

	// wrt-radauth $IFNAME $server $port $share $override $mackey $maxun &

	if (nvram_nmatch("1", "%s_radauth", prefix)
	    && nvram_nmatch("ap", "%s_mode", prefix)) {
		char *server = nvram_nget("%s_radius_ipaddr", prefix);
		char *port = nvram_nget("%s_radius_port", prefix);
		char *share = nvram_nget("%s_radius_key", prefix);
		char *ifname = nvram_nget("%s_ifname", prefix);
		char type[32];

		sprintf(type, "%s_radmactype", prefix);
		char *pragma = "";

		if (nvram_default_match(type, "0", "0"))
			pragma = "-n1 ";
		if (nvram_match(type, "1"))
			pragma = "-n2 ";
		if (nvram_match(type, "2"))
			pragma = "-n3 ";
		if (nvram_match(type, "3"))
			pragma = "";
		sleep(1);	// some delay is usefull
		sysprintf("wrt-radauth %s %s %s %s %s %s %s %s &", pragma,
			  ifname, server, port, share, nvram_nget("%s_radius_override", prefix), nvram_nget("%s_radmacpassword", prefix), nvram_nget("%s_max_unauth_users", prefix));
	}

}
Exemple #11
0
int openMonitorSocket(char *dev)
{
	//Open the socket
	struct ifreq ifr;
	struct sockaddr_ll addr;
	int s;
	sysprintf("ifconfig %s up", dev);
	s = socket(PF_PACKET, SOCK_RAW, 0);
	memset(&ifr, 0, sizeof(ifr));
	strcpy(ifr.ifr_name, dev);
	if (ioctl(s, SIOCGIFINDEX, &ifr) != 0) {
		printf("ioctl IFINDEX failed!!!\n");
		return -1;
	}
	close(s);

	s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
	memset(&addr, 0, sizeof(addr));
	addr.sll_family = AF_PACKET;
	addr.sll_ifindex = ifr.ifr_ifindex;
	addr.sll_protocol = 0;
	if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		printf("bind failed!!! (%s)\n", dev);
		return -1;
	}

	return s;
}
Exemple #12
0
int br_add_bridge(const char *brname)
{
    dd_syslog(LOG_INFO, "bridge added successfully\n");
    char ipaddr[32];
    char brmcast[32];

    sprintf(brmcast, "%s_mcast", brname);
    sprintf(ipaddr, "%s_ipaddr", brname);
    char netmask[32];

    sprintf(netmask, "%s_netmask", brname);
    int ret = eval("brctl", "addbr", brname);

#ifdef HAVE_80211AC
    eval("emf", "add", "bridge", brname);
    eval("igs", "add", "bridge", brname);
#endif

    if (nvram_get(ipaddr) && nvram_get(netmask)
            && !nvram_match(ipaddr, "0.0.0.0")
            && !nvram_match(netmask, "0.0.0.0")) {
        eval("ifconfig", brname, nvram_safe_get(ipaddr), "netmask", nvram_safe_get(netmask), "mtu", getBridgeMTU(brname), "up");
    } else
        eval("ifconfig", brname, "mtu", getBridgeMTU(brname));

    char *mcast = nvram_default_get(brmcast, "0");
    sysprintf("echo %s > /sys/devices/virtual/net/%s/bridge/multicast_snooping", mcast, brname);
    return ret;
}
Exemple #13
0
void delpppoeconnected_main(int argc, char *argv[])
{
	static int lock = 0;

	while (lock) {
		usleep(100);
	}

	lock = 1;
	sysprintf("grep -v %s /tmp/pppoe_connected > /tmp/pppoe_connected.tmp", argv[1]);
	sysprintf("mv /tmp/pppoe_connected.tmp /tmp/pppoe_connected -f");
	//      just an uptime test
	sysprintf("grep -v %s /tmp/pppoe_uptime > /tmp/pppoe_uptime.tmp", argv[2]);
	sysprintf("mv /tmp/pppoe_uptime.tmp /tmp/pppoe_uptime -f");
	lock = 0;

}
Exemple #14
0
static void makeipup(void)
{
	FILE *fp = fopen("/tmp/pppoeserver/ip-up.sh", "w");

	fprintf(fp, "#!/bin/sh\n");
	if (nvram_match("filter", "on"))	// only needed if firewall is enabled
		fprintf(fp, "iptables -I INPUT -i $1 -j ACCEPT\n");
//      if (nvram_match("pppoeserver_clip", "local")) //for radius ip's...to be worked on
	if (nvram_match("wan_proto", "pppoe")	//only when there is an ppp0 interface
	    || nvram_match("wan_proto", "pptp") || nvram_match("wan_proto", "pppoe_dual"))
		fprintf(fp, "iptables -I FORWARD -i $1 -j ACCEPT\n" "iptables -I FORWARD -o $1 -j ACCEPT\n");
	fprintf(fp, "addpppoeconnected $PPPD_PID $1 $5 $PEERNAME\n"
		//"echo \"$PPPD_PID\t$1\t$5\t`date +%%s`\t0\t$PEERNAME\" >> /tmp/pppoe_connected\n"
		//      just an uptime test
		//"echo \"`date +%%s`\t$PEERNAME\" >> /tmp/pppoe_uptime\n"      //
		//->use something like $(( ($(date +%s) - $(date -d "$dates" +%s)) / (60*60*24*31) )) for computing uptime in the gui
	    );
	//      per peer shaping
	if (nvram_match("pppoeradius_enabled", "1")) {
		fprintf(fp, "IN=`grep -i RP-Upstream-Speed-Limit /var/run/radattr.$1 | awk '{print $2}'`\n" "OUT=`grep -i RP-Downstream-Speed-Limit /var/run/radattr.$1 | awk '{print $2}'`\n" "if [ ! -z $IN ] && [ $IN -gt 0 ]\n" "then tc qdisc del dev $1 ingress\n" "\t tc qdisc add dev $1 handle ffff: ingress\n" "\t tc filter add dev $1 parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate \"$IN\"kbit burst \"$IN\"kbit drop flowid :1\n" "fi\n" "if [ ! -z $OUT ] && [ $OUT -gt 0 ]\n"	//only if Speed limit !0 and !empty
			"then	tc qdisc del root dev $1\n" "\t tc qdisc add dev $1 root tbf rate \"$OUT\"kbit latency 50ms burst \"$OUT\"kbit\n" "fi\n");
	}
//tc qdisc add dev $1 root red min 150KB max 450KB limit 600KB burst 200 avpkt 1000 probability 0.02 bandwidth 100Mbit
//eg: tc qdisc add dev $1 root red min 150KB max 450KB limit 600KB burst 200 avpkt 1000 probability 0.02 bandwidth 10Mbit
//burst = (min+min+max)/(3*avpkt); limit = minimum: max+burst or x*max, max = 2*min
	fclose(fp);
	fp = fopen("/tmp/pppoeserver/ip-down.sh", "w");
	fprintf(fp, "#!/bin/sh\n" "delpppoeconnected $PPPD_PID $PEERNAME\n"
		//      calc connected time and volume per peer
		"CONTIME=`grep $PEERNAME /tmp/pppoe_peer.db | awk '{print $1}'`\n"
		"SENT=`grep $PEERNAME /tmp/pppoe_peer.db | awk '{print $2}'`\n"
		"RCVD=`grep $PEERNAME /tmp/pppoe_peer.db | awk '{print $3}'`\n"
		"CONTIME=$(($CONTIME+$CONNECT_TIME))\n" "SENT=$(($SENT+$BYTES_SENT))\n" "RCVD=$(($RCVD+$BYTES_RCVD))\n" "addpppoetime $PEERNAME $CONTIME $SENT $RCVD\n");
	if (nvram_match("wan_proto", "pppoe")
	    || nvram_match("wan_proto", "pptp") || nvram_match("wan_proto", "pppoe_dual"))
		fprintf(fp, "iptables -D FORWARD -i $1 -j ACCEPT\n" "iptables -D FORWARD -o $1 -j ACCEPT\n");
	if (nvram_match("filter", "on"))	// only needed if firewall is enabled
		fprintf(fp, "iptables -D INPUT -i $1 -j ACCEPT\n");
	if (nvram_match("pppoeradius_enabled", "1"))
		fprintf(fp, "tc qdisc del root dev $1\n" "tc qdisc del dev $1 ingress\n");
	fclose(fp);

	chmod("/tmp/pppoeserver/ip-up.sh", 0700);
	chmod("/tmp/pppoeserver/ip-down.sh", 0700);

	//      copy existing peer data to /tmp
	if ((nvram_match("usb_enable", "1")
	     && nvram_match("usb_storage", "1")
	     && nvram_match("usb_automnt", "1")
	     && nvram_match("usb_mntpoint", "jffs"))
	    || (nvram_match("enable_jffs2", "1")
		&& nvram_match("jffs_mounted", "1")
		&& nvram_match("sys_enable_jffs2", "1")))
		mkdir("/jffs/etc", 0700);
		mkdir("/jffs/etc/pppoeserver", 0700);
		sysprintf("/bin/cp /jffs/etc/pppoeserver/pppoe_peer.db /tmp/");
}
Exemple #15
0
void setMacFilter(char *iface)
{
	char *next;
	char var[32];
	char nvvar[32];

	sysprintf("iwpriv %s set ACLClearAll=1", getRADev(iface));
	sysprintf("iwpriv %s set AccessPolicy=0", getRADev(iface));

	sprintf(nvvar, "%s_macmode", iface);
	if (nvram_match(nvvar, "deny")) {
		sysprintf("iwpriv %s set AccessPolicy=2", getRADev(iface));
		char nvlist[32];

		sprintf(nvlist, "%s_maclist", iface);

		foreach(var, nvram_safe_get(nvlist), next) {
			sysprintf("iwpriv %s set ACLAddEntry=%s", getRADev(iface), var);
		}
Exemple #16
0
int archwriter_write_buffer(carchwriter *ai, struct s_writebuf *wb)
{
    struct statvfs64 statvfsbuf;
    char textbuf[128];
    long lres;
    
    assert(ai);
    assert(wb);

    if (wb->size == 0)
    {   errprintf("wb->size=%ld\n", (long)wb->size);
        return -1;
    }

    if ((lres=write(ai->archfd, (char*)wb->data, (long)wb->size))!=(long)wb->size)
    {
        errprintf("write(size=%ld) returned %ld\n", (long)wb->size, (long)lres);
        if ((lres>0) && (lres < (long)wb->size)) // probably "no space left"
        {
            if (fstatvfs64(ai->archfd, &statvfsbuf)!=0)
            {   sysprintf("fstatvfs(fd=%d) failed\n", ai->archfd);
                return -1;
            }
            
            u64 freebytes = statvfsbuf.f_bfree * statvfsbuf.f_bsize;
            errprintf("Can't write to the archive file. Space on device is %s. \n"
                "If the archive is being written to a FAT filesystem, you may have reached \n"
                "the maximum filesize that it can handle (in general 2 GB)\n", 
                format_size(freebytes, textbuf, sizeof(textbuf), 'h'));
             werte_uebergeben (109,4);     
            return -1;
        }
        else // another error
        {
            sysprintf("write(size=%ld) failed\n", (long)wb->size);
            return -1;
        }
    }
    
    return 0;
}
Exemple #17
0
void addpppoeconnected_main(int argc, char *argv[])
{
	static int lock = 0;

	while (lock) {
		usleep(100);
	}

	lock = 1;
	sysprintf("echo \"%s\t%s\t%s\t%s\" >> /tmp/pppoe_connected", argv[1], argv[2], argv[3], argv[4]);
	lock = 0;
}
Exemple #18
0
/**
  * @brief  Read phone book and print on console
  * @param  Phone book record number
  * @return None
  */
void read_phoneBook(uint32_t cnt)
{

    int i, j, k;

    for(i = 1; i < cnt + 1; i++) {
        au8ReadRec[2] = (uint8_t)i;
        if(SCLIB_StartTransmission(0, au8ReadRec, 5, buf, &len) != SCLIB_SUCCESS) {
            sysprintf("Command Read Record failed\n");
            break;
        }
        if(buf[0] == 0xFF) // This is an empty entry
            continue;
        sysprintf("\n======== %d ========", i);
        sysprintf("\nName: ");
        for(j = 0; buf[j] != 0xFF; j++) {
            sysprintf("%c", buf[j]);
        }
        while(buf[j] == 0xFF)   // Skip reset of the Alpha Identifier bytes
            j++;

        sysprintf("\nNumber: ");
        j += 2; // Skip Length of BCD and TNO/NPI
        for(k = 0; k < 10; k++) {
            if((buf[j + k] & 0xf) != 0xF)
                sysprintf("%c", (buf[j + k] & 0xf) + 0x30);
            else
                break;

            if((buf[j + k] >> 4) != 0xF)
                sysprintf("%c", (buf[j + k] >> 4) + 0x30);
            else
                break;
        }
    }
Exemple #19
0
void start_gen_radius_cert(void)
{
	if (nvram_match("cert_running", "1") && pidof("openssl") > 0)
		return;		//already running
	prep();
	gen_cert("/jffs/etc/freeradius/certs/server.cnf", TYPE_SERVER, nvram_safe_get("radius_common"), nvram_safe_get("radius_passphrase"));
	gen_cert("/jffs/etc/freeradius/certs/ca.cnf", TYPE_CA, nvram_safe_get("radius_common"), nvram_safe_get("radius_passphrase"));
	nvram_set("cert_running", "1");
	//this takes a long time (depending from the cpu speed)
	system("cd /jffs/etc/freeradius/certs && ./bootstrap");
	sysprintf("sed \"s/private_key_password = whatever/private_key_password = %s/g\" /etc/freeradius/eap.conf > /jffs/etc/freeradius/eap.conf", nvram_safe_get("radius_passphrase"));
	nvram_set("cert_running", "0");
}
Exemple #20
0
int archreader_read_data(carchreader *ai, void *data, u64 size)
{
    long lres;
    
    assert(ai);

    if ((lres=read(ai->archfd, (char*)data, (long)size))!=(long)size)
    {   sysprintf("read failed: read(size=%ld)=%ld\n", (long)size, lres);
        return -1;
    }
    
    return 0;
}
Exemple #21
0
/**
  * @brief  Send verify command to verify CHV1
  * @param  Remaining retry count, valid values are between 3~1
  * @return Unlock SIM card success or not
  * @retval 0 Unlock success
  * @retval -1 Unlock failed
  */
int unlock_sim(uint32_t u32RetryCnt)
{
    while(u32RetryCnt > 0) {

        get_pin(); // Ask user input PIN

        if(SCLIB_StartTransmission(0, au8VerifyChv, 13, buf, &len) != SCLIB_SUCCESS) {
            sysprintf("Command Verify CHV failed\n");
            break;
        }
        if(buf[0] == 0x90 || buf[1] == 0x00) {
            sysprintf("Pass\n");
            return 0;
        } else {
            u32RetryCnt--;
            sysprintf("Failed, remaining retry count: %d\n", u32RetryCnt);
        }
    }

    sysprintf("Oops, SIM card locked\n");

    return -1;
}
Exemple #22
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
	sysInitializeUART();
    sysprintf("\n");
    sysprintf("=========================\n");
    sysprintf("     NUC970 USB VCOM     \n");
    sysprintf("=========================\n");

	sysDisableCache();
	sysInvalidCache();
	sysSetMMUMappingMethod(MMU_DIRECT_MAPPING);
	sysEnableCache(CACHE_WRITE_BACK);

    sysInstallISR(HIGH_LEVEL_SENSITIVE|IRQ_LEVEL_1, USBD_IRQn, (PVOID)USBD_IRQHandler);
    /* enable CPSR I bit */
    sysSetLocalInterrupt(ENABLE_IRQ);

    USBD_Open(&gsInfo, VCOM_ClassRequest, NULL);

    /* Endpoint configuration */
    VCOM_Init();

	sysEnableInterrupt(USBD_IRQn);

    /* Start transaction */
    while(1) {
        if (USBD_IS_ATTACHED()) {
            USBD_Start();
            break;
        }
    }

    while(1) {
        VCOM_TransferData();
    }
}
Exemple #23
0
/**
  * @brief  Ask user to input PIN from console
  * @param  None
  * @return None
  * @details Valid input characters (0~9) are echo to console and store in command buffer.
  *         Backspace key can delete previous input digit, ESC key delete all input digits.
  *         Valid PIN length is between 4~8 digits. If PIN length is shorter than 8
  *         digits, an Enter key can terminate the input procedure.
  */
void get_pin(void)
{
    int i = 0;
    char c = 0;

    sysprintf("Please input PIN number:");
    while(i < 8) {
        c = sysGetChar();
        if(c >= 0x30 && c <= 0x39) {    // Valid input characters (0~9)
            au8VerifyChv[5 + i] = c;
            sysprintf("%c", c);
            i++;
        } else if(c == 0x7F) {// DEL (Back space)
            i--;
            sysprintf("%c", c);
        } else if(c == 0x0D) { // Enter
            if(i >= 4)  //Min CHV length is 4 digits
                break;
        } else if(c == 0x1B) {//ESC
            sysprintf("\nPlease input PIN number:");
            i = 0;  // retry
        } else {
            continue;
        }

    }

    // Fill remaining digits with 0xFF
    for(; i < 8; i++) {
        au8VerifyChv[5 + i] = 0xFF;
    }

    sysprintf("\n");

    return;
}
Exemple #24
0
void SD_Open_(unsigned int cardSel)
{
    switch(cardSel & 0xff)
    {
        case SD_PORT0:
            SD_Open(cardSel);
            if (SD_Probe(cardSel & 0x00ff) != TRUE) {
                sysprintf("SD0 initial fail!!\n");
                return;
            }
            f_mount(&_FatfsVolSd0, _Path, 1);
            break;

        case SD_PORT1:
            SD_Open(cardSel);
            if (SD_Probe(cardSel & 0x00ff) != TRUE) {
                sysprintf("SD1 initial fail!!\n");
                return;
            }
            _Path[0] = 	1 + '0';	
            f_mount(&_FatfsVolSd1, _Path, 1);
            break;
    }
}
Exemple #25
0
void runStartup(char *folder, char *extension)
{
	struct dirent *entry;
	DIR *directory;

	directory = opendir(folder);
	if (directory == NULL) {
		return;
	}
	// list all files in this directory 
	while ((entry = readdir(directory)) != NULL) {
		if (endswith(entry->d_name, extension)) {
			sysprintf("%s/%s&\n", folder, entry->d_name);
		}
	}
	closedir(directory);
}
Exemple #26
0
int main(int argc, char **argv)
{
	/* 
	 * Run it in the background 
	 */
	switch (fork()) {
	case -1:
		// can't fork
		exit(0);
		break;
	case 0:
		/* 
		 * child process 
		 */
		// fork ok
		(void)setsid();
		break;
	default:
		/* 
		 * parent process should just die 
		 */
		_exit(0);
	}
	int timeout = atoi(argv[1]);
	while (timeout) {
		FILE *fp = fopen("/tmp/.wpsdone", "rb");
		if (fp) {
			killall("ledtool", SIGKILL);
			nvram_set("wps_status", "1");
			nvram_commit();
			sysprintf("rm -f /tmp/.wpsdone");
			fclose(fp);
			led_control(LED_SES, LED_ON);
			break;
		}
		timeout--;
		sleep(1);
	}
	if (!timeout) {
		killall("ledtool", SIGKILL);
		nvram_set("wps_status", "1");
		nvram_commit();
		system("ledtool 1800 3");
	}
	return 0;
}				// end main
Exemple #27
0
void start_change_mac(void)
{
	int i;
	FILE *fp;
	unsigned char os[32];
	char mtdpath[32];

	int mtd = getMTD("boot");

	sprintf(mtdpath, "/dev/mtdblock/%d", mtd);
	fp = fopen(mtdpath, "rb");
      nexttry:;
	fprintf(stdout,
		"MAC Invalid. Please enter new MAC Address: (format xx:xx:xx:xx:xx:xx)\n-->");
	char maddr[64];

	fscanf(stdin, "%s", maddr);
	int newmac[6];
	int ret = sscanf(maddr, "%02x:%02x:%02x:%02x:%02x:%02x", &newmac[0],
			 &newmac[1], &newmac[2], &newmac[3], &newmac[4],
			 &newmac[5]);
	if (ret != 6) {
		fprintf(stdout, "\ninvalid format!, try again\n");
		goto nexttry;
	}
	//valid;
	for (i = 0; i < 6; i++)
		sprintf(os, "%02x%02x%02x%02x%02x%02x", newmac[0] & 0xff,
			newmac[1] & 0xff, newmac[2] & 0xff, newmac[3] & 0xff,
			newmac[4] & 0xff, newmac[5] & 0xff);
	fprintf(stderr, "new mac will be %s\n", os);
	FILE *tmp = fopen("/tmp/boot.bin", "w+b");

	fseek(fp, 0, SEEK_SET);
	for (i = 0; i < 65536; i++)
		putc(getc(fp), tmp);
	fseek(tmp, 0xff82, SEEK_SET);
	for (i = 0; i < 12; i++)
		putc(os[i], tmp);
	fclose(tmp);
	sysprintf("mtd -f write /tmp/boot.bin boot");
	fclose(fp);

}
Exemple #28
0
int logfile_open()
{
    char logpath[PATH_MAX];
    char timestamp[1024];
    char *logdir="/var/log";  
    
    format_time(timestamp, sizeof(timestamp), time(NULL));
    snprintf(logpath, sizeof(logpath), "%s/fsarchiver_%s_%ld.log", logdir, timestamp, (long)getpid());
    mkdir_recursive(logdir);
    
    g_logfile=open64(logpath, O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
    if (g_logfile>=0)
    {   msgprintf(MSG_VERB1, "Creating logfile in %s\n", logpath);
        msgprintf(MSG_VERB1, "Running fsarchiver version=[%s], fileformat=[%s]\n", FSA_VERSION, FSA_FILEFORMAT);
        return FSAERR_SUCCESS;
    }
    else
    {   sysprintf("Cannot create logfile in %s\n", logpath);
        return FSAERR_UNKNOWN;
    }
}
Exemple #29
0
void set_gpio(int pin, int value)
{
	int fd;
	switch (pin) {
	case 16:		// main LED
		sysprintf
		    ("echo %d > /sys/devices/platform/leds-gpio/leds/user1/brightness",
		     value);
		break;
	default:
		if ((fd = open("/dev/misc/gpio", O_RDWR)) < 0) {
			printf("Error whilst opening /dev/gpio\n");
			return;
		}
		ioctl(fd, GPIO_DIR_OUT, pin);
		if (value)
			ioctl(fd, GPIO_SET, pin);
		else
			ioctl(fd, GPIO_CLEAR, pin);
		close(fd);
		break;
	}
}
Exemple #30
0
void start_sysinit(void)
{
	char buf[PATH_MAX];
	struct stat tmp_stat;
	time_t tm = 0;

	mknod("/dev/mmc", S_IFBLK | 0660, makedev(126, 0));
	mknod("/dev/mmc0", S_IFBLK | 0660, makedev(126, 1));
	mknod("/dev/mmc1", S_IFBLK | 0660, makedev(126, 2));
	mknod("/dev/mmc2", S_IFBLK | 0660, makedev(126, 3));
	mknod("/dev/mmc3", S_IFBLK | 0660, makedev(126, 4));
	mknod("/dev/gpio", S_IFCHR | 0644, makedev(252, 0));

	/*
	 * Setup console 
	 */

	cprintf("sysinit() klogctl\n");
	klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
	cprintf("sysinit() get router\n");

	/*
	 * load some netfilter stuff 
	 */

//    eval( "watchdog" );
	/*
	 * Set a sane date 
	 */

	stime(&tm);
	nvram_set("wl0_ifname", "ra0");
	insmod("rt2860v2_ap");
	insmod("RTPCI_ap");
	insmod("raeth");
#ifdef HAVE_WHR300HP2
	insmod("rt2880_wdt");


	FILE *in = fopen("/dev/mtdblock/2", "rb");
	unsigned char mac[32];
	if (in != NULL) {
		fseek(in, 4, SEEK_SET);
		fread(mac, 6, 1, in);
		fclose(in);
		unsigned int copy[6];
		int i;
		for (i = 0; i < 6; i++)
			copy[i] = mac[i] & 0xff;
		sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]);
		fprintf(stderr,"configure mac address to %s\n",mac);
		if (!strcmp(mac, "ff:ff:ff:ff:ff:ff"))
			eval("ifconfig", "eth0", "hw", "ether", "00:11:22:33:44:55");
		else
			eval("ifconfig", "eth0", "hw", "ether", mac);
	}

/*	system("swconfig dev eth0 set reset 1");
	system("swconfig dev eth0 set enable_vlan 1");
	system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 6t\"");
	system("swconfig dev eth0 vlan 2 set ports \"4 6t\"");
	system("swconfig dev eth0 set apply");*/
	
	//LAN/WAN ports as security mode
	sysprintf("switch reg w 2004 ff0003");
	sysprintf("switch reg w 2104 ff0003");
	sysprintf("switch reg w 2204 ff0003");
	sysprintf("switch reg w 2304 ff0003");
	sysprintf("switch reg w 2404 ff0003");
	sysprintf("switch reg w 2504 ff0003");
	//LAN/WAN ports as transparent port
	sysprintf("switch reg w 2010 810000c0");
	sysprintf("switch reg w 2110 810000c0");
	sysprintf("switch reg w 2210 810000c0");
	sysprintf("switch reg w 2310 810000c0");	
	sysprintf("switch reg w 2410 810000c0");
	sysprintf("switch reg w 2510 810000c0");
	//set CPU/P7 port as user port
	sysprintf("switch reg w 2610 81000000");
	sysprintf("switch reg w 2710 81000000");

	sysprintf("switch reg w 2604 20ff0003");// #port6, Egress VLAN Tag Attribution=tagged
	sysprintf("switch reg w 2704 20ff0003");// #port7, Egress VLAN Tag Attribution=tagged
	

	sysprintf("switch reg w 2014 10001");
	sysprintf("switch reg w 2114 10001");
	sysprintf("switch reg w 2214 10001");
	sysprintf("switch reg w 2314 10001");
	sysprintf("switch reg w 2414 10002");
	sysprintf("switch reg w 2514 10001");
	//VLAN member port
	sysprintf("switch vlan set 0 1 11110111");
	sysprintf("switch vlan set 1 2 00001011");
	sysprintf("switch clear");
	eval("ifconfig", "eth0", "up");
	
	eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
	eval("vconfig", "add", "eth0", "1");	//LAN
	eval("vconfig", "add", "eth0", "2");	//WAN

	struct ifreq ifr;
	int s;

	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
		char eabuf[32];

		strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
		ioctl(s, SIOCGIFHWADDR, &ifr);
		nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		close(s);
	}

#else

#if defined(HAVE_DIR600) && !defined(HAVE_ALL02310N)
	writeproc("/proc/rt3052/mii/ctrl", "write 0 0 0x3300");
	writeproc("/proc/rt3052/mii/ctrl", "write 1 0 0x3300");
	writeproc("/proc/rt3052/mii/ctrl", "write 2 0 0x3300");
	writeproc("/proc/rt3052/mii/ctrl", "write 3 0 0x3300");
#endif
#if defined(HAVE_RT10N) || defined(HAVE_F5D8235) || defined(HAVE_RT15N) || defined(HAVE_WCRGN) && !defined(HAVE_HAMEA15)
	FILE *in = fopen("/dev/mtdblock/2", "rb");
	unsigned char mac[32];
	if (in != NULL) {
		fseek(in, 4, SEEK_SET);
		fread(mac, 6, 1, in);
		fclose(in);
		unsigned int copy[6];
		int i;
		for (i = 0; i < 6; i++)
			copy[i] = mac[i] & 0xff;
		sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]);
		if (!strcmp(mac, "ff:ff:ff:ff:ff:ff"))
			eval("ifconfig", "eth2", "hw", "ether", "00:11:22:33:44:55");
		else
			eval("ifconfig", "eth2", "hw", "ether", mac);
	}
#endif
#ifdef HAVE_HAMEA15
	FILE *in = fopen("/dev/mtdblock/1", "rb");
	if (in != NULL) {
		unsigned char *config = malloc(65536);
		memset(config, 0, 65536);
		fread(config, 65536, 1, in);
		int len = strlen("WAN_MAC_ADDR=");
		int i;
		for (i = 0; i < 65535 - (len + 18); i++) {
			if (!strncmp(&config[i], "WAN_MAC_ADDR=", len)) {
				char *mac = &config[i + len];
				if (mac[0] == '"')
					mac++;
				mac[17] = 0;
				eval("ifconfig", "eth2", "hw", "ether", mac);
				nvram_set("et0macaddr_safe", mac);
				nvram_set("et0macaddr", mac);
				break;
			}
		}
		free(config);
		fclose(in);
	}
#endif
#if (defined(HAVE_DIR600) || defined(HAVE_AR670W) || defined(HAVE_EAP9550) || defined(HAVE_AR690W)) && !defined(HAVE_ALL02310N)

	FILE *in = fopen("/dev/mtdblock/1", "rb");
	if (in != NULL) {
		unsigned char *config = malloc(65536);
		memset(config, 0, 65536);
		fread(config, 65536, 1, in);
#if defined(HAVE_AR670W) || defined(HAVE_AR690W)
		int len = strlen("lanmac=");
#else
		int len = strlen("ethaddr=");
#endif
		int i;
		for (i = 0; i < 65535 - (18 + len); i++) {
#if defined(HAVE_AR670W) || defined(HAVE_AR690W)
			if (!strncmp(&config[i], "lanmac=", 7))
#else
			if (!strncmp(&config[i], "ethaddr=", 8))
#endif
			{
				char *mac = &config[i + len];
				if (mac[0] == '"')
					mac++;
				mac[17] = 0;
				eval("ifconfig", "eth2", "hw", "ether", mac);
				nvram_set("et0macaddr_safe", mac);
				nvram_set("et0macaddr", mac);
				break;
			}
		}
		free(config);
		fclose(in);
	}
#endif

	/* switch config */
	if (getRouterBrand() != ROUTER_BOARD_ECB9750 && getRouterBrand() != ROUTER_BOARD_TECHNAXX3G)	// lets load
	{
		eval("ifconfig", "eth2", "up");
#ifndef HAVE_EAP9550
		eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
		eval("vconfig", "add", "eth2", "1");	//LAN 

		eval("vconfig", "add", "eth2", "2");	//WAN
#ifdef HAVE_RT10N
		MAC_ADD(mac);
		eval("ifconfig", "vlan2", "hw", "ether", mac);
#endif
#endif

#if defined(HAVE_ALLNET11N) || defined(HAVE_ESR6650) || defined(HAVE_WR5422) || defined(HAVE_RT10N) || \
    defined(HAVE_ACXNR22) || defined(HAVE_W502U) || defined(HAVE_ESR9752) || defined(HAVE_ALL02310N)
		sysprintf("switch reg w 14 405555");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f3f");
		sysprintf("switch reg w e4 3f");
		sysprintf("switch reg w 40 1002");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1001");
		sysprintf("switch reg w 70 ffff417e");
#ifdef HAVE_ESR9752
		sysprintf("switch reg w c8 3f502b28");
#endif
#elif HAVE_AR670W
		sysprintf("mii_mgr -s -p 29 -r 23 -v 0x07c2");
		sysprintf("mii_mgr -s -p 29 -r 22 -v 0x8420");

		sysprintf("mii_mgr -s -p 29 -r 24 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 25 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 26 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 27 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 28 -v 0x2");
		sysprintf("mii_mgr -s -p 30 -r 9 -v 0x1089");
		sysprintf("mii_mgr -s -p 30 -r 1 -v 0x2f00");
		sysprintf("mii_mgr -s -p 30 -r 2 -v 0x0030");
#elif HAVE_AR690W
#elif HAVE_RT15N
#elif HAVE_BR6574N
#elif HAVE_F5D8235
		sysprintf("switch reg w 14 405555");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f40");
		sysprintf("switch reg w e4 20");
		sysprintf("switch reg w 40 1001");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1001");
		sysprintf("switch reg w 4c 1");
		sysprintf("switch reg w 70 ffffffff");
#elif HAVE_EAP9550
		sysprintf("switch reg w 14 5555");
		sysprintf("switch reg w 40 1001");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1001");
		sysprintf("switch reg w 4c 1");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 70 ffffffff");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f7f");
		sysprintf("switch reg w e4 7f");
#else
		sysprintf("switch reg w 14 405555");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f3f");
		sysprintf("switch reg w e4 3f");
		sysprintf("switch reg w 40 1001");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1002");
		sysprintf("switch reg w 70 ffff506f");
#endif
	}

	struct ifreq ifr;
	int s;

	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
		char eabuf[32];

		strncpy(ifr.ifr_name, "eth2", IFNAMSIZ);
		ioctl(s, SIOCGIFHWADDR, &ifr);
		nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		close(s);
	}
#endif
	led_control(LED_POWER, LED_ON);
	led_control(LED_SES, LED_OFF);
	led_control(LED_SES2, LED_OFF);
	led_control(LED_DIAG, LED_OFF);
	led_control(LED_BRIDGE, LED_OFF);
	led_control(LED_WLAN0, LED_OFF);
	led_control(LED_WLAN1, LED_OFF);
	led_control(LED_CONNECTED, LED_OFF);
#ifdef HAVE_WCRGN
	set_gpio(0,1);
	set_gpio(10,1);
#endif

	if (!nvram_match("disable_watchdog", "1")) {
		eval("watchdog");
	}
	return;
}