Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

rt_rtl8139.c File Reference

#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include "netif/etharp.h"
#include "netif/rt_rtl8139_exports.h"
#include "netif/ethernetif.h"
#include <unistd.h>
#include "bcopy.h"
#include <signal.h>
#include <rtl_sema.h>

Include dependency graph for rt_rtl8139.c:

Go to the source code of this file.

Data Structures

struct  rt_rtl8139if

Defines

#define IFNAME0   'e'
#define IFNAME1   't'
#define RTL8139_SIGNAL   RTL_SIGUSR1

Functions

void rt_rtl8139if_input (struct pbuf *p, struct netif *netif)
err_t rt_rtl8139if_output (struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
void rt_rtl8139if_ethernetif_thread (void *arg)
void rt_rtl8139if_low_level_init (struct netif *netif)
err_t rt_rtl8139if_low_level_output (struct netif *rt_rtl8139if, struct pbuf *p)
pbufrt_rtl8139if_low_level_input (struct rt_rtl8139if *rt_rtl8139if)
void rt_rtl8139_ifetharp_timer (int signo)
err_t rt_rtl8139if_init (struct netif *netif)
void rt_rtl8139if_close (void)

Variables

ethernetif_thread_t rtl8139_thread
const struct eth_addr rt_rtl8139if_ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}
int rt_rtl8139if_fd
netifrt_rtl8139if_netif


Define Documentation

#define IFNAME0   'e'
 

Definition at line 101 of file rt_rtl8139.c.

#define IFNAME1   't'
 

Definition at line 102 of file rt_rtl8139.c.

#define RTL8139_SIGNAL   RTL_SIGUSR1
 

Definition at line 103 of file rt_rtl8139.c.


Function Documentation

void rt_rtl8139_ifetharp_timer int  signo  ) 
 

Definition at line 314 of file rt_rtl8139.c.

References ARP_TMR_INTERVAL, etharp_tmr(), NULL, rt_rtl8139_ifetharp_timer(), sys_timeout(), and sys_timeout_handler.

Referenced by rt_rtl8139_ifetharp_timer(), and rt_rtl8139if_init().

00315 {
00316   etharp_tmr();
00317   sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler) rt_rtl8139_ifetharp_timer, NULL);
00318 }

Here is the call graph for this function:

void rt_rtl8139if_close void   ) 
 

Definition at line 357 of file rt_rtl8139.c.

References rt_rtl8139if_fd.

00357                              {
00358   /* Closing the RTL8139 card */
00359   close(rt_rtl8139if_fd);
00360 }

void rt_rtl8139if_ethernetif_thread void *  arg  )  [static]
 

Definition at line 148 of file rt_rtl8139.c.

References NULL, rt_rtl8139if_input(), and rt_rtl8139if_netif.

Referenced by rt_rtl8139if_low_level_init().

00148                                                      {
00149   struct sched_param p;
00150 
00151   p . sched_priority = 100000;
00152   pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);
00153 
00154   do{
00155     rt_rtl8139if_input(NULL, rt_rtl8139if_netif);  
00156   }while(1);
00157 }

Here is the call graph for this function:

err_t rt_rtl8139if_init struct netif netif  ) 
 

Definition at line 331 of file rt_rtl8139.c.

References ARP_TMR_INTERVAL, ERR_OK, etharp_init(), netif::hwaddr, netif::hwaddr_len, IFNAME0, IFNAME1, netif::linkoutput, mem_malloc(), netif::name, NULL, netif::output, rt_rtl8139_ifetharp_timer(), rt_rtl8139if_low_level_init(), rt_rtl8139if_low_level_output(), rt_rtl8139if_netif, rt_rtl8139if_output(), netif::state, sys_timeout(), and sys_timeout_handler.

00332 {
00333   struct rt_rtl8139if *rt_rtl8139if;
00334     
00335   rt_rtl8139if = mem_malloc(sizeof(struct rt_rtl8139if));
00336   netif->state = rt_rtl8139if;
00337   netif->name[0] = IFNAME0;
00338   netif->name[1] = IFNAME1;
00339   netif->output = rt_rtl8139if_output;
00340   netif->linkoutput = rt_rtl8139if_low_level_output;
00341   
00342   rt_rtl8139if->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
00343   netif->hwaddr_len = 6;
00344 
00345   rt_rtl8139if_netif = netif; 
00346 
00347   rt_rtl8139if_low_level_init(netif);
00348   etharp_init();
00349 
00350   sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)rt_rtl8139_ifetharp_timer, NULL);
00351 
00352   return ERR_OK;
00353 }

Here is the call graph for this function:

void rt_rtl8139if_input struct pbuf p,
struct netif netif
[static]
 

Definition at line 280 of file rt_rtl8139.c.

References etharp_arp_input(), etharp_ip_input(), ETHTYPE_ARP, ETHTYPE_IP, htons, netif::input, NULL, pbuf_free(), pbuf_header(), rt_rtl8139if_low_level_input(), rt_rtl8139if_low_level_output(), and netif::state.

Referenced by rt_rtl8139if_ethernetif_thread().

00281 {
00282 
00283   /* Ethernet protocol layer */
00284   struct eth_hdr *ethhdr;
00285   struct rt_rtl8139if *rt_rtl8139if = netif->state;
00286   struct pbuf *q = NULL , *p = NULL;
00287   
00288   p = rt_rtl8139if_low_level_input(rt_rtl8139if);
00289 
00290   ethhdr = p->payload;
00291   
00292   switch(htons(ethhdr->type)) {
00293   case ETHTYPE_IP:
00294     q = etharp_ip_input(netif, p);
00295     pbuf_header(p, -14);
00296     netif->input(p, netif);
00297     break;
00298   case ETHTYPE_ARP:
00299     q = etharp_arp_input(netif, rt_rtl8139if->ethaddr, p);
00300     break;
00301   default:
00302     pbuf_free(p);
00303     break;
00304   }
00305   if(q != NULL) {
00306 
00307     rt_rtl8139if_low_level_output(netif, q);
00308 
00309     pbuf_free(q);
00310   }
00311 }

Here is the call graph for this function:

void rt_rtl8139if_low_level_init struct netif netif  )  [static]
 

Definition at line 123 of file rt_rtl8139.c.

References ip_addr::addr, netif::ip_addr, rt_rtl8139if_ethernetif_thread(), rt_rtl8139if_fd, RTL_RTL8139_NAME, netif::state, and sys_thread_new().

Referenced by rt_rtl8139if_init().

00124 {
00125   struct rt_rtl8139if *rt_rtl8139if;
00126   char dev_name[]={"/dev/rtl0"};
00127   
00128   rt_rtl8139if = netif->state;
00129   
00130   /* Do whatever else is needed to initialize interface. */  
00131   if((rt_rtl8139if_fd=open(dev_name,0)) == -1)
00132     rtl_printf("ERROR OPENING /dev/%s0\n",RTL_RTL8139_NAME);
00133 
00134   /* Obtain MAC address from network interface. */
00135   ioctl(rt_rtl8139if_fd, 2, (unsigned long) rt_rtl8139if->ethaddr->addr);
00136 
00137   /* We set an IP filter to the ethernet card */
00138   ioctl(rt_rtl8139if_fd, 1, (unsigned long) netif->ip_addr.addr);
00139 
00140 //  rtl_printf("ADRESS: %x:%x:%x:%x:%x:%x \n",rt_rtl8139if->ethaddr->addr[0],rt_rtl8139if->ethaddr->addr[1],rt_rtl8139if->ethaddr->addr[2],rt_rtl8139if->ethaddr->addr[3],rt_rtl8139if->ethaddr->addr[4],rt_rtl8139if->ethaddr->addr[5]);
00141 
00142   sys_thread_new(rt_rtl8139if_ethernetif_thread, netif, 0);
00143 
00144   return ;
00145 }

Here is the call graph for this function:

struct pbuf* rt_rtl8139if_low_level_input struct rt_rtl8139if rt_rtl8139if  )  [static]
 

Definition at line 213 of file rt_rtl8139.c.

References bcopy(), len, NULL, pbuf_alloc(), PBUF_LINK, PBUF_POOL, rt_rtl8139if_fd, sys_arch_close(), and u16_t.

Referenced by rt_rtl8139if_input().

00214 {
00215   struct pbuf *p, *q;
00216   struct memory receive_buffer;
00217   unsigned char *bufptr;
00218   u16_t len;
00219   
00220   /* Obtain the size of the packet and put it into the "len"
00221      variable. */
00222   len = read(rt_rtl8139if_fd,(void *) &receive_buffer,1536);
00223   
00224   /* We allocate a pbuf chain of pbufs from the pool. */
00225   p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL);
00226   
00227   if(p != NULL) {
00228     /* We iterate over the pbuf chain until we have read the entire
00229        packet into the pbuf. */
00230     bufptr = receive_buffer.mem;
00231     for(q = p; q != NULL; q = q->next) {
00232       /* Read enough bytes to fill this pbuf in the chain. The
00233          avaliable data in the pbuf is given by the q->len
00234          variable. */
00235       bcopy(bufptr, q->payload, q->len);
00236       bufptr += q->len;
00237     }
00238   } else {
00239     rtl_printf("ERROR:Not enough memory!!!\n");
00240     sys_arch_close();
00241   }
00242 
00243   return p;  
00244 }

Here is the call graph for this function:

err_t rt_rtl8139if_low_level_output struct netif rt_rtl8139if,
struct pbuf p
 

Definition at line 171 of file rt_rtl8139.c.

References bcopy(), ERR_OK, NULL, and rt_rtl8139if_fd.

Referenced by rt_rtl8139if_init(), rt_rtl8139if_input(), and rt_rtl8139if_output().

00172 {
00173 
00174   struct pbuf *q;
00175   unsigned char buf[1536];
00176   unsigned char *bufptr;  
00177 
00178   //initiate transfer;
00179   bufptr = buf;  
00180 
00181   
00182   for(q = p; q != NULL; q = q->next) {
00183     /* Send the data from the pbuf to the interface, one pbuf at a
00184        time. The size of the data in each pbuf is kept in the ->len
00185        variable. */
00186     bcopy(q->payload, bufptr, q->len);
00187     bufptr += q->len;
00188   }
00189 
00190   //signal that packet should be sent;
00191   {
00192     int tmp;
00193     int counter=0;
00194  
00195     while((tmp = write(rt_rtl8139if_fd,buf,p->tot_len)) == -1){
00196       counter++;
00197       usleep(1);  
00198     }
00199   }
00200   
00201   return ERR_OK;
00202 }

Here is the call graph for this function:

err_t rt_rtl8139if_output struct netif netif,
struct pbuf p,
struct ip_addr ipaddr
[static]
 

Definition at line 256 of file rt_rtl8139.c.

References ERR_OK, etharp_output(), ipaddr, NULL, and rt_rtl8139if_low_level_output().

Referenced by rt_rtl8139if_init().

00258 {
00259   
00260   p = etharp_output(netif, ipaddr, p);
00261   if(p != NULL) {
00262     rt_rtl8139if_low_level_output(netif, p);
00263   }
00264   return ERR_OK;
00265 }

Here is the call graph for this function:


Variable Documentation

const struct eth_addr rt_rtl8139if_ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}} [static]
 

Definition at line 111 of file rt_rtl8139.c.

int rt_rtl8139if_fd [static]
 

Definition at line 112 of file rt_rtl8139.c.

Referenced by rt_rtl8139if_close(), rt_rtl8139if_low_level_init(), rt_rtl8139if_low_level_input(), and rt_rtl8139if_low_level_output().

struct netif* rt_rtl8139if_netif [static]
 

Definition at line 113 of file rt_rtl8139.c.

Referenced by rt_rtl8139if_ethernetif_thread(), and rt_rtl8139if_init().

ethernetif_thread_t rtl8139_thread
 

Definition at line 105 of file rt_rtl8139.c.


Generated on Wed Jan 14 12:59:09 2004 for RTL-lwIP-0.4 by doxygen 1.3.4