Beispiel #1
0
void load_interfaces(interface *inter)
{
  struct ifaddrs *addrs,*tmp;
  struct interface *buffor;
  getifaddrs(&addrs);
  tmp = addrs;
  while (tmp)
  {
    if((buffor=search_interface_name(inter,tmp->ifa_name)) != NULL)
    {
      set_interface(buffor,tmp);
    }
    else
    {
      if(strncmp(inter->name,"\0",1) == 0)
        set_interface(inter,tmp);
      else
      {
        buffor=search_interface_last(inter);
        buffor->next = malloc(sizeof(interface));
        memset_struct(buffor->next);
        set_interface(buffor->next,tmp);
      }
    }
    tmp = tmp->ifa_next;
  }
  freeifaddrs(addrs);
}
Beispiel #2
0
	StorageReal(CreatorInt& creat, IRef<eprovider::Storage> ifa, 
		Index ses) 
		: CreatureDefaultImplementation(creat)
	{
		set_interface(ifa,false,Monitor());
		session = ses;
	}
Beispiel #3
0
char MySniff::cfg_read_fname(char *file_name)
{
	if (this->status==TH_STARTED){
		this->stop();
	}
	
	if (this->status==TH_STOPPED){
		new_dev_clean();
		
		if (file_name==NULL){
			xlog_err(LEVEL2,parent,"Alert","Null file name");
			return -1;
		}	
		if (set_read_file(file_name) != 0){
			xlog_err(LEVEL2,parent,"Alert","Can't set read file name");
			return -1;
		}
		
		if (set_interface() < 0){
			xlog_err(LEVEL2,parent,"Alert","Can't read data from %s",file_name);
			return -1; 
		}
		
		settings = settings | XSNIFF_SETTING_IS_SET_INTERFACE;
		return 0;
	}else{
		xlog_err(LEVEL2,parent,"Alert","Can't stop thread, before starting a new one (in read)");
		return -1;		
	}	
	

	
}
static void msd()
{
#if 1
    unsigned InEndPt = 1;
    unsigned OutEndPt = 1;
#else
    unsigned InEndPt = 1;
    unsigned OutEndPt = 2;
#endif
    unsigned char abBuf[512];
    int i;

//    set_config(1); - the culprit
    set_interface(0, 0);

#if 0
    /* Send an Get Max LUN request */
    abBuf[0] = 0;
    if (doctrl(VUSB_DIR_TO_HOST | VUSB_REQ_CLASS | VUSB_TO_INTERFACE,
               0xfe /* max lun */, 0, 1, 1, abBuf, "get max lun") >= 0)
        printf("max luns: %d\n",  abBuf[0]);
#endif

    for (i = 0; i < 3; i++)
    {
        printf("i=%d\n", i);

        /* Send an INQUIRY command to ep 2 */
        memset(abBuf, 0, sizeof(abBuf));
        memcpy(abBuf, "USBC", 4);
        *(uint32_t *)(&abBuf[4]) = 0x12330984 ;
        //abBuf[8]    = 0x08;
        abBuf[8]    = 0x24;
        abBuf[0xc]  = 0x80;
        abBuf[0xe]  = 0x06; /* cmd length */
        abBuf[0x0f] = 0x12; /* cmd - INQUIRY */
        abBuf[0x13] = 0x24;

        hex(abBuf, 31, "intquery req");
        if (send_bulk(OutEndPt, abBuf, 31) < 0)
            return;
        //usleep(15000);

        /* read result */
        memset(abBuf, 0, sizeof(abBuf));
    //printf("recv..\n");
        int cb = recv_bulk(InEndPt, abBuf, 36);
        hex(abBuf, cb, "inquiry result");

        /* sense? */
        memset(abBuf, 0, sizeof(abBuf));
        cb = recv_bulk(InEndPt, abBuf, 36);
        hex(abBuf, cb, "inquiry sense?");
        usleep(150000);
    }
}
Beispiel #5
0
//-----------------------------------------------------------------
// usb_process_request:
//-----------------------------------------------------------------
static void usb_process_request(struct device_request *request, unsigned char type, unsigned char req, unsigned char *data)
{
	if ( type == USB_STANDARD_REQUEST )
	{
        // Standard requests
        switch (req)
        {
        case REQ_GET_STATUS:
            get_status(request);
            break;
        case REQ_CLEAR_FEATURE:
            clear_feature(request);
            break;
        case REQ_SET_FEATURE:
            set_feature(request);
            break;
        case REQ_SET_ADDRESS:
            set_address(request);
            break;
        case REQ_GET_DESCRIPTOR:
            get_descriptor(request);
            break;
        case REQ_GET_CONFIGURATION:
            get_configuration(request);
            break;
        case REQ_SET_CONFIGURATION:
            set_configuration(request);
            break;
        case REQ_GET_INTERFACE:
            get_interface(request);
            break;
        case REQ_SET_INTERFACE:
            set_interface(request);
            break;
        default:
            log_printf(USBLOG_ERR, "USB: Unknown standard request %x\n", req);
		    usbhw_control_endpoint_stall();
            break;
        }
	}
	else if ( type == USB_VENDOR_REQUEST )
	{
        log_printf(USBLOG_ERR, "Vendor: Unknown command\n");

        // None supported
		usbhw_control_endpoint_stall();
	}
	else if ( type == USB_CLASS_REQUEST && _class_request)
	{
        _class_request(req, request->wValue, request->wIndex, data, request->wLength);
	}
	else
        usbhw_control_endpoint_stall();
}
Beispiel #6
0
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void SuifPrinterModule::initialize()
{
   Module::initialize();
   // register as a listener
   ModuleSubSystem *ms = get_suif_env()->get_module_subsystem();
   ms->register_interface_listener(this, "print_init");
   //   ms->register_interface_producer(this, "print");
   set_interface("print", (Address)SuifPrinterModule::print_dispatch);
   
   init();
}
Beispiel #7
0
	StorageReal(CreatorInt& creat, IRef<eprovider::Storage> ifa, 
		        const wchar_t* path, bool create_if_not_exists) 
		: CreatureDefaultImplementation(creat)
	{
		set_interface(ifa,true,Monitor());
		
		Monitor monitor;
		SIMPLE_CALL( (session = ifa->createSession(error)) );
		SIMPLE_CALL( (ifa->openPath(session,path,create_if_not_exists,error)) );
		
		//TODO: what if error???
	}
Beispiel #8
0
void sr_integ_add_interface(struct sr_instance* sr,
                            struct sr_vns_if* vns_if/* borrowed */)
{
    printf(" ** sr_integ_add_interface(..) called \n");
    struct sr_router* subsystem = (struct sr_router*)sr_get_subsystem(sr);
    subsystem->interface[subsystem->num_interfaces] = set_interface(vns_if, subsystem->num_interfaces);
#ifdef _CPUMODE_
    write_interface_hw(subsystem);
#endif
    subsystem->num_interfaces = subsystem->num_interfaces + 1;
    printf(" ** sr_integ_add_interface(..) current no. of interfaces: %u\n", subsystem->num_interfaces);
    
} /* -- sr_integ_add_interface -- */
Beispiel #9
0
void CPrintStyleModule::initialize() {
  Module::initialize();

  _print_map = 
    new CascadingMap<string_gen_fn>(get_suif_env(), default_string_gen_fn);
  
#define HANDLE_DISPATCH(lower, name) \
  set_print_function( name ## ::get_class_name(), \
		     handle_static_ ## lower ## );
#include "obj.defs"
#undef HANDLE_DISPATCH
 set_interface("print", (Address)CPrintStyleModule::print_dispatch);

}
Beispiel #10
0
int main(int argc, char **argv)
{
    g_fd = open(argv[1], O_RDWR);
    if (g_fd < 0)
        return bitch("open");

    reset();

    usb_set_connected(0, 1);
    claim_if(0);

//    set_config(1); - the culprit!
    set_interface(0, 0);

    msd();
    return 0;
}
Beispiel #11
0
NTSTATUS set_interface_ex(libusb_device_t *dev, 
					   interface_request_t* interface_request, 
                       int timeout)
{
    NTSTATUS status = STATUS_SUCCESS;

    USB_INTERFACE_DESCRIPTOR *interface_descriptor = NULL;

	USBMSG("interface-%s=%d alt-%s=%d timeout=%d\n",
		interface_request->intf_use_index ? "index" : "number",
		interface_request->intf_use_index ? interface_request->interface_index : interface_request->interface_number,
		interface_request->altf_use_index ? "index" : "number",
		interface_request->altf_use_index ? interface_request->altsetting_index : interface_request->altsetting_number,
		timeout);

	interface_descriptor = find_interface_desc_ex(dev->config.descriptor,dev->config.total_size,interface_request,NULL);
	if (!interface_descriptor)
	{
        return STATUS_NO_MORE_ENTRIES;
	}

	return set_interface(dev,interface_descriptor->bInterfaceNumber, interface_descriptor->bAlternateSetting, timeout);
}
Beispiel #12
0
char MySniff::cfg_interface(char *name)
{
	new_dev_clean();
	set_dev_name(name);
	if (set_interface()<0){
		xlog_err(LEVEL2,parent,"Alert","This is not an supported wireless device. Check if the device is wireless and you have enabled monitor mode");
		return -1; 
	}
	
//TODO 	we should use G.freq and not default one
	
	settings = settings | XSNIFF_SETTING_IS_SET_INTERFACE; 
	
	if (is_offline() == 0){
		if (this->cfg_chann()!=0){
			xlog_err(LEVEL7,parent,"Alert","Please set custom channels before start capturing");
			//return -1;
			//!?
		}
	}
	
	return 0;
}
void LocationModule::initialize() {
  Module::initialize();
  set_interface("get_object_location", 
		(Address)LocationModule::get_object_location);
}
Beispiel #14
0
void USBTester::callback_set_interface(uint16_t interface, uint8_t alternate)
{
    complete_set_interface(set_interface(interface, alternate));
}
Beispiel #15
0
/* Main server module common for all transports
 * This module will do the initial transport setups.
 * Then it receives the command from client in CDC format
 * and transmits the response back to the client.
 * In the case of socket, it receives the command from the client
 * and sends the response directly to the client via TCP socket.
 *
 * In the case of serial & wifi , it receives the command from the driver
 * and sends the response to the driver.
 */
int
remote_server_exec(int argc, char **argv, void *wl)
{
	int err;
	int transport_descriptor;
	char *async_cmd_flag = NULL;
	int skip;
	int download_flag = 0;
#if defined(LINUX) || defined(vxworks) || defined(OLYMPIC_RWL)
	char old_intf_name[IFNAMSIZ];
#endif
#ifdef WIN32
	char shell_fname[MAX_SHELL_FILE_LENGTH];
	DWORD dwlen;
#endif
#ifdef RWL_DONGLE
	int uart_enable = 1;
	/* To set dongle flag when dongle server starts */
	if ((err = rwl_var_setbuf(wl, dongleset, &uart_enable,
		sizeof(int))) < 0) {
			DPRINT_INFO(OUTPUT, "Unable to send to wl driver,error=%d\n", err);
	}
#endif
	if (rwl_iovar_check (wl) < 0) {
		DPRINT_ERR(ERR, "wl_server: RWL_WIFI/RWL_DONGLE not defined ");
		DPRINT_ERR(ERR, "Or In-Dongle mode enabled\n");
		exit(0);
	}
	/* Initialise for all the transports - socket, serial, and wifi
	 * In Socket transport, main socket handler will be returned.
	 */
	if ((transport_descriptor = rwl_transport_setup(argc, argv)) < 0)
		return BCME_ERROR;

#ifdef RWL_WIFI
	remote_wifi_ser_init_cmds(wl);
#endif
	/* Create a directory /tmp/RWL for the shell response files */
	if (rwl_create_dir() < 0)
		return BCME_ERROR;


#ifdef RWLASD
	/* DUT initialization function */
	wfa_dut_init(&trafficBuf, &respBuf, &parmsVal, &xcCmdBuf, &toutvalp);
#endif

#if defined(LINUX) || defined(vxworks)
	/* Copy old interface name to restore it */
	store_old_interface(wl, old_intf_name);
#endif /* defined(LINUX) || defined(vxworks) */

	while (1) {
		uchar *buf_ptr = NULL;
#ifdef VISTA_SERVER
		int index;
		char *vista_buf[MAX_VISTA_ARGC];
#endif
#ifdef RWL_SERIAL
		g_rwl_hndle = transport_descriptor;
#else
		g_rwl_hndle = -1;
#endif
#ifdef RWL_DONGLE
		if (set_ctrlc) {
			uart_enable = 0;
			if ((err = rwl_var_setbuf(wl, dongleset, &uart_enable,
				sizeof(int))) < 0) {
				DPRINT_INFO(OUTPUT, "Unable to send to wl driver,error=%d\n", err);
			}
			set_ctrlc = 0;
			exit(0);
		}
#endif /* RWL_DONGLE */

		/* Receive the CDC header */
		if ((remote_rx_header(wl, transport_descriptor)) == BCME_ERROR) {
			DPRINT_DBG(OUTPUT, "\n Waiting for client to transmit command\n");
			continue;
		}

		DPRINT_INFO(OUTPUT, "REC : cmd %d\t msg len %d  msg flag %d\t msg status %d\n",
		            g_rem_ptr->msg.cmd, g_rem_ptr->msg.len,
		            g_rem_ptr->msg.flags, g_rem_ptr->msg.status);

#ifdef RWL_WIFI
		/* send the response to remote if it is findserver cmd, this is specific to wifi */
		if (g_rem_ptr->msg.flags & REMOTE_FINDSERVER_IOCTL) {
			remote_wifi_response(wl);
			continue;
		}
#endif /* RWL_WIFI */

		/*
		 * Allocate buffer only if there is a response message expected.
		 * Some commands such as up/down do not output anything.
		 */
		if (g_rem_ptr->msg.len) {
			if ((buf_ptr = malloc(g_rem_ptr->msg.len)) == NULL) {
				DPRINT_ERR(ERR, "malloc of %d bytes failed\n", g_rem_ptr->msg.len);
				continue;
			}
		}

		/* Receive the data */
		if ((err = remote_rx_data(buf_ptr)) == BCME_ERROR) {
			if (buf_ptr)
				free(buf_ptr);
			continue;
		}

		/* Process RWL negotiate commands */
		if (g_rem_ptr->msg.flags & REMOTE_NEGOTIATE_CMD) {
			if (g_rem_ptr->msg.cmd == NEGOTIATE_GET_OS) {
				if (g_rem_ptr->msg.len >= sizeof(int)) {
#if defined(LINUX)
					*(int*)buf_ptr = LINUX_OS;
#elif defined(VISTA_SERVER)
					*(int*)buf_ptr = WINVISTA_OS;
#elif defined(WIN32)
					*(int*)buf_ptr = WIN32_OS;
#elif defined(MACOSX)
					*(int*)buf_ptr = MAC_OSX;
#else
					*(int*)buf_ptr = UNKNOWN_OS;
#endif
					g_rem_ptr->msg.len = sizeof(int);

					DPRINT_INFO(OUTPUT, "RESP : os type %d\n", *(int*)buf_ptr);
					if (remote_tx_response(wl, buf_ptr, 0) < 0)
						DPRINT_ERR(ERR, "\nReturn results failed\n");
				}
			}
#ifdef RWL_SOCKET
			close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
			if (buf_ptr)
				free(buf_ptr);
			continue;
		}

		/* Process command */
		if (g_rem_ptr->msg.flags & REMOTE_SHELL_CMD) {
			/* Get the response length first and get the response buffer in case of
			 * synchronous shell commands and the buf_ptr will have the response file
			 * name. In case of asynchronous shell commands, buf_ptr
			 * will be get updated by the remote_shell_execute function.
			 */
			need_speedy_response = 1;
#ifndef WIN32
			if (buf_ptr) {
				async_cmd_flag = strstr((char*)buf_ptr, "%");
			}
			if ((err = remote_shell_execute((char*)buf_ptr, wl)) > 0) {
				if (async_cmd_flag)
					g_rem_ptr->msg.len = err;
			}
			/* Sync shell command: No need to send response from here */
			else {
#ifdef RWL_SOCKET
				/* Transmitted to client. Then close the handle &
				 * get the new handle for next transmission & reception.
				 */
				close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
				continue;
			}
#else
			if ((err = remote_shell_execute((char*)buf_ptr, wl)) != SUCCESS) {
				DPRINT_ERR(ERR, "Error in executing shell command\n");
				if (buf_ptr)
					free(buf_ptr);
#ifdef RWL_SOCKET
				/* Transmitted to client. Then close the handle &
				 * get the new handle for next transmission & reception.
				 */
				close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
				continue;
			}
			/* Get the response from the temporary file */
			if ((err = remote_shell_get_resp(shell_fname, wl)) != SUCCESS) {
				DPRINT_ERR(ERR, "Error in executing shell command\n");
			}
			if (buf_ptr)
				free(buf_ptr);
#ifdef RWL_SOCKET
			/* Transmitted to client. Then close the handle &
			 * get the new handle for next transmission & reception.
			 */
			close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
			continue;
#endif	/* WIN32 */
		} /* REMOTE_SHELL_CMD */

#ifdef RWLASD
		if (g_rem_ptr->msg.flags & REMOTE_ASD_CMD) {
			if ((err = remote_asd_exec(buf_ptr, (int *)&g_rem_ptr->msg.len)) < 0) {
				DPRINT_ERR(ERR, "Error in executing asd command\n");
			}
		} /* REMOTE_ASD_CMD */
#endif

/*
 * added to take care of OID base problem for cross OS RWL cleint server
 * In case of LX Server and WIN32 client OID base need to be removed
 * In case of WIN32 server and LX client OID base need to be added
 */
		if (!(g_rem_ptr->msg.flags & REMOTE_ASD_CMD)) {
#if defined(LINUX) || defined(vxworks)
		if (g_rem_ptr->msg.cmd > MAX_IOVAR)
			g_rem_ptr->msg.cmd -= WL_OID_BASE;
#endif
#if defined(WIN32)
		if (g_rem_ptr->msg.cmd < MAX_IOVAR)
			g_rem_ptr->msg.cmd += WL_OID_BASE;
#endif
		}
#ifdef VISTA_SERVER
		if (g_rem_ptr->msg.flags & REMOTE_VISTA_CMD) {
			vista_buf[0] = strtok(buf_ptr, " \t\n");
			for (index = 1; (vista_buf[index] = strtok(NULL, " \t\n")) != NULL;
				index++);
			if ((err = remote_vista_exec(wl, vista_buf)) < 0) {
				DPRINT_ERR(ERR, "Error in executing vista command\n");
			}
			memcpy(buf_ptr, vista_buf[0], strlen(vista_buf[0]));
			g_rem_ptr->msg.len = strlen(vista_buf[0]);
		} /* REMOTE_VISTA_CMD */
#endif /* VISTA_SERVER */

#ifndef OLYMPIC_RWL
#if defined(LINUX) || defined(vxworks)
#ifndef RWL_DONGLE
		if (g_rem_ptr->msg.flags & REMOTE_GET_IOCTL ||
			g_rem_ptr->msg.flags & REMOTE_SET_IOCTL) {
			if (strlen(g_rem_ptr->intf_name) != 0) {
#if defined(LINUX)
				struct ifreq ifr;
				/* validate the interface */
				memset(&ifr, 0, sizeof(ifr));
				if (g_rem_ptr->intf_name)
					strncpy(ifr.ifr_name, g_rem_ptr->intf_name, IFNAMSIZ);

				if (wl_check((void *)&ifr)) {
					DPRINT_ERR(ERR, "%s: wl driver adapter not found\n",
						g_rem_ptr->intf_name);
					/* Signal end of command output */
					g_rem_ptr->msg.len = 0;
					remote_tx_response(wl, NULL, BCME_NODEVICE);
					if (buf_ptr)
						free(buf_ptr);
#ifdef RWL_SOCKET
					close_sock_handle(g_rwl_hndle);
#endif
					continue;
				}
#endif /* LINUX */
#if defined(vxworks)
				if (wl_check((void *)g_rem_ptr->intf_name)) {
					DPRINT_ERR(ERR, "%s: wl driver adapter not found\n",
						g_rem_ptr->intf_name);
					/* Signal end of command output */
					g_rem_ptr->msg.len = 0;
					remote_tx_response(wl, NULL, BCME_NODEVICE);
					if (buf_ptr)
						free(buf_ptr);
#ifdef RWL_SOCKET
					close_sock_handle(g_rwl_hndle);
#endif
					continue;
				}
#endif /* vxworks */

				if (set_interface(wl, g_rem_ptr->intf_name) == BCME_OK)
					DPRINT_DBG(OUTPUT, "\n %s Interface will be used \n",
						(char *)wl);
			}
		}
#endif /* ifndef RWL_DONGLE */
#endif /* defined(LINUX) || defined(vxworks) */
#endif /* ifndef OLYMPIC_RWL */
		if (g_rem_ptr->msg.flags & REMOTE_SET_IOCTL ||
			g_rem_ptr->msg.flags & RDHD_SET_IOCTL) {
#ifdef WIN32
#if defined (RWL_DONGLE) || defined (RWL_WIFI)
			/* For commands with msg length as zero initialize the buffer to null */
			if (g_rem_ptr->msg.len == 0)
				buf_ptr = NULL;
#endif
#else
			if (g_rem_ptr->msg.len == 0)
				buf_ptr = NULL;
#endif /* WIN32 */

#if defined(LINUX) || defined(TARGETOS_symbian) || defined(TARGETOS_nucleus) || defined(MACOSX) || defined(TARGET_wiced)
#ifdef OLYMPIC_RWL
			set_interface(wl, old_intf_name);
#endif
#if defined( TARGET_wiced )
            set_interface(wl, g_rem_ptr->intf_name);
#endif
			if (g_rem_ptr->msg.flags & REMOTE_SET_IOCTL) {
				if (g_rem_ptr->msg.cmd == WLC_SET_VAR && buf_ptr &&
				    !strncmp((const char *)buf_ptr,
					     "init", g_rem_ptr->msg.len)) {
					DPRINT_INFO(OUTPUT, "REC : init command\n");
					err = 0;
				} else if (g_rem_ptr->msg.cmd == WLC_SET_VAR && buf_ptr &&
				   !strncmp((const char *)buf_ptr,
					    "download", g_rem_ptr->msg.len)) {
					DPRINT_INFO(OUTPUT, "REC : download command\n");
					download_flag =  download_flag? 0: 1;
					if (download_flag) {
						DPRINT_INFO(OUTPUT, "download started\n");
						start_download( );
					} else {
						DPRINT_INFO(OUTPUT, "download completed\n");
						finish_download( );
					}
					err = 0;
				} else if (g_rem_ptr->msg.cmd == WLC_SET_VAR && buf_ptr &&
				   !strncmp((const char *)buf_ptr,
					    "membytes", g_rem_ptr->msg.len)) {
					DPRINT_INFO(OUTPUT, "REC : membytes command\n");
					skip = strlen("membytes ");
					uint32_t address = *((uint32_t*)(buf_ptr + skip));
					skip += sizeof(uint32_t);
                    uint32_t len = *((uint32_t*)(buf_ptr + skip));
                    skip += sizeof(uint32_t);
                    if ( len != g_rem_ptr->msg.len - skip )
                    {
                        DPRINT_ERR(ERR, "Length does not match\n");
                    }
					membytes_write( address, buf_ptr + skip, g_rem_ptr->msg.len - skip );
					err = 0;
				} else {
					err = wl_ioctl(wl, g_rem_ptr->msg.cmd,
					       (void *)buf_ptr, g_rem_ptr->msg.len, TRUE);
					DPRINT_INFO(OUTPUT, "SEND : cmd %d\t msg len %d\n",
					    g_rem_ptr->msg.cmd, g_rem_ptr->msg.len);
					DPRINT_INFO(OUTPUT, "error code: %d\n", err);
				}
			}
#if defined(LINUX)
			if (err == IOCTL_ERROR) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl\n");
				DPRINT_ERR(ERR, "Setting Default Interface1 \n");
				set_interface(wl, old_intf_name);
			}

			if (g_rem_ptr->msg.flags & RDHD_SET_IOCTL) {
				err = dhd_ioctl(wl, g_rem_ptr->msg.cmd,
				(void *)buf_ptr, g_rem_ptr->msg.len, TRUE);
			}
#endif /* LINUX */

#elif vxworks
			if ((err = wl_ioctl_vx(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
				g_rem_ptr->msg.len)) != 0) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl_vx\n");
			}

			if (err == IOCTL_ERROR) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl\n");
				DPRINT_ERR(ERR, "Setting Default Interface \n");
				set_interface(wl, old_intf_name);
			}
#elif WIN32
			dwlen = g_rem_ptr->msg.len;
			if (g_rem_ptr->msg.flags & RDHD_SET_IOCTL) {
				g_rem_ptr->msg.cmd = g_rem_ptr->msg.cmd
					- WL_OID_BASE + OID_DHD_IOCTLS;
			}

			err = (int)ir_setinformation(wl, g_rem_ptr->msg.cmd,
			                       buf_ptr, &dwlen);
#endif /* LINUX TARGETOS_symbian MACOSX */
			g_rem_ptr->msg.flags = REMOTE_SET_IOCTL;

		} /* RDHD/REMOTE_SET_IOCTL */

		if (g_rem_ptr->msg.flags & REMOTE_GET_IOCTL ||
			g_rem_ptr->msg.flags & RDHD_GET_IOCTL) {
#if defined(LINUX) || defined(TARGETOS_symbian) || defined(TARGETOS_nucleus) || defined(MACOSX) || defined(TARGET_wiced)
			if (g_rem_ptr->msg.cmd == WLC_GET_VAR && buf_ptr &&
				strncmp((const char *)buf_ptr, "exit", g_rem_ptr->msg.len) == 0) {
					/* exit command from remote client terminates server */
					free(buf_ptr);
					break;
			}
#if defined( TARGET_wiced )
            set_interface(wl, g_rem_ptr->intf_name);
#endif
			if (g_rem_ptr->msg.flags & REMOTE_GET_IOCTL)
				err = wl_ioctl(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
					g_rem_ptr->msg.len, FALSE);
#if defined (LINUX)
			if (err == IOCTL_ERROR) {
				DPRINT_ERR(ERR, "REMOTE_GET_IOCTL::Error in executing wl_ioctl\n");
				DPRINT_ERR(ERR, "Setting Default Interface \n");
				set_interface(wl, old_intf_name);
			}

			if (g_rem_ptr->msg.flags & RDHD_GET_IOCTL)
				err = dhd_ioctl(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
					g_rem_ptr->msg.len, FALSE);
#endif /* LINUX */
#elif vxworks
			if ((err = wl_ioctl_vx(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
				g_rem_ptr->msg.len)) != 0) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl_vx\n");
			}

			if (err == IOCTL_ERROR) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl_vx\n");
				DPRINT_ERR(ERR, "Setting Default Interface \n");
				set_interface(wl, old_intf_name);
			}
#elif WIN32
			if (g_rem_ptr->msg.cmd == (WL_OID_BASE + WLC_GET_VAR) &&
				strncmp(buf_ptr, "exit", g_rem_ptr->msg.len) == 0) {
					/* exit command from remote client terminates server */
					if (buf_ptr) {
						free(buf_ptr);
					}
					break;
			}

			dwlen = g_rem_ptr->msg.len;
			if (g_rem_ptr->msg.flags & RDHD_GET_IOCTL) {
				g_rem_ptr->msg.cmd = g_rem_ptr->msg.cmd -
					WL_OID_BASE + OID_DHD_IOCTLS;
				}

			err = (int)ir_queryinformation(wl,
			g_rem_ptr->msg.cmd, buf_ptr, &dwlen);

#endif /* defined(LINUX) || defined(TARGETOS_symbian) || defined(TARGETOS_nucleus)  || defined(TARGET_wiced) */
			g_rem_ptr->msg.flags = REMOTE_GET_IOCTL;
		} /* REMOTE_GET_IOCTL */
		DPRINT_INFO(OUTPUT, "RESP : cmd %d\t msg len %d\n",
		g_rem_ptr->msg.cmd, g_rem_ptr->msg.len);
#if defined(LINUX) || defined(vxworks)
		/* setting back default interface  */
		set_interface(wl, old_intf_name);
#endif /*  defined(LINUX) || defined(vxworks) */
		/* Transmit the response results */
		if (remote_tx_response(wl, buf_ptr, err) < 0) {
			DPRINT_ERR(ERR, "\nReturn results failed\n");
		}

#ifdef RWL_SOCKET
		if (g_rem_ptr->msg.flags != REMOTE_SHELL_CMD)
		/* Transmitted to client. Then close the handle & get the new handle
		 * for next transmission & reception. In case of shell commands this
		 * should be closed in respective shellproc files.
		 */
		close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */

		if (buf_ptr) {
			free(buf_ptr);
		}
	} /* end of while */
#if defined (RWL_SOCKET)
	/* Close the main handle for socket */
	close_sock_handle(transport_descriptor);
#elif defined(RWL_SERIAL)
	/* Close the main handle for serial pipe  */
	rwl_close_pipe(remote_type, (void*)&transport_descriptor);
#endif

#ifdef RWLASD
	wfa_dut_deinit();
#endif

	return err;
}
int main(int argc, char **argv)
{
    
    int status;
    int i;
    int debug = 0;
    int long_preamble = 0;
    
    int test = TEST_NONE;
    DataRate rate_e = DATA_RATE_1M;
    char *rate_s = "1Mbps";
    char *interface_name = NULL;
    
    
    DBG("argc=%u\n", argc);

    if(argc < 2)
    {
        print_usage();
        return -1;
    }

    interface_name = argv[1];

    
    
    for(i=2;i<argc;i++)
    {
        if(str_comp(argv[i], "-ch:", 4))
        {
            channel = atoi(argv[i]+4);
            if((channel > 14) || (channel < 1))
            {
                CON("Invalid channel: %u\n", channel);
                return -1;
            }
            continue;
        }

        if(str_comp(argv[i], "-time:", 6))
        {
            time = atoi(argv[i]+6);
            if((time > 24*3600) || (time < 1))
            {
                CON("Invalid time: %u\n", time);
                return -1;
            }
            continue;
        }

        if(str_comp(argv[i], "-rate:", 6))
        {
            int rate = atoi(argv[i]+6);
            switch(rate)
            {
                case 1:
                case 1000:
                    rate_e = DATA_RATE_1M;
                    rate_s = "1Mbps";
                    break;
                case 2:    
                case 2000:
                    rate_e = DATA_RATE_2M;
                    rate_s = "2Mbps";
                    break;
                case 5500:
                    rate_e = DATA_RATE_5_5M;
                    rate_s = "5.5Mbps";
                    break;
                //case 6: the user migh have writen "-rate:6.5"...    
                case 6000:
                    rate_e = DATA_RATE_6M;
                    rate_s = "6Mbps";
                    break;
                case 6500:
                    rate_e = DATA_RATE_MCS0;
                    rate_s = "6.5Mbps (MCS0)";
                    break;    
                case 9:    
                case 9000:
                    rate_e = DATA_RATE_9M;
                    rate_s = "9Mbps";
                    break;
                case 11:    
                case 11000:
                    rate_e = DATA_RATE_11M;
                    rate_s = "11Mbps";
                    break;
                case 12:    
                case 12000:
                    rate_e = DATA_RATE_12M;
                    rate_s = "12Mbps";
                    break;
                case 13:    
                case 13000:
                    rate_e = DATA_RATE_MCS1;
                    rate_s = "13Mbps (MSC1)";
                    break;
                case 18:    
                case 18000:
                    rate_e = DATA_RATE_18M;
                    rate_s = "18Mbps";
                    break;
                case 19500:
                    rate_e = DATA_RATE_MCS2;
                    rate_s = "19.5Mbps (MSC2)";
                    break;
                case 22:    
                case 22000:
                    rate_e = DATA_RATE_22M;
                    rate_s = "22Mbps";
                    break;
                case 24:    
                case 24000:
                    rate_e = DATA_RATE_24M;
                    rate_s = "24Mbps";
                    break;
                case 26:    
                case 26000:
                    rate_e = DATA_RATE_MCS3;
                    rate_s = "26Mbps (MSC3)";
                    break;
                case 33:    
                case 33000:
                    rate_e = DATA_RATE_33M;
                    rate_s = "33Mbps";
                    break;
                case 36:    
                case 36000:
                    rate_e = DATA_RATE_36M;
                    rate_s = "36Mbps";
                    break;
                case 39:
                case 39000:
                    rate_e = DATA_RATE_MCS4;
                    rate_s = "39Mbps (MCS4)";
                    break;
                case 48:    
                case 48000:
                    rate_e = DATA_RATE_48M;
                    rate_s = "48Mbps";
                    break;
                case 52:    
                case 52000:
                    rate_e = DATA_RATE_MCS5;
                    rate_s = "52Mbps (MCS5)";
                    break;
                case 54:    
                case 54000:
                    rate_e = DATA_RATE_54M;
                    rate_s = "54Mbps";
                    break;    
                case 58500:
                    rate_e = DATA_RATE_MCS6;
                    rate_s = "58.5Mbps (MCS6)";
                    break;
                case 65:    
                case 65000:
                    rate_e = DATA_RATE_MCS7;
                    rate_s = "65Mbps (MSC7)";
                    break;
               default:
                   CON("Invalid modulation rate %uKbps\n",rate);
                   return -1;
           }
           continue;
        }
        
        if(str_comp(argv[i], "-bi:", 4))
        {
            burst_interval = atoi(argv[i]+4);
            if(burst_interval < 0)
            {
                CON("Invalid burst interval: %u\n", burst_interval);
                return -1;
            }
            continue;
        }
         
        if(str_comp(argv[i], "-size:", 6))
        {
            packet_size = atoi(argv[i]+6);
            if((packet_size < 0) || (packet_size > 1536))
            {
                CON("Invalid packet size: %u\n", packet_size);
                return -1;
            }
            continue;
        }
        
        if(str_comp(argv[i], "-pwr:", 5))
        {
            output_power = atoi(argv[i]+5);
            if((output_power < 0) || (output_power > 30))
            {
                CON("Invalid output power: %ddBm\n", output_power);
                return -1;
            }
            continue;
        }     

        if(str_comp(argv[i], "none", 4))
        {
            test = TEST_NONE;
            continue;
        }

        if(str_comp(argv[i], "tx", 2))
        {
            test = TEST_TX;
            continue;
        }

        if(str_comp(argv[i], "rx", 2))
        {
            test = TEST_RX;
            continue;
        }
        
        if(str_comp(argv[i], "-lp", 3))
        {
            long_preamble = 1;
            continue;
        }  

        if(str_comp(argv[i], "-dbg", 4))
        {
            enable_debug();
            continue;
        }

        CON("I do not understand argument \"%s\", ignoring\n", argv[i]);
    }

    status = set_interface(interface_name);
    if(status)
    {
        CON("Could not set interface name\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        return -1;
    }
  
  
    status = OpenDUT();
    if(status)
    {
        CON("Could not open connection to Nanoradio WiFi-chip\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        return -1;
    }
     
    status = SetLongPreamble(long_preamble);
    if(status)
    {
        CON("Failed to set long preamble\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }
     
    status = SetBurstInterval(burst_interval);
    if(status)
    {
        CON("Failed to set burst interval\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }   
  
  
    status = SetChannel(channel);
    if(status)
    {
        CON("Failed to write channel to Nanoradio WiFi-chip\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }
    
    status = SetPayload(packet_size);
    if(status)
    {
        CON("Failed to set packet size\n");
        CON("  Driver say:\"%s\"\n",GetErrorString());
        goto exit;
    }
  

  status = SetDataRate(rate_e);
  if(status)
  {
    CON("Failed to write data rate to Nanoradio WiFi-chip\n");
    CON("  Driver say:\"%s\"\n",GetErrorString());
    goto exit;
  }

    switch(test)
    {
        case TEST_NONE:
            break;
        case TEST_TX:
        {
            status = TxGain(output_power);
            if(status)
            {
                CON("Failed to set output power\n");
                CON("  Driver say:\"%s\"\n",GetErrorString());
                goto exit;
            }   
         
            status = TxStartWithMod();
            if(status)
            {
                CON("Failed to start TX\n");
                CON("  Driver say:\"%s\"\n",GetErrorString());
                goto exit;
            }
            else
            {
                CON("Sending frames continiously on channel %u with rate %s for %u seconds\n",channel,rate_s,time);
                sleep(time);
                status = TxStop();
                if(status)
                {
                    CON("Failed to stop TX\n");
                    CON("  Driver say:\"%s\"\n",GetErrorString());
                    goto exit;
                }
                
            }
        }
        break;
        
        case TEST_RX:
        {
            status = RxStart();
            if(status)
            {
                CON("Failed to start RX\n");
                CON("  Driver say:\"%s\"\n",GetErrorString());
                goto exit;
            }
            else
            {
                CON("Counting frames on channel %u with rate %s for %u seconds\n",channel,rate_s,time);
                sleep(time);
                status = RxStop();
                if(status)
                {
                    CON("Failed to stop RX\n");
                    CON("  Driver say:\"%s\"\n",GetErrorString());
                    goto exit;
                }
                else
                {
                    CON("Good frames:%u\n", GetGoodFrame());
                }
            }
      }
      break;
  }

exit:

    CloseDUT();
    return status;
}
Beispiel #17
0
int main() {
	//###################################################################### //TODO get this from config file eventually
	//host interface
	my_host_mac_addr = 0x080027445566ull;
	my_host_ip_addr = IP4_ADR_P2H(192,168,1,20);
	my_host_mask = IP4_ADR_P2H(255,255,255,0);

	//loopback interface
	loopback_ip_addr = IP4_ADR_P2H(127,0,0,1);
	loopback_mask = IP4_ADR_P2H(255,0,0,0);

	//any
	any_ip_addr = IP4_ADR_P2H(0,0,0,0);
	//######################################################################

	sem_init(&control_serial_sem, 0, 1); //TODO remove after gen_control_serial_num() converted to RNG

	signal(SIGINT, termination_handler); //register termination handler

	// Start the driving thread of each module
	PRINT_DEBUG("Initialize Modules");
	switch_init(); //should always be first
	daemon_init(); //TODO improve how sets mac/ip
	interface_init();

	arp_init();
	arp_register_interface(my_host_mac_addr, my_host_ip_addr);

	ipv4_init();
	set_interface(my_host_ip_addr, my_host_mask);
	set_loopback(loopback_ip_addr, loopback_mask);

	icmp_init();
	tcp_init();
	udp_init();
	//rtm_init(); //TODO when updated/fully implemented

	pthread_attr_t fins_pthread_attr;
	pthread_attr_init(&fins_pthread_attr);

	PRINT_DEBUG("Run/start Modules");
	switch_run(&fins_pthread_attr);
	daemon_run(&fins_pthread_attr);
	interface_run(&fins_pthread_attr);
	arp_run(&fins_pthread_attr);
	ipv4_run(&fins_pthread_attr);
	icmp_run(&fins_pthread_attr);
	tcp_run(&fins_pthread_attr);
	udp_run(&fins_pthread_attr);
	//rtm_run(&fins_pthread_attr);

	//############################# //TODO custom test, remove later
	/*
	 if (0) {
	 char recv_data[4000];

	 while (1) {
	 gets(recv_data);

	 PRINT_DEBUG("Sending ARP req");

	 metadata *params_req = (metadata *) malloc(sizeof(metadata));
	 if (params_req == NULL) {
	 PRINT_ERROR("metadata alloc fail");
	 exit(-1);
	 }
	 metadata_create(params_req);

	 uint32_t dst_ip = IP4_ADR_P2H(192, 168, 1, 11);
	 //uint32_t dst_ip = IP4_ADR_P2H(172, 31, 50, 152);
	 uint32_t src_ip = IP4_ADR_P2H(192, 168, 1, 20);
	 //uint32_t src_ip = IP4_ADR_P2H(172, 31, 50, 160);

	 metadata_writeToElement(params_req, "dst_ip", &dst_ip, META_TYPE_INT32);
	 metadata_writeToElement(params_req, "src_ip", &src_ip, META_TYPE_INT32);

	 struct finsFrame *ff_req = (struct finsFrame*) malloc(sizeof(struct finsFrame));
	 if (ff_req == NULL) {
	 PRINT_ERROR("todo error");
	 //metadata_destroy(params_req);
	 exit(-1);
	 }

	 ff_req->dataOrCtrl = CONTROL;
	 ff_req->destinationID.id = ARP_ID;
	 ff_req->destinationID.next = NULL;
	 ff_req->metaData = params_req;

	 ff_req->ctrlFrame.senderID = IP_ID;
	 ff_req->ctrlFrame.serial_num = gen_control_serial_num();
	 ff_req->ctrlFrame.opcode = CTRL_EXEC;
	 ff_req->ctrlFrame.param_id = EXEC_ARP_GET_ADDR;

	 ff_req->ctrlFrame.data_len = 0;
	 ff_req->ctrlFrame.data = NULL;

	 arp_to_switch(ff_req); //doesn't matter which queue
	 }
	 }
	 //#############################
	 */

	while (1)
		;

	return (1);
}
Beispiel #18
0
void Pass::initialize() {
  Module::initialize();
  set_interface("Pass", 0);
}
Beispiel #19
0
void PipelinablePass::initialize() {
  Pass::initialize();
  set_interface("PipelinablePass", 0);
}
Beispiel #20
0
void FrontendPass::initialize() {
  Module::initialize();
  set_interface("FrontendPass", 0);
}
/**
 * Submit a LinuxRequest.
 * @param env The JNIEnv.
 * @param fd The file descriptor.
 * @param linuxRequest The LinuxRequest.
 */
static void submitRequest( JNIEnv *env, int fd, jobject linuxRequest )
{
	int type, err, sync = 0;

	jclass LinuxRequest;
	jmethodID getType, setError, setCompleted;

	LinuxRequest = (*env)->GetObjectClass( env, linuxRequest );
	getType = (*env)->GetMethodID( env, LinuxRequest, "getType", "()I" );
	setCompleted = (*env)->GetMethodID( env, LinuxRequest, "setCompleted", "(Z)V" );
	setError = (*env)->GetMethodID( env, LinuxRequest, "setError", "(I)V" );
	(*env)->DeleteLocalRef( env, LinuxRequest );

	type = (*env)->CallIntMethod( env, linuxRequest, getType );

	dbg(MSG_DEBUG1, "submitRequest : Submitting Request.\n");

	switch (type) {
	case LINUX_PIPE_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting Pipe Request.\n");
		err = pipe_request( env, fd, linuxRequest );
		break;
	case LINUX_DCP_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting Dcp Request.\n");
		err = dcp_request( env, fd, linuxRequest );
		break;
	case LINUX_SET_INTERFACE_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting SetInterface Request.\n");
		err = set_interface( env, fd, linuxRequest );
		sync = 1;
		break;
	case LINUX_SET_CONFIGURATION_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting SetConfiguration Request.\n");
		err = set_configuration( env, fd, linuxRequest );
		sync = 1;
		break;
	case LINUX_CLAIM_INTERFACE_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting ClaimInterface Request.\n");
		err = claim_interface( env, fd, 1, linuxRequest );
		sync = 1;
		break;
	case LINUX_RELEASE_INTERFACE_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting ReleaseInterface Request.\n");
		err = claim_interface( env, fd, 0, linuxRequest );
		sync = 1;
		break;
	case LINUX_IS_CLAIMED_INTERFACE_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting IsClaimed Request.\n");
		err = is_claimed( env, fd, linuxRequest );
		sync = 1;
		break;
	case LINUX_ISOCHRONOUS_REQUEST:
		dbg(MSG_DEBUG1, "submitRequest : Submitting Isochronous Request.\n");
		err = isochronous_request( env, fd, linuxRequest );
		break;
	default: /* ? */
		dbg( MSG_ERROR, "submitRequest : Unknown Request type %d\n", type );
		err = -EINVAL;
		break;
	}

	if (err)
		(*env)->CallVoidMethod( env, linuxRequest, setError, err );

	if (sync || err)
		(*env)->CallVoidMethod( env, linuxRequest, setCompleted, JNI_TRUE );
}
Beispiel #22
0
Menu::Menu(QString name, bool is_training, QWidget* parent) : QWidget(parent) {
    this -> is_training = is_training;
    this -> name = name;
    set_interface();
}