示例#1
0
文件: main.c 项目: EFraim/trans-vpn
int main(int argc, char *argv[])
{
    if (argc != 5) {
        printf("Usage: ./ethapp <eth-port-my> <eth-port-other> <usb-port-my> <usb-port-other>\n");
        return 1;
    }
    
    LOG_INFO("Initializing USB Stack");
    usbnet_init(argv[3], argv[4]);
    
	LOG_INFO("Initializing Ethernet stack");
	enc28j60_init(0, 0, MACAddress, argv[1], argv[2]);
	
	LOG_INFO("Starting USB Stack");
    
    LOG_INFO("Entering main loop");
    
    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.sa_handler = sigint_handler;
    //sigaction(SIGINT, &act, NULL);
    
    appnet_loop();
	return 0;
}
示例#2
0
文件: acm.c 项目: dell-asm-ci/ipxe
/**
 * Probe device
 *
 * @v func		USB function
 * @v config		Configuration descriptor
 * @ret rc		Return status code
 */
static int acm_probe ( struct usb_function *func,
		       struct usb_configuration_descriptor *config ) {
	struct usb_device *usb = func->usb;
	struct rndis_device *rndis;
	struct acm_device *acm;
	int rc;

	/* Allocate and initialise structure */
	rndis = alloc_rndis ( sizeof ( *acm ) );
	if ( ! rndis ) {
		rc = -ENOMEM;
		goto err_alloc;
	}
	rndis_init ( rndis, &acm_operations );
	rndis->netdev->dev = &func->dev;
	acm = rndis->priv;
	acm->usb = usb;
	acm->bus = usb->port->hub->bus;
	acm->rndis = rndis;
	usbnet_init ( &acm->usbnet, func, &acm_intr_operations,
		      &acm_in_operations, &acm_out_operations );
	usb_refill_init ( &acm->usbnet.intr, 0, ACM_INTR_MAX_FILL );
	usb_refill_init ( &acm->usbnet.in, ACM_IN_MTU, ACM_IN_MAX_FILL );

	/* Describe USB network device */
	if ( ( rc = usbnet_describe ( &acm->usbnet, config ) ) != 0 ) {
		DBGC ( acm, "ACM %p could not describe: %s\n",
		       acm, strerror ( rc ) );
		goto err_describe;
	}

	/* Register RNDIS device */
	if ( ( rc = register_rndis ( rndis ) ) != 0 )
		goto err_register;

	usb_func_set_drvdata ( func, acm );
	return 0;

	unregister_rndis ( rndis );
 err_register:
 err_describe:
	free_rndis ( rndis );
 err_alloc:
	return rc;
}
示例#3
0
/**
 * Probe device
 *
 * @v func		USB function
 * @v config		Configuration descriptor
 * @ret rc		Return status code
 */
static int smsc95xx_probe ( struct usb_function *func,
			    struct usb_configuration_descriptor *config ) {
	struct usb_device *usb = func->usb;
	struct net_device *netdev;
	struct smsc95xx_device *smsc95xx;
	int rc;

	/* Allocate and initialise structure */
	netdev = alloc_etherdev ( sizeof ( *smsc95xx ) );
	if ( ! netdev ) {
		rc = -ENOMEM;
		goto err_alloc;
	}
	netdev_init ( netdev, &smsc95xx_operations );
	netdev->dev = &func->dev;
	smsc95xx = netdev->priv;
	memset ( smsc95xx, 0, sizeof ( *smsc95xx ) );
	smsc95xx->usb = usb;
	smsc95xx->bus = usb->port->hub->bus;
	smsc95xx->netdev = netdev;
	usbnet_init ( &smsc95xx->usbnet, func, &smsc95xx_intr_operations,
		      &smsc95xx_in_operations, &smsc95xx_out_operations );
	usb_refill_init ( &smsc95xx->usbnet.intr, 0, 0,
			  SMSC95XX_INTR_MAX_FILL );
	usb_refill_init ( &smsc95xx->usbnet.in,
			  ( sizeof ( struct smsc95xx_tx_header ) -
			    sizeof ( struct smsc95xx_rx_header ) ),
			  SMSC95XX_IN_MTU, SMSC95XX_IN_MAX_FILL );
	mii_init ( &smsc95xx->mii, &smsc95xx_mii_operations );
	DBGC ( smsc95xx, "SMSC95XX %p on %s\n", smsc95xx, func->name );

	/* Describe USB network device */
	if ( ( rc = usbnet_describe ( &smsc95xx->usbnet, config ) ) != 0 ) {
		DBGC ( smsc95xx, "SMSC95XX %p could not describe: %s\n",
		       smsc95xx, strerror ( rc ) );
		goto err_describe;
	}

	/* Reset device */
	if ( ( rc = smsc95xx_reset ( smsc95xx ) ) != 0 )
		goto err_reset;

	/* Read MAC address */
	if ( ( rc = smsc95xx_fetch_mac ( smsc95xx, netdev->hw_addr ) ) != 0 )
		goto err_fetch_mac;

	/* Register network device */
	if ( ( rc = register_netdev ( netdev ) ) != 0 )
		goto err_register;

	usb_func_set_drvdata ( func, netdev );
	return 0;

	unregister_netdev ( netdev );
 err_register:
 err_fetch_mac:
 err_reset:
 err_describe:
	netdev_nullify ( netdev );
	netdev_put ( netdev );
 err_alloc:
	return rc;
}
示例#4
0
文件: dm96xx.c 项目: dell-asm-ci/ipxe
/**
 * Probe device
 *
 * @v func		USB function
 * @v config		Configuration descriptor
 * @ret rc		Return status code
 */
static int dm96xx_probe ( struct usb_function *func,
		       struct usb_configuration_descriptor *config ) {
	struct usb_device *usb = func->usb;
	struct net_device *netdev;
	struct dm96xx_device *dm96xx;
	int rc;

	/* Allocate and initialise structure */
	netdev = alloc_etherdev ( sizeof ( *dm96xx ) );
	if ( ! netdev ) {
		rc = -ENOMEM;
		goto err_alloc;
	}
	netdev_init ( netdev, &dm96xx_operations );
	netdev->dev = &func->dev;
	dm96xx = netdev->priv;
	memset ( dm96xx, 0, sizeof ( *dm96xx ) );
	dm96xx->usb = usb;
	dm96xx->bus = usb->port->hub->bus;
	dm96xx->netdev = netdev;
	usbnet_init ( &dm96xx->usbnet, func, &dm96xx_intr_operations,
		      &dm96xx_in_operations, &dm96xx_out_operations );
	usb_refill_init ( &dm96xx->usbnet.intr, 0, DM96XX_INTR_MAX_FILL );
	usb_refill_init ( &dm96xx->usbnet.in, DM96XX_IN_MTU,
			  DM96XX_IN_MAX_FILL );
	DBGC ( dm96xx, "DM96XX %p on %s\n", dm96xx, func->name );

	/* Describe USB network device */
	if ( ( rc = usbnet_describe ( &dm96xx->usbnet, config ) ) != 0 ) {
		DBGC ( dm96xx, "DM96XX %p could not describe: %s\n",
		       dm96xx, strerror ( rc ) );
		goto err_describe;
	}

	/* Reset device */
	if ( ( rc = dm96xx_reset ( dm96xx ) ) != 0 )
		goto err_reset;

	/* Read MAC address */
	if ( ( rc = dm96xx_read_mac ( dm96xx, netdev->hw_addr ) ) != 0 )
		goto err_read_mac;

	/* Get initial link status */
	if ( ( rc = dm96xx_check_link ( dm96xx ) ) != 0 )
		goto err_check_link;

	/* Register network device */
	if ( ( rc = register_netdev ( netdev ) ) != 0 )
		goto err_register;

	usb_func_set_drvdata ( func, netdev );
	return 0;

	unregister_netdev ( netdev );
 err_register:
 err_check_link:
 err_read_mac:
 err_reset:
 err_describe:
	netdev_nullify ( netdev );
	netdev_put ( netdev );
 err_alloc:
	return rc;
}