Esempio n. 1
0
void serve_client(int fd, parameters_t *pars)
{
	sockprint(fd, "Enter 'h' for help\r\n");

	for(;;)
	{
		int key;

		if (sockprint(fd, "emergency console > ") == -1)
			break;

		if ((key = readchar(fd)) == -1)
			break;

		if (key < 32 || key > 126)
		{
			if (sockprint(fd, "\r") == -1)
				break;
			continue;
		}

		if (sockprint(fd, "%c\r\n", key) == -1)
			break;

		switch(key)
		{
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
				if (set_dmesg_loglevel(fd, key - '0') == -1)
					return;
				break;

			case 'd':
				if (dump_virtual_console(fd, pars -> vcsa0_fd) == -1)
					return;
				break;

			case '?':
			case 'h':
				if (ec_help(fd) == -1)
					return;
				break;

			case 'i':
				if (dump_loadavg(fd) == -1)
					return;
				break;

			case 'j':
				if (kill_one_proc(fd) == -1)
					return;
				break;

			case 'k':
				if (kill_procs(fd) == -1)
					return;
				break;

			case 'l':
				if (dump_dmesg(fd, pars -> dmesg_buffer, pars -> dmesg_buffer_size, 0) == -1)
					return;
				break;

			case 'm':
				if (dump_dmesg(fd, pars -> dmesg_buffer, pars -> dmesg_buffer_size, 1) == -1)
					return;
				break;

			case 'p':
				if (dump_ps(fd) == -1)
					return;
				break;

			case 'q':
				return;

			case 10:
			case 13:
				break;
			default:
				if (isupper(key))
					do_sysreq(fd, tolower(key), pars -> sysrq_fd);
				else
					sockprint(fd, "'%c' is not understood\r\n", key);
				break;
		}
	}
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	FILE *fp;
	int gpio_state=-1;
	int last_gpio_state=-1;
	int i;
#if !(defined(CONFIG_RTL865X_SC) && defined(CONFIG_RTL865X_AC) && defined(CONFIG_RTL8186_TR) && defined(CONFIG_RTL8196C_EC))
	struct ps_info ps;
	static int wlan_schl=0, ntp_enable=0, ntp_success=0;
#if defined(CONFIG_RTL865X_KLD)
	struct ps_info ps_va0, ps_eth;
	static int wlan_va0_schl=0, eth_port=0;
	pre_enable_state[0] = 1;
	for (i=1; i<WLAN_IF_TOTAL; i++)
		pre_enable_state[i] = 0;
#endif

	memset(&ps, '\0', sizeof(ps));
	if (argc > 2) {
		for (i=0; i<argc; i++) {
			if (!strcmp(argv[i], "-e")) {
				parse_schl(argv[i+1], &ps);
				dump_ps(&ps);
				wlan_schl = 1;
			}
#if defined(CONFIG_RTL865X_KLD)
			if (!strcmp(argv[i], "-f")) {
				parse_schl(argv[i+1], &ps_va0);
				dump_ps(&ps_va0);
				wlan_va0_schl = 1;
			}
			if (!strcmp(argv[i], "-g")) {
				parse_schl(argv[i+1], &ps_eth);
				dump_ps(&ps_eth);			
			}
			if (!strcmp(argv[i], "-p")) {
				sscanf(argv[i+1], "%d", &eth_port);	
			}			
#endif
		}
	}

#if !defined(CONFIG_RTL865X_AP)
	get_flash_int_value("NTP_ENABLED", &ntp_enable);
#endif
#endif

	while(1)
	{
		fp = fopen("/proc/load_default", "r");
		fscanf(fp, "%d", &i);
		if (i == 1) {
			printf("Going to Reload Default\n");
			system("flash reset");
			system("reboot");
		}
		fclose(fp);

#if !defined(CONFIG_RTL865X_SC) && !defined(CONFIG_RTL865X_AC) && !defined(CONFIG_RTL8186_TR) && !defined(CONFIG_RTL8196B) && !defined(CONFIG_RTL8196C_EC)
#if !defined(CONFIG_RTL865X_AP)
		if (ntp_enable) {
			if (!ntp_success) {
				fp = fopen("/etc/TZ", "r");
				if (fp) {
					fclose(fp);
					ntp_success = 1;
				}
			}
		}
#endif
		// enable wlan scheduling
		if (wlan_schl && (!ntp_enable || ntp_success))
			check_time_and_control_RF(&ps, WLAN_IF_ROOT, 0);
#if defined(CONFIG_RTL865X_KLD)
		if (wlan_va0_schl && (!ntp_enable || ntp_success))
			check_time_and_control_RF(&ps_va0, WLAN_IF_VA0, 0);
		else if (wlan_va0_schl && ntp_enable && !ntp_success)
			check_time_and_control_RF(&ps, WLAN_IF_VA0, 1);

		if (eth_port &&  (!ntp_enable || ntp_success)) {
			if (eth_port & 1)			
				check_time_and_control_eth(&ps_eth, ETH_IF_0, 0);
			if (eth_port & 2)			
				check_time_and_control_eth(&ps_eth, ETH_IF_2, 0);
			if (eth_port & 4)			
				check_time_and_control_eth(&ps_eth, ETH_IF_3, 0);			
			if (eth_port & 8)			
				check_time_and_control_eth(&ps_eth, ETH_IF_4, 0);
		}		
		else if (eth_port && ntp_enable && !ntp_success) {
			if (eth_port & 1)			
				check_time_and_control_eth(&ps_eth, ETH_IF_0, 1);
			if (eth_port & 2)			
				check_time_and_control_eth(&ps_eth, ETH_IF_2, 1);
			if (eth_port & 4)			
				check_time_and_control_eth(&ps_eth, ETH_IF_3, 1);			
			if (eth_port & 8)			
				check_time_and_control_eth(&ps_eth, ETH_IF_4, 1);		
		}		
#endif
#endif

#if defined(CONFIG_RTL8196B)
#if defined(CONFIG_RTL8196C) || defined(CONFIG_RTL8198)
		/* rtl8196C or rtl8198 do not need to check rf pin status*/
		gpio_state = 1;
		last_gpio_state =gpio_state; 
#else
		gpio_state = poll_rf_switch();
#endif		

		//printf("the gpio state =%d\n", gpio_state);
		if (last_gpio_state != gpio_state) {
			if (last_gpio_state == -1) {    // This is first state, we should check in advance for schedule, if the gpio is enabled
				if (gpio_state == 1) {
#if !defined(CONFIG_RTL865X_AP)
					if (ntp_enable) {
						if (!ntp_success) {
							fp = fopen("/etc/TZ", "r");
							if (fp) {
								fclose(fp);
								ntp_success = 1;
							}
						}
					}
#endif
					// enable wlan scheduling
					if (wlan_schl && (!ntp_enable || ntp_success))
						check_time_and_control_RF(&ps, WLAN_IF_ROOT, 0);
					else if (wlan_schl && ntp_enable && !ntp_success)
						check_time_and_control_RF(&ps, WLAN_IF_ROOT, 0);
				}
			}
			else {    // It is not first state, we get the result from gpio state
				if (gpio_state == 1) {    // gpio state is available for time schedule match
#if !defined(CONFIG_RTL865X_AP)
					if (ntp_enable) {
						if (!ntp_success) {
							fp = fopen("/etc/TZ", "r");
							if (fp) {
								fclose(fp);
								ntp_success = 1;
							}
						}
					}
#endif
					// enable wlan scheduling
					if (wlan_schl && (!ntp_enable || ntp_success))
						check_time_and_control_RF(&ps, WLAN_IF_ROOT, 0);
					else if (wlan_schl && ntp_enable && !ntp_success)
						check_time_and_control_RF(&ps, WLAN_IF_ROOT, 0);
					else
						enable_wlan();
				}
			}
			last_gpio_state = gpio_state;
		}
		else {
			if (gpio_state == 1) {
#if !defined(CONFIG_RTL865X_AP)
				if (ntp_enable) {
					if (!ntp_success) {
						fp = fopen("/etc/TZ", "r");
						if (fp) {
							fclose(fp);
							ntp_success = 1;
						}
					}
				}
#endif
				// enable wlan scheduling
				if (wlan_schl && (!ntp_enable || ntp_success))
					check_time_and_control_RF(&ps, WLAN_IF_ROOT, 0);
				else if (wlan_schl && ntp_enable && !ntp_success)
						check_time_and_control_RF(&ps, WLAN_IF_ROOT, 0);
			}
		}
#endif
		sleep(3);
	}
}