int handle_kamailioSIPProxyAuthMethod(netsnmp_mib_handler *handler,
	netsnmp_handler_registration *reginfo,
	netsnmp_agent_request_info   *reqinfo,
	netsnmp_request_info         *requests)
{

	/* The result needs to be returned as an SNMP bit field. */
	unsigned int auth_bitfield = SIP_AUTH_METHOD_NONE;
	
	if (module_loaded("tls")) {
		auth_bitfield |=  SIP_AUTH_METHOD_TLS;
		auth_bitfield &= ~SIP_AUTH_METHOD_NONE;
	}
	
	/* We can have both tls and auth loaded simultaneously.  Therefore we
	 * use an if instead of a else/else-if. */
	if (module_loaded("auth")) {
		auth_bitfield |= SIP_AUTH_METHOD_DIGEST;
		auth_bitfield &= ~SIP_AUTH_METHOD_NONE;
	}

	if (reqinfo->mode==MODE_GET) {
		snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
			(u_char *) &auth_bitfield, 1);
		return SNMP_ERR_NOERROR;
	}

	return SNMP_ERR_GENERR;
}
int handle_kamailioSIPProxyStatefulness(netsnmp_mib_handler *handler,
	netsnmp_handler_registration *reginfo,
	netsnmp_agent_request_info   *reqinfo,
	netsnmp_request_info         *requests)
{
	int statefullness;

	if (module_loaded("dialog") || module_loaded("dialog_ng")) 
	{
		statefullness = PROXY_STATEFULNESS_CALL_STATEFUL;
	}
	else if (module_loaded("tm"))
	{
		statefullness = PROXY_STATEFULNESS_TRANSACTION_STATEFUL;
	}
	else
	{
		statefullness = PROXY_STATEFULNESS_STATELESS;
	}

	if (reqinfo->mode==MODE_GET) {
		snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
			(u_char *) &statefullness, sizeof(int));
		return SNMP_ERR_NOERROR;
	}

	return SNMP_ERR_GENERR;
}
Esempio n. 3
0
static void
load_module(void)
{
	FILE *fp;
	char line[8192];
	//若没有加载则调用system执行modprobe flashcache加载模块
	if (!module_loaded()) {
		if (verbose)
			fprintf(stderr, "Loading Flashcache Module\n");
		system("modprobe flashcache");
		if (!module_loaded()) {
			fprintf(stderr, "Could not load Flashcache Module\n");
			exit(1);
		}
	} else if (verbose)//verbose表示是否显示详细信息
			fprintf(stderr, "Flashcache Module already loaded\n");
	fp = fopen("/proc/flashcache/flashcache_version", "ro");
	fgets(line, 8190, fp);
	if (fgets(line, 8190, fp)) {
		if (verbose)
			fprintf(stderr, "version string \"%s\"\n", line);
#ifdef COMMIT_REV
		if (!strstr(line, COMMIT_REV)) {
			fprintf(stderr, "Flashcache revision doesn't match tool revision.\n");
			exit(1);
		}
#endif
	}
	fclose(fp);
}
Esempio n. 4
0
/*
 * Initialize the module system by loading the Symbols.dylib module.
 * Once loaded, locate the _lookup_symbol function so that internal
 * symbols can be resolved.
 */
int init_module_system()
{
    // Start any modules that were compiled in first.
    start_built_in_modules();
    
    
	int retVal = 0;
	void (*module_start)(void) = NULL;
	char* module_data = symbols_module_start + BOOT2_ADDR;
    
	// Intialize module system
	if(symbols_module_start != (void*)0xFFFFFFFF)
	{
		// Module system  was compiled in (Symbols.dylib addr known)
		module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
		
		if(module_start && module_start != (void*)0xFFFFFFFF)
		{
			// Notify the system that it was laoded
			module_loaded(SYMBOLS_MODULE, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
			
			(*module_start)();	// Start the module. This will point to load_all_modules due to the way the dylib was constructed.
			execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);
			DBG("Module %s Loaded.\n", SYMBOLS_MODULE);
			retVal = 1;

		}
		else
		{
            module_data -= 0x10;    // XCODE 4 HACK
            module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
            
            if(module_start && module_start != (void*)0xFFFFFFFF)
            {
                // Notify the system that it was laoded
                module_loaded(SYMBOLS_MODULE, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
                
                (*module_start)();	// Start the module. This will point to load_all_modules due to the way the dylib was constructed.
                execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);
                DBG("Module %s Loaded.\n", SYMBOLS_MODULE);
                retVal = 1;
                
            }
            else
            {
                // The module does not have a valid start function
                printf("Unable to start %s\n", SYMBOLS_MODULE); getchar();
            }		
		}		
	}
	return retVal;
}
/* Initializes the kamailioSIPMethodSupportedTable, and populates the tables 
 * contents */
void init_kamailioSIPMethodSupportedTable(void)
{
	initialize_table_kamailioSIPMethodSupportedTable();

	/* Tables is defined as follows:
	 *
	 * 	1)  METHOD_INVITE
	 *  	2)  METHOD_CANCEL
	 *	3)  METHOD_ACK
	 *	4)  METHOD_BYE
	 *	5)  METHOD_INFO
	 *	6)  METHOD_OPTIONS
	 *	7)  METHOD_UPDATE
	 *	8)  METHOD_REGISTER
	 *	9)  METHOD_MESSAGE
	 *	10) METHOD_SUBSCRIBE
	 *	11) METHOD_NOTIFY
	 *	12) METHOD_PRACK
	 *	13) METHOD_REFER
	 *	14) METHOD_PUBLISH
	 *
	 * We should keep these indices fixed.  For example if we don't support
	 * METHOD_REGISTER but we do support METHOD_MESSAGE, then METHOD_MESSAGE
	 * should still be at index 9.  
	 *
	 * NOTE: My way of checking what METHODS we support is probably wrong.
	 * Please feel free to correct it! */
	
	createRow(1, "METHOD_INVITE");
	createRow(2, "METHOD_CANCEL");
	createRow(3, "METHOD_ACK");
	createRow(4, "METHOD_BYE");

	if (module_loaded("options") || module_loaded("siputils")) {
		createRow(6, "METHOD_OPTIONS");
	}

	createRow(7, "METHOD_UPDATE");

	if (module_loaded("registrar")) {
		createRow(8, "METHOD_REGISTER");
		createRow(10, "METHOD_SUBSCRIBE");
		createRow(11, "METHOD_NOTIFY");
	}

	createRow(5,  "METHOD_INFO");
	createRow(9,  "METHOD_MESSAGE");
	createRow(12, "METHOD_PRACK");
	createRow(13, "METHOD_REFER");
	createRow(14, "METHOD_PUBLISH");
}
int handle_kamailioNetConfOutbound(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
	int value = 0;	/* Not implemented */
	unsigned int type;
	
	if (module_loaded("outbound")) {
		value = snmp_cfg_get_int("outbound", "outbound_enabled", &type);
		if (type != CFG_VAR_INT) {
			value = 0;
		}
	}

	switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int));
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfOutbound\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
	}

	return SNMP_ERR_NOERROR;
}
int handle_kamailioNetConfTcpTlsTransport(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    int value = 0;

#ifdef USE_TCP
	if (!tcp_disable) {
#ifdef USE_TLS
		if (module_loaded("tls")) {
			value = 1;
		}
#endif
		;	/* Empty statement needed here */
	}
#endif

    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int));
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfTcpTlsTransport\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
Esempio n. 8
0
// only ralink solution can reload it dynamically
void reinit_hwnat()
{
	// only happened when hwnat=1
	// only loaded when unloaded, and unloaded when loaded
	// in restart_firewall for fw_pt_l2tp/fw_pt_ipsec
	// in restart_qos for qos_enable
	// in restart_wireless for wlx_mrate_x
	
	if (nvram_get_int("hwnat")) {
		if (is_nat_enabled() && !nvram_get_int("qos_enable") /*&&*/
			/* TODO: consider RTCONFIG_DUALWAN case */
//			!nvram_match("wan0_proto", "l2tp") &&
//			!nvram_match("wan0_proto", "pptp") &&
			/*(nvram_match("wl0_radio", "0") || !nvram_get_int("wl0_mrate_x")) &&
			(nvram_match("wl1_radio", "0") || !nvram_get_int("wl1_mrate_x"))*/) {

#if !defined(RTCONFIG_DUALWAN)
#if defined(RTN65U) || defined(RTN56U)
			char primary[] = "wan1_primaryXXXXXX";

			sprintf(primary, "wan%d_primary", WAN_UNIT_SECOND);
			if (nvram_match(primary, "1")) {
				_dprintf("%s: don't install hardware NAT driver if 3G is enabled!\n", __func__);
				return;
			}
#endif
#endif

			if (!module_loaded("hw_nat")) {
#if 0
				system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
				system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
				modprobe("hw_nat");
				sleep(1);
			}
		}	
		else if (module_loaded("hw_nat")) {
			modprobe_r("hw_nat");
			sleep(1);
#if 0
			system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
			system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
		}
	}
}
Esempio n. 9
0
static void
load_module(void)
{
	FILE *fp;
	char line[8192];
	int found = 0;

	if (module_loaded()) {
		if (verbose)
			fprintf(stderr, "Flashcache Module already loaded\n");		
		return;
	}
	if (verbose)
		fprintf(stderr, "Loading Flashcache Module\n");
	system("modprobe flashcache_wt");
	if (!module_loaded()) {
		fprintf(stderr, "Could not load Flashcache Module\n");
		exit(1);
	}
}
Esempio n. 10
0
void start_built_in_module(const char* name, 
                           const char* author, 
                           const char* description,
                           UInt32 version,
                           UInt32 compat,
                           void(*start_function)(void))
{
    start_function();
    // Notify the module system that this module really exists, specificaly, let other module link with it
    module_loaded(name, author, description, version, compat);
}
Esempio n. 11
0
void init_wl(void)
{
	if (!module_loaded("rt2860v2_ap"))
		modprobe("rt2860v2_ap");
#if defined (RTCONFIG_WLMODULE_RT3090_AP)
	if (!module_loaded("RTPCI_ap"))
	{
		modprobe("RTPCI_ap");
	}
#endif
#if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII)
	if (!module_loaded("iNIC_mii"))
		modprobe("iNIC_mii", "mode=ap", "bridge=1", "miimaster=eth2", "syncmiimac=0");	// set iNIC mac address from eeprom need insmod with "syncmiimac=0"
#endif
#if defined (RTCONFIG_WLMODULE_MT7610_AP)
	if (!module_loaded("MT7610_ap"))
		modprobe("MT7610_ap");
#endif

	sleep(1);
}
Esempio n. 12
0
/*
 * Load a module file in /Extra/modules/
 */
int load_module(char* module)
{
	int retVal = 1;
	void (*module_start)(void) = NULL;
	char modString[128];
	int fh = -1;

	// Check to see if the module has already been loaded
	if(is_module_loaded(module))
	{
		DBG("Module '%s' already loaded.\n", module);
		return 1;
	}

	snprintf(modString, sizeof(modString), MODULE_PATH "%s", module);
	fh = open(modString, 0);
	if(fh < 0)
	{
		DBG("[WARNING!] Unable to locate module '%s'. Not loaded.\n", modString);
		DBGPAUSE();
		return 0;
	}
	unsigned int moduleSize = file_size(fh);

	if(moduleSize == 0)
	{
		DBG("[WARNING!] The module '%s' has a file size=%d. Not loading.\n", modString, moduleSize);
		return 0;
	}

	char* module_base = (char*) malloc(moduleSize);
	if (moduleSize && read(fh, module_base, moduleSize) == moduleSize)
	{
		// Module loaded into memory, parse it
		module_start = parse_mach(module_base, &load_module, &add_symbol, NULL);

		if(module_start && module_start != (void*)0xFFFFFFFF)
		{
			// Notify the system that it was laoded
			module_loaded(module, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
			(*module_start)();	// Start the module
			DBG("Module %s Loaded.\n", module);
			DBGPAUSE();
		}
#if CONFIG_MODULE_DEBUG
		else // The module does not have a valid start function. This may be a library.
		{
			printf("[WARNING!] Unable to start module '%s'.\n", module);
			getchar();
		}
#else
		else msglog("[WARNING!] Unable to start module '%s'.\n", module);
Esempio n. 13
0
void fini_wl(void)
{
	if (module_loaded("hw_nat"))
		modprobe_r("hw_nat");

#if defined (RTCONFIG_WLMODULE_MT7610_AP)
	if (module_loaded("MT7610_ap"))
		modprobe_r("MT7610_ap");
#endif
#if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII)
	if (module_loaded("iNIC_mii"))
		modprobe_r("iNIC_mii");
#endif

#if defined (RTCONFIG_WLMODULE_RT3090_AP)
	if (module_loaded("RTPCI_ap"))
	{
		modprobe_r("RTPCI_ap");
	}
#endif

	if (module_loaded("rt2860v2_ap"))
		modprobe_r("rt2860v2_ap");
}
Esempio n. 14
0
int handle_kamailioSIPProxyRecordRoute(netsnmp_mib_handler *handler,
		netsnmp_handler_registration *reginfo,
		netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests)
{
	/* If the rr module is loaded, then we support record route.  otherwise,
	 * we want to return 2, which is false for SNMP TruthValue. */
	int supportRecordRoute = TC_FALSE;

	if(module_loaded("rr")) {
		supportRecordRoute = TC_TRUE;
	}

	if(reqinfo->mode == MODE_GET) {
		snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
				(u_char *)&supportRecordRoute, sizeof(int));
		return SNMP_ERR_NOERROR;
	}

	return SNMP_ERR_GENERR;
}
Esempio n. 15
0
/**
 * init module function
 */
static int mod_init(void)
{
	if(msrp_sruid_init()<0) {
		LM_ERR("cannot init msrp uid\n");
		return -1;
	}

	if(msrp_cmap_init_rpc()<0)
	{
		LM_ERR("failed to register cmap RPC commands\n");
		return -1;
	}

	if(msrp_cmap_size>0) {
		if(msrp_cmap_size>16)
			msrp_cmap_size = 16;
		if(msrp_cmap_init(1<<msrp_cmap_size)<0) {
			LM_ERR("Cannot init internal cmap\n");
			return -1;
		}
		if(msrp_timer_interval<=0)
			msrp_timer_interval = 60;
		register_sync_timers(1);
	}

	sr_event_register_cb(SREV_TCP_MSRP_FRAME, msrp_frame_received);

	if(!module_loaded("tls")) {
		LM_WARN("\"tls\" module is not loaded. TLS is mandatory for"
			" MSRP Relays. To comply with RFC 4976 you must use"
			"  TLS.\n");
	} else {
		msrp_tls_module_loaded = 1;
	}

	return 0;
}
Esempio n. 16
0
int handle_kamailioNetConfStunServer(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    int value = 0;
    if (module_loaded("stun"))  {
	value = 1;
    }

    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int));
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfStunServer\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
Esempio n. 17
0
static int mod_init(void)
{
	if (sl_load_api(&ws_slb) != 0)
	{
		LM_ERR("binding to SL\n");
		goto error;
	}

	if (sr_event_register_cb(SREV_TCP_WS_FRAME_IN, ws_frame_receive) != 0)
	{
		LM_ERR("registering WebSocket receive call-back\n");
		goto error;
	}

	if (sr_event_register_cb(SREV_TCP_WS_FRAME_OUT, ws_frame_transmit) != 0)
	{
		LM_ERR("registering WebSocket transmit call-back\n");
		goto error;
	}

	if (register_module_stats(exports.name, stats) != 0)
	{
		LM_ERR("registering core statistics\n");
		goto error;
	}

	if (register_mi_mod(exports.name, mi_cmds) != 0)
	{
		LM_ERR("registering MI commands\n");
		goto error;
	}

	if (wsconn_init() < 0)
	{
		LM_ERR("initialising WebSocket connections table\n");
		goto error;
	}

	if (ws_ping_application_data.len < 1
		|| ws_ping_application_data.len > 125)
	{
		ws_ping_application_data.s = DEFAULT_PING_APPLICATION_DATA + 8;
		ws_ping_application_data.len =
					DEFAULT_PING_APPLICATION_DATA_LEN - 8;
	}

	if (ws_keepalive_mechanism != KEEPALIVE_MECHANISM_NONE)
	{
		if (ws_keepalive_timeout < 1 || ws_keepalive_timeout > 3600)
			ws_keepalive_timeout = DEFAULT_KEEPALIVE_TIMEOUT;

		switch(ws_keepalive_mechanism)
		{
		case KEEPALIVE_MECHANISM_PING:
		case KEEPALIVE_MECHANISM_PONG:
			break;
		default:
			ws_keepalive_mechanism = DEFAULT_KEEPALIVE_MECHANISM;
			break;
		}

		if (ws_keepalive_interval < 1 || ws_keepalive_interval > 60)
			ws_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;

		if (ws_keepalive_processes < 1 || ws_keepalive_processes > 16)
			ws_keepalive_processes = DEFAULT_KEEPALIVE_PROCESSES;

		/* Add extra process/timer for the keepalive process */
		register_sync_timers(ws_keepalive_processes);
	}

	if (ws_sub_protocols & SUB_PROTOCOL_MSRP
		&& !sr_event_enabled(SREV_TCP_MSRP_FRAME))
		ws_sub_protocols &= ~SUB_PROTOCOL_MSRP;

	if ((ws_sub_protocols & SUB_PROTOCOL_ALL) == 0)
	{
		LM_ERR("no sub-protocols enabled\n");
		goto error;
	}

	if ((ws_sub_protocols | SUB_PROTOCOL_ALL) != SUB_PROTOCOL_ALL)
	{
		LM_ERR("unrecognised sub-protocols enabled\n");
		goto error;
	}

	if (ws_cors_mode < 0 || ws_cors_mode > 2)
	{
		LM_ERR("bad value for cors_mode\n");
		goto error;
	}

	if (cfg_declare("websocket", ws_cfg_def, &default_ws_cfg,
			cfg_sizeof(websocket), &ws_cfg))
	{
		LM_ERR("declaring configuration\n");
		return -1;
	}
	cfg_get(websocket, ws_cfg, keepalive_timeout) = ws_keepalive_timeout;

	if (!module_loaded("xhttp"))
	{
		LM_ERR("\"xhttp\" must be loaded to use WebSocket.\n");
		return -1;
	}

	if (((ws_sub_protocols & SUB_PROTOCOL_SIP) == SUB_PROTOCOL_SIP)
			&& !module_loaded("nathelper")
			&& !module_loaded("outbound"))
	{
		LM_WARN("neither \"nathelper\" nor \"outbound\" modules are"
			" loaded. At least one of these is required for correct"
			" routing of SIP over WebSocket.\n");
	}

	return 0;

error:
	wsconn_destroy();
	return -1;
}
Esempio n. 18
0
int main() {
  pthread_t t;
  module_loaded();
  pthread_create(&t, (void*)0, module_activity, (void*)0);
  pthread_create(&t, (void*)0, module_activity, (void*)0);
}
Esempio n. 19
0
/*
 * Initialize the module system by loading the Symbols.dylib module.
 * Once loaded, locate the _lookup_symbol function so that internal
 * symbols can be resolved.
 */
int init_module_system()
{
	// Start any modules that were compiled in first.
	start_built_in_modules();


	int retVal = 0;
	void (*module_start)(void) = NULL;

	extern char  symbols_start  __asm("section$start$__DATA$__Symbols");
	char* module_data = &symbols_start;

	// Intialize module system
	if(module_data)
	{
		// Module system  was compiled in (Symbols.dylib addr known)
		module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);

		if(module_start && (module_start != (void*)0xFFFFFFFF))
		{
			// Notify the system that it was laoded
			module_loaded(SYMBOLS_MODULE, module_start, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
			(*module_start)();	// Start the module. This will point to load_all_modules due to the way the dylib was constructed.
			DBG("Module %s Loaded.\n", SYMBOLS_MODULE);
			retVal = 1;

		}
		else
		{
			// The module does not have a valid start function
			printf("Unable to start %s at 0x%x\n", SYMBOLS_MODULE, module_data);
			pause();
		}
	}

	// Look for modules located in the multiboot header.
	if(gMI && (gMI->mi_flags & MULTIBOOT_INFO_HAS_MODS))
	{
		if(gMI->mi_mods_count)
		{
			struct multiboot_module* mod = (struct multiboot_module*)gMI->mi_mods_addr;
			while(gMI->mi_mods_count--)
			{
				if(mod->mm_string)
				{
					// Convert string to module name, check for dylib.
					if(strcmp(&mod->mm_string[strlen(mod->mm_string) - sizeof("dylib")], ".dylib") == 0)
					{
						module_data = (char*)mod->mm_mod_start;

						char* last = strrchr(mod->mm_string, '/');
						if(last)
						{
							last++;
						}
						else
						{
							last = mod->mm_string;
						}

						char *name = strdup(last);
						name[strlen(last) - sizeof("dylib")] = 0;
						DBG("Loading multiboot module %s\n", name);

						module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);

						if(module_start && (module_start != (void*)0xFFFFFFFF))
						{
							// Notify the system that it was laoded
							module_loaded(name, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
							(*module_start)();	// Start the module
							DBG("Module %s Loaded.\n", name); DBGPAUSE();
						}
					}
				}
			}
		}
	}

	if(retVal) execute_hook("ModulesLoaded", NULL, NULL, NULL, NULL);

	return retVal;
}
Esempio n. 20
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 2) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on)
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "wan_port") == 0) {
			if(on) start_wan_port();
			else stop_wan_port();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#if ! (defined(RTCONFIG_QCA) || defined(RTCONFIG_RALINK))
		else if (strcmp(argv[1], "watchdog02") == 0) {
			if(on) start_watchdog02();
			else stop_watchdog02();
		}
#endif  /* ! (RTCONFIG_QCA || RTCONFIG_RALINK) */
		else if (strcmp(argv[1], "sw_devled") == 0) {
			if(on) start_sw_devled();
			else stop_sw_devled();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
#ifdef RTCONFIG_IPERF
		else if (strcmp(argv[1], "monitor") == 0) {
			if(on) start_monitor();
			else stop_monitor();
		}
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "0", 0, 0);
					f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "0", 0, 0);
#endif
				}
#endif
			add_iQosRules(get_wan_ifname(wan_primary_ifunit()));
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1) {
					start_dpi_engine_service();
					// force to rebuild firewall to avoid some loopback issue
					if (nvram_match("fw_nat_loopback", "2"))
						start_firewall(wan_primary_ifunit(), 0);
				}
				else
#endif
				start_iQos();
			}
			else
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
					/* TODO: consider RTCONFIG_DUALWAN case */
//					!nvram_match("wan0_proto", "l2tp") &&
//					!nvram_match("wan0_proto", "pptp") &&
//					!(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") &&
//					(nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) &&
//					(nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) &&
					!module_loaded("hw_nat"))
				{
#if 0
					f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "2", 0, 0);
					f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "2", 0, 0);
#endif

#if defined(RTN14U) || defined(RTAC52U) || defined(RTAC51U) || defined(RTN11P) || defined(RTN300) || defined(RTN54U) || defined(RTAC1200HP) || defined(RTN56UB1) || defined(RTAC54U) || defined(RTN56UB2)
					if (!(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", "")))
#endif
					{
						modprobe("hw_nat");
						sleep(1);
					}
				}
#endif
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1){
					stop_dpi_engine_service(1);
				}
				else
#endif
				stop_iQos();
				del_iQosRules();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
#ifdef RTCONFIG_TUNNEL
		else if (strcmp(argv[1], "mastiff") == 0) {
			if(on)
				start_mastiff();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			printf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "gpiod") == 0) {
			if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch();
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}
		else if (strcmp(argv[1], "pwr_usb") == 0) {
			set_pwr_usb(atoi(argv[2]));
			_dprintf("done.\n");
		}
		else if (strcmp(argv[1], "enc_chk") == 0) {
        		unsigned char enc_buf[ENC_WORDS_LEN];
        		unsigned char dec_buf[DATA_WORDS_LEN + 1];

			_dprintf("get enc str:[%s]\n", enc_str(argv[2], (char *) enc_buf));
			_dprintf("get dec str:[%s]\n", dec_str((char *) enc_buf, (char *) dec_buf));

			_dprintf("done(%d)\n", strcmp(argv[2], (const char *) dec_buf));
		}
#ifdef RTCONFIG_BCMFA
		else if (strcmp(argv[1], "fa_rev") == 0) {
			_dprintf("(%d) done.\n", get_fa_rev());
		}
		else if (strcmp(argv[1], "fa_dump") == 0) {
			_dprintf("(%d) done.\n", get_fa_dump());
		}
#endif
		else {
			printf("what?\n");
		}
	}
	return 0;
}
Esempio n. 21
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 3) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{	
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on) 
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
				}
#endif
				add_iQosRules(get_wan_ifname(0));
				start_iQos();
			}
			else 
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
					/* TODO: consider RTCONFIG_DUALWAN case */
//					!nvram_match("wan0_proto", "l2tp") &&
//					!nvram_match("wan0_proto", "pptp") &&
//					!(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") &&
//					(nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) &&
//					(nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) &&
					!module_loaded("hw_nat"))
				{
#if 0
					system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
					modprobe("hw_nat");
					sleep(1);
				}
#endif
				stop_iQos();
				del_iQosRules();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			_dprintf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "gpiod") == 0) {
			if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch(on);
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}
		else if (strcmp(argv[1], "pwr_usb") == 0) {
			set_pwr_usb(atoi(argv[2]));
			_dprintf("done.\n");
		}
		else {
			printf("what?\n");
		}
	}
	return 0;
}