⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network.c

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifdef DEBUG_INIT_2  printf("\nTransmitter adds packet\n");  print_hdr    ( sc->pTxCmd->pTbd->data ); /* print the first part */  print_pkt    ( sc->pTxCmd->pTbd->next->data ); /* print the first part */  /*  print_echo(sc->pTxCmd->pTbd->data); */#endif#ifdef DBG_VERSION	  BREAKPOINT();#endif  /* add the command to the output command queue */  uti596addCmd ( (struct i596_cmd *) sc->pTxCmd );    /* sleep until the command has been processed or Timeout encountered. */  status= rtems_bsdnet_event_receive (INTERRUPT_EVENT,				      RTEMS_WAIT|RTEMS_EVENT_ANY,				      RTEMS_NO_TIMEOUT,				      &events);     if ( status != RTEMS_SUCCESSFUL ) {    printf("Could not sleep %s\n", rtems_status_text(status));   }  #ifdef DBG_RAW  printf("RAW: wake\n");#endif    sc->txInterrupts++;      #ifdef DEBUG_INIT  printf("\nTransmitter issued packet\n");  print_hdr    ( sc->pTxCmd->pTbd -> data ); /* print the first part */  print_pkt    ( sc->pTxCmd->pTbd ->next-> data ); /* print the first part */#endif  if ( sc->pTxCmd -> cmd.status & STAT_OK )    sc->stats.tx_packets++;  else    {#ifdef DBG_RAW      printf("******Driver Error 0x%x\n", sc->pTxCmd -> cmd.status );#endif      sc->stats.tx_errors++;      if ( sc->pTxCmd->cmd.status  & 0x0020 ) 	sc->stats.tx_retries_exceeded++;      if (!(sc->pTxCmd->cmd.status & 0x0040)) 	sc->stats.tx_heartbeat_errors++;      if ( sc->pTxCmd->cmd.status  & 0x0400 ) 	sc->stats.tx_carrier_errors++;      if ( sc->pTxCmd->cmd.status  & 0x0800 ) 	sc->stats.collisions++;      if ( sc->pTxCmd->cmd.status  & 0x1000 ) 	sc->stats.tx_aborted_errors++;    } /* end if stat_ok */	     /*    * Restore the transmited buffer descriptor chain.   */  pTbd -> next = pRemainingTbdList;    /*   * Free the mbufs used by the sender.   */  m = input_m;  while ( m != NULL ) {    MFREE(m,n);    m = n;  }  } /***********************************************************************  *  Function:   print_eth  *  *  Description:  *              Print the contents of an ethernet packet header  *              CANNOT BE CALLED FROM ISR  *  *  Algorithm:  *            Print Destination, Src, and type of packet  *  ***********************************************************************/ /* static */ void print_eth(unsigned char *add) {     int i;     short int length;     printf("Packet Location %p\n", add);     printf ("Dest  ");     for (i = 0; i < 6; i++)	 printf(" %2.2X", add[i]);     printf ("\n");     printf ("Source");     for (i = 6; i < 12; i++)	 printf(" %2.2X", add[i]);     printf ("\n");     printf ("frame type %2.2X%2.2X\n", add[12], add[13]);     if ( add[12] == 0x08 && add[13] == 0x06 )       { /* an ARP */	 printf("Hardware type : %2.2X%2.2X\n", add[14],add[15]);	 printf("Protocol type : %2.2X%2.2X\n", add[16],add[17]);	 printf("Hardware size : %2.2X\n", add[18]);	 printf("Protocol size : %2.2X\n", add[19]);	 printf("op            : %2.2X%2.2X\n", add[20],add[21]);	 printf("Sender Enet addr: ");	 for ( i=0; i< 5 ; i++)	   printf( "%x:", add[22 + i]);	 printf("%x\n", add[27]);	 printf("Sender IP addr: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[28 + i]);	 printf("%u\n", add[31]);	 printf("Target Enet addr: ");	 for ( i=0; i< 5 ; i++)	   printf( "%x:", add[32 + i]);	 printf("%x\n", add[37]);	 printf("Target IP addr: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[38 + i]);	 printf("%u\n", add[41]);	}     if ( add[12] == 0x08 && add[13] == 0x00 )       { /* an IP packet */	 printf("*********************IP HEADER******************\n");	 printf("IP version/IPhdr length: %2.2X TOS: %2.2X\n", add[14] , add[15]);	 printf("IP total length: %2.2X %2.2X, decimal %d\n", add[16], add[17], length = (add[16]<<8 | add[17] )); 	 printf("IP identification: %2.2X %2.2X, 3-bit flags and offset %2.2X %2.2X\n",		add[18],add[19], add[20], add[21]);	 printf("IP TTL: %2.2X, protocol: %2.2X, checksum: %2.2X %2.2X \n",		add[22],add[23],add[24],add[25]);	 printf("IP packet type: %2.2X code %2.2X\n", add[34],add[35]);	 printf("Source IP address: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[26 + i]);	 printf("%u\n", add[29]);	 printf("Destination IP address: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[30 + i]);	 printf("%u\n", add[33]);	 /* printf("********************IP Packet Data*******************\n");	 	 length -=20;	 for ( i=0; i < length ; i++)	   printf("0x%2.2x ", add[34+i]);	 printf("\n");	 printf("ICMP checksum: %2.2x %2.2x\n", add[36], add[37]);	 printf("ICMP identifier: %2.2x %2.2x\n", add[38], add[39]);	 printf("ICMP sequence nbr: %2.2x %2.2x\n", add[40], add[41]);	 */	} }#ifdef DEBUG_INIT /***********************************************************************  *  Function:   print_eth  *  *  Description:  *              Print the contents of an ethernet packet header  *              CANNOT BE CALLED FROM ISR  *  *  Algorithm:  *            Print Destination, Src, and type of packet  *  ***********************************************************************/ /* static */ void print_hdr(unsigned char *add) {     int i;     short int length;     printf("Header Location %p\n", add);     printf ("Dest  ");     for (i = 0; i < 6; i++)	 printf(" %2.2X", add[i]);     printf ("\n");     printf ("Source");     for (i = 6; i < 12; i++)	 printf(" %2.2X", add[i]);     printf ("\n");     printf ("frame type %2.2X%2.2X\n", add[12], add[13]); } /***********************************************************************  *  Function:   print_pkt  *  *  Description:  *              Print the contents of an ethernet packet header  *              CANNOT BE CALLED FROM ISR  *  *  Algorithm:  *            Print Destination, Src, and type of packet  *  ***********************************************************************/ /* static */ void print_pkt(unsigned char *add) {     int i;     short int length;     printf("Data Location %p\n", add);     if ( add[0] == 0x08 && add[1] == 0x06 )       { /* an ARP */	 printf("Hardware type : %2.2X%2.2X\n", add[14],add[15]);	 printf("Protocol type : %2.2X%2.2X\n", add[16],add[17]);	 printf("Hardware size : %2.2X\n", add[18]);	 printf("Protocol size : %2.2X\n", add[19]);	 printf("op            : %2.2X%2.2X\n", add[20],add[21]);	 printf("Sender Enet addr: ");	 for ( i=0; i< 5 ; i++)	   printf( "%x:", add[22 + i]);	 printf("%x\n", add[27]);	 printf("Sender IP addr: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[28 + i]);	 printf("%u\n", add[31]);	 printf("Target Enet addr: ");	 for ( i=0; i< 5 ; i++)	   printf( "%x:", add[32 + i]);	 printf("%x\n", add[37]);	 printf("Target IP addr: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[38 + i]);	 printf("%u\n", add[41]);	}     if ( add[0] == 0x08 && add[1] == 0x00 )       { /* an IP packet */	 printf("*********************IP HEADER******************\n");	 printf("IP version/IPhdr length: %2.2X TOS: %2.2X\n", add[14] , add[15]);	 printf("IP total length: %2.2X %2.2X, decimal %d\n", add[16], add[17], length = (add[16]<<8 | add[17] )); 	 printf("IP identification: %2.2X %2.2X, 3-bit flags and offset %2.2X %2.2X\n",		add[18],add[19], add[20], add[21]);	 printf("IP TTL: %2.2X, protocol: %2.2X, checksum: %2.2X %2.2X \n",		add[22],add[23],add[24],add[25]);	 printf("IP packet type: %2.2X code %2.2X\n", add[34],add[35]);	 printf("Source IP address: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[26 + i]);	 printf("%u\n", add[29]);	 printf("Destination IP address: ");	 for ( i=0; i< 3 ; i++)	   printf( "%u.", add[30 + i]);	 printf("%u\n", add[33]);	 printf("********************IP Packet Data*******************\n");	 length -=20;	 for ( i=0; i < length ; i++)	   printf("0x%2.2x ", add[34+i]);	 printf("\n");	 printf("ICMP checksum: %2.2x %2.2x\n", add[36], add[37]);	 printf("ICMP identifier: %2.2x %2.2x\n", add[38], add[39]);	 printf("ICMP sequence nbr: %2.2x %2.2x\n", add[40], add[41]);	} } /***********************************************************************  *  Function:   print_echo  *  *  Description:  *              Print the contents of an ethernet packet header  *              CANNOT BE CALLED FROM ISR  *  *  Algorithm:  *            Prints only echo packets  *  ***********************************************************************/ /* static */ void print_echo(unsigned char *add) {     int i;     short int length;     if ( add[12] == 0x08 && add[13] == 0x00 ){ /* an IP packet */              printf("Packet Location %p\n", add);              printf ("Dest  ");              for (i = 0; i < 6; i++)	 printf(" %2.2X", add[i]);              printf ("\n");              printf ("Source");              for (i = 6; i < 12; i++)	 printf(" %2.2X", add[i]);              printf ("\n");              printf ("frame type %2.2X%2.2X\n", add[12], add[13]);              printf("*********************IP HEADER******************\n");       printf("IP version/IPhdr length: %2.2X TOS: %2.2X\n", add[14] , add[15]);       printf("IP total length: %2.2X %2.2X, decimal %d\n", add[16], add[17], length = (add[16]<<8 | add[17] ));        printf("IP identification: %2.2X %2.2X, 3-bit flags and offset %2.2X %2.2X\n",	      add[18],add[19], add[20], add[21]);       printf("IP TTL: %2.2X, protocol: %2.2X, checksum: %2.2X %2.2X \n",	      add[22],add[23],add[24],add[25]);       printf("IP packet type: %2.2X code %2.2X\n", add[34],add[35]);              printf("Source IP address: ");       for ( i=0; i< 3 ; i++)	 printf( "%u.", add[26 + i]);              printf("%u\n", add[29]);              printf("Destination IP address: ");       for ( i=0; i< 3 ; i++)	 printf( "%u.", add[30 + i]);       printf("%u\n", add[33]);              printf("********************IP Packet Data*******************\n");       length -=20;       for ( i=0; i < length ; i++)	 printf("0x%2.2x ", add[34+i]);       printf("\n");              printf("ICMP checksum: %2.2x %2.2x\n", add[36], add[37]);       printf("ICMP identifier: %2.2x %2.2x\n", add[38], add[39]);       printf("ICMP sequence nbr: %2.2x %2.2x\n", add[40], add[41]);     }    }#endif  /***********************************************************************  *  Function:   uti596_attach  *  *  Description:  *              User requested attach of driver to hardware  *  *  Algorithm:  *  *              Check that the board is present  *              parse and store the command line parameters  *                 argv[0]: interface label, e.g., "uti596"  *                 argv[1]: maximum transmission unit, bytes, e.g., "1500"  *                 argv[2]: IP address (optional)  *              initialize required rx and tx buffers  *              hook interrupt  *              issue start command and some diagnostics  *              return         *  ***********************************************************************/int uti596_attach(struct rtems_bsdnet_ifconfig * pConfig ){  struct uti596_softc *sc = &uti596_softc;          /* soft config */  struct ifnet * ifp = &sc->arpcom.ac_if;  int i = 0;  #ifdef DBG_ATTACH  printf("attach");#endif    sc->started = 0; /* The NIC is not started yet */  sc->ioAddr = IO_ADDR;  /* Indicate to ULCS that this is initialized */    ifp->if_softc = sc;    sc -> pScp = NULL;    /* Assign the name */  ifp->if_name = "uti";    /* Assign the unit number */  ifp->if_unit = 1;    /* Assign mtu */  if ( pConfig -> mtu )    ifp->if_mtu = pConfig -> mtu;  else    ifp->if_mtu = ETHERMTU;    /* Assign and possibly override the hw address */  if ( !pConfig->hardware_address) { /* Read the ethernet address from the board */    for (i = 0; i < 8; i++)      inport_byte(NIC_ADDR+i,sc->arpcom.ac_enaddr[i] );  }  else {    /* hwaddr override */     memcpy (sc->arpcom.ac_enaddr, pConfig->hardware_address, ETHER_ADDR_LEN);  }    /* Test for valid hwaddr */  if(memcmp(sc->arpcom.ac_enaddr,"\xAA\x55\x01",3)!= 0)/* b0 of byte 0 != 0 => multicast */    return ENODEV;    /* Assign requested receive buffer descriptor count */  if (pConfig->rbuf_count)    sc->rxBdCount = pConfig->rbuf_count;  else    sc->rxBdCount = RX_BUF_COUNT;  /* Assign requested tx buffer descriptor count */  if (pConfig->xbuf_count)    sc->txBdCount = pConfig->xbuf_count;  else    sc->txBdCount = TX_BUF_COUNT * TX_BD_PER_BUF;  /* ignore_broadcast is an unused feature... accept broadcast */  /* sc->acceptBroadcast = !pConfig->ignore_broadcast; */  ifp->if_snd.ifq_maxlen = ifqmaxlen;  ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;  /* to init_hardware */  sc->started = 1;  sc->pInboundFrameQueue = I596_NULL;    ifp->if_ioctl = uti596_ioctl;  ifp->if_init  = uti596_init;  ifp->if_start    = uti596_start;  ifp->if_output   = ether_output;    sc->scb.command = 0;    /*   * Attach the interface   */  if_attach (ifp);  ether_ifattach (ifp);  return 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -