55#define USBETH_TRACE( x, y ... ) xprintf( x, ##y )
57#define USBETH_TRACE( x, y ... ) ((void)0)
63#define ALIGN(n,align) (((n)+((align)-1)) & ~((align)-1))
65#define usb_dma_alloc(n) (KMALLOC(ALIGN((n),CACHE_ALIGN),CACHE_ALIGN))
66#define usb_dma_free(p) (KFREE(p))
77static void hexdump(
unsigned char *src,
int srclen,
int rowlen,
int rows )
79 unsigned char *rowptr;
80 unsigned char *srcstp;
81 unsigned char *byteptr;
83 srcstp = src + srclen;
85 for( rowptr = src; rowptr < src + rowlen * rows; rowptr += rowlen ) {
86 for( byteptr = rowptr; byteptr < rowptr + rowlen && byteptr < srcstp; byteptr++ ) {
94#define hexdump(src,srclen,rowlen,rows) ((void)0)
103static const char *VENDOR_NAMES[] = {
104 "?",
"CATC-Netmate",
"Belkin/CATC",
"Yikes!"
107static const int ID_TBL[] = {
128static int catc_send_eth_frame(
void *ctx,
hsaddr_t buf,
int len );
129static int catc_get_eth_frame(
void *ctx,
hsaddr_t buf );
130static int catc_data_rx(
void *ctx );
131static int catc_get_dev_addr(
void *ctx,
hsaddr_t mac_addr );
171 const int *
ptr=ID_TBL;
173 unsigned char *mcast_tbl;
181 while( *
ptr != -1 ) {
182 if( (vendor_id ==
ptr[0]) && (product_id ==
ptr[1]) ) {
189 xprintf(
"Unrecognized CATC USB-Ethernet device\n" );
205 memset( mcast_tbl, 0, 64 );
206 mcast_tbl[31] = 0x80;
211 catc_get_mac_addr( dev, softc->
mac_addr );
214 xprintf(
"%s USB-Ethernet Adapter (%a)\n",
220static int catc_get_dev_addr(
void *ctx,
hsaddr_t mac_addr )
223 hs_memcpy_to_hs( mac_addr, softc->
mac_addr, 6 );
235static int catc_data_rx(
void *ctx )
242static int catc_get_eth_frame(
void *ctx,
hsaddr_t buf )
249 rxbuf = softc->
rxbuf;
253 xprintf(
"Incoming packet :\n" );
254 hexdump( rxbuf, len, 16, len / 16 + 1 );
256 hs_memcpy_to_hs( buf, rxbuf, len );
259 catc_queue_rx( softc );
262 xprintf(
"Bulk data is not available yet!\n" );
267static int catc_send_eth_frame(
void *ctx,
hsaddr_t buf,
int len )
272 unsigned char *txbuf;
275 txbuf[0] = txlen & 0xff;
276 txbuf[1] = (txlen >> 8) & 0xff;
277 hs_memcpy_from_hs( &txbuf[2], buf, txlen );
280 xprintf(
"Outgoing packet :\n" );
281 hexdump( txbuf, txlen, 16, txlen / 16 + 1 );
296 for(i = 0; i < 6; ++i)
303 catc_queue_rx( softc );
349 if( softc ==
NULL ) {
350 xprintf(
"Failed to allocate softc memory.\n" );
358 if (ifdscr ==
NULL) {
359 xprintf(
"USBETH: ERROR...no interace descriptor\n");
363 for (idx = 0; idx < 2; idx++) {
371 if (!indscr || !outdscr) {
376 xprintf(
"USBETH: ERROR...no endpoint descriptors\n");
384 if (catc_init_device(softc) < 0)
395 catc_open_device( softc );
415static int catc_detach(
usbdev_t *dev)
421 catc_close_device ( softc );
444static int catc_ether_open(cfe_devctx_t *ctx)
449 return CFE_ERR_NOTREADY;
452 catc_open_device( softc );
457static int catc_ether_read( cfe_devctx_t *ctx, iocb_buffer_t *buffer )
462 return CFE_ERR_NOTREADY;
464 buffer->buf_retlen = catc_get_eth_frame( softc, buffer->buf_ptr );
470static int catc_ether_inpstat( cfe_devctx_t *ctx, iocb_inpstat_t *inpstat )
475 return CFE_ERR_NOTREADY;
477 inpstat->inp_status = catc_data_rx( softc );
482static int catc_ether_write(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
487 return CFE_ERR_NOTREADY;
490 catc_send_eth_frame( softc, buffer->buf_ptr, buffer->buf_length );
496static int catc_ether_ioctl(cfe_devctx_t *ctx,iocb_buffer_t *buffer)
502 return CFE_ERR_NOTREADY;
504 switch( (
int)buffer->buf_ioctlcmd ) {
505 case IOCTL_ETHER_GETHWADDR:
507 catc_get_dev_addr( softc, buffer->buf_ptr );
509 case IOCTL_ETHER_SETHWADDR:
510 xprintf(
"IOCTL_ETHER_SETHWADDR not implemented.\n" );
513 case IOCTL_ETHER_GETSPEED:
514 xprintf(
"GETSPEED not implemented.\n" );
517 case IOCTL_ETHER_SETSPEED:
518 xprintf(
"SETSPEED not implemented.\n" );
521 case IOCTL_ETHER_GETLINK:
522 xprintf(
"GETLINK not implemented.\n" );
525 case IOCTL_ETHER_GETLOOPBACK:
526 xprintf(
"GETLOOPBACK not implemented.\n" );
529 case IOCTL_ETHER_SETLOOPBACK:
530 xprintf(
"SETLOOPBACK not implemented.\n" );
535 xprintf(
"Invalid IOCTL to catc_ether_ioctl.\n" );
543static int catc_ether_close(cfe_devctx_t *ctx)
548 return CFE_ERR_NOTREADY;
551 catc_close_device( softc );
558const static cfe_devdisp_t catc_ether_dispatch =
572 "USB-Ethernet Device",
575 &catc_ether_dispatch,
usb_driver_t usbcatc_driver
const cfe_driver_t usbcatcdrv
#define hexdump(src, srclen, rowlen, rows)
#define USBETH_TRACE(x, y ...)
struct catc_softc_s catc_softc_t
#define KMALLOC(size, align)
uint8_t bConfigurationValue
usb_config_descr_t * ud_cfgdescr
#define USBREQ_TYPE_VENDOR
#define USB_ENDPOINT_DESCRIPTOR_TYPE
#define USB_ENDPOINT_DIR_OUT(addr)
#define USB_INTERFACE_DESCRIPTOR_TYPE
#define USBREQ_REC_INTERFACE
#define USB_REQUEST_SET_INTERFACE
void * usb_find_cfg_descr(usbdev_t *dev, int dtype, int idx)
int usb_std_request(usbdev_t *dev, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *buffer, int length)
int usb_sync_request(usbreq_t *ur)
usbreq_t * usb_make_request(usbdev_t *dev, int epaddr, uint8_t *buf, int length, int flags)
void usb_free_request(usbreq_t *ur)
void usb_poll(usbbus_t *bus)
int usb_queue_request(usbreq_t *ur)
int usb_get_device_descriptor(usbdev_t *dev, usb_device_descr_t *dscr, int smallflg)
int usb_set_configuration(usbdev_t *dev, int config)
int usb_open_pipe(usbdev_t *dev, usb_endpoint_descr_t *epdesc)
int usbeth_register(usbeth_disp_t *disp, void *softc)
void usbeth_unregister(void *softc)
#define CATC_RX_BUF_CNT_REG
#define CATC_TX_BUF_CNT_REG
#define CATC_ETH_CTRL_REG
#define CATC_ADV_OP_MODES_REG
#define CATC_MCAST_TBL_ADDR
#define CATC_GET_MAC_ADDR
#define CATC_LED_CTRL_REG
#define CATC_ETH_ADDR_0_REG