static int can_xmit(FAR struct can_dev_s *dev) { int tmpndx; int ret = -EBUSY; canllvdbg("xmit head: %d queue: %d tail: %d\n", dev->cd_xmit.tx_head, dev->cd_xmit.tx_queue, dev->cd_xmit.tx_tail); /* If there is nothing to send, then just disable interrupts and return */ if (dev->cd_xmit.tx_head == dev->cd_xmit.tx_tail) { DEBUGASSERT(dev->cd_xmit.tx_queue == dev->cd_xmit.tx_head); dev_txint(dev, false); return -EIO; } /* Check if we have already queued all of the data in the TX fifo. * * tx_tail: Incremented in can_write each time a message is queued in the FIFO * tx_head: Incremented in can_txdone each time a message completes * tx_queue: Incremented each time that a message is sent to the hardware. * * Logically (ignoring buffer wrap-around): tx_head <= tx_queue <= tx_tail * tx_head == tx_queue == tx_tail means that the FIFO is empty * tx_head < tx_queue == tx_tail means that all data has been queued, but * we are still waiting for transmissions to complete. */ while (dev->cd_xmit.tx_queue != dev->cd_xmit.tx_tail && dev_txready(dev)) { /* No.. The FIFO should not be empty in this case */ DEBUGASSERT(dev->cd_xmit.tx_head != dev->cd_xmit.tx_tail); /* Increment the FIFO queue index before sending (because dev_send() * might call can_txdone(). */ tmpndx = dev->cd_xmit.tx_queue; if (++dev->cd_xmit.tx_queue >= CONFIG_CAN_FIFOSIZE) { dev->cd_xmit.tx_queue = 0; } /* Send the next message at the FIFO queue index */ ret = dev_send(dev, &dev->cd_xmit.tx_buffer[tmpndx]); if (ret != OK) { candbg("dev_send failed: %d\n", ret); break; } } /* Make sure that TX interrupts are enabled */ dev_txint(dev, true); return ret; }
void arp_request(__be32 daddr) { struct sk_buff *skb; struct ethhdr *eh; struct arppkt *ah; skb = alloc_skb(&nic); skb->protocol = ETHERTYPE_ARP; skb->len = sizeof(struct arppkt); eh = (struct ethhdr *) (skb->data); ah = (struct arppkt *) (skb->data + ETH_HLEN); skb->data += ETH_HLEN; ah->ar_hrd = htons(ARPHRD_ETHER); ah->ar_pro = htons(ETHERTYPE_IP); ah->ar_hln = ETH_ALEN; ah->ar_pln = 4; ah->ar_op = htons(ARPOP_REQUEST); memcpy(ah->__ar_sha, nic.dev_addr, ETH_ALEN); *(__be32 *)ah->__ar_sip = nic.ip; memset(ah->__ar_tha, 0, ETH_ALEN); *(__be32 *)ah->__ar_tip = daddr; eh->h_proto = htons(skb->protocol); memcpy(eh->h_source, nic.dev_addr, ETH_ALEN); memcpy(eh->h_dest, nic.broadcast, ETH_ALEN); dev_send(skb); }
// Scheduled event int olsrd_pcf_event(int changes_neighborhood, int changes_topology, int changes_hna) { int useless; useless = changes_neighborhood || changes_hna || changes_topology; // useless code to avoid warning with gcc tc_check_data(); dev_send(); return 0; }
void OlsrEventServer::handleAccept(TcpConnectionPtr connectionPtr, const boost::system::error_code& error) { if (!error) { SER_PRINTF("Got new connection"); EventListenerPtr newListener(new EventListener(connectionPtr, eventListenerManager_)); newListener->start(); dev_send_init(); tc_send_all_data(); dev_send(); // Waiting for new connection again waitForConnection(); } }
void dev_send_init(void) { union olsr_ip_addr* addr, mask; struct interface* ifs; //------------------------------ // reset sereadmo iptable module //------------------------------ dev_add_cmd(DEV_CMD_RESET_TC,NULL,NULL,0); //------------------ // send local config //------------------ //main addr (ie. addr used by olsrd in links for local node) addr = &olsr_cnf->main_addr; // retreive IP mask for the main addr for(ifs = ifnet; ifs != NULL; ifs = ifs->int_next) { if(ipequal(addr,&ifs->ip_addr) != 0) { mask.v4.s_addr = ifs->int_netmask.sin_addr.s_addr; break; } } dev_add_cmd(DEV_CMD_SET_LOCAL_ADDR,addr,&mask,0); //---------------- // send addr alias //---------------- for(ifs = ifnet; ifs != NULL; ifs = ifs->int_next) { if(ipequal(addr,&ifs->ip_addr) == 0) { mask.v4.s_addr = ifs->int_netmask.sin_addr.s_addr; dev_add_cmd(DEV_CMD_SET_ALIAS_ADDR,&ifs->ip_addr,&mask,0); } } dev_send(); }
void *do_arp_queue(void *arg) { struct sk_buff *skb; for (;;) { pthread_mutex_lock(&arp_mutex_lock); /* while empty? */ /* and change to timewait? */ pthread_cond_wait(&arp_queue_check, &arp_mutex_lock); pthread_mutex_unlock(&arp_mutex_lock); while ((skb = skb_dequeue(&arp_queue)) != NULL) { /* should I only wake up which with arp request */ /* skb->data += ETH_HLEN; */ /* skb->len += ETH_HLEN; */ dev_send(skb); } } return 0; }
/*-----------------------------------------------------------------------------------*/ int main(void) { idata u8_t i, arptimer; idata u16_t j; // idata int i; InitGraphic();//putchar(0,62,0); //while(1) for(i=0;i<100;i++) { putstring(6,0, "Welcome to http://shop34480016.taobao.com www.dianshijin.cn"); } init_uart(); printu("starting......\r\n"); /* Initialize the device driver. */ // rtl8019as_init(); dev_init(); uip_arp_init(); /* Initialize the uIP TCP/IP stack. */ uip_init(); printu("11111111111111111111111\r\n"); /* Initialize the HTTP server. */ // httpd_init(); tcp_server_init(); arptimer = 0; printu("222222222222222222222222222\r\n"); while(1) { /* Let the tapdev network device driver read an entire IP packet into the uip_buf. If it must wait for more than 0.5 seconds, it will return with the return value 0. If so, we know that it is time to call upon the uip_periodic(). Otherwise, the tapdev has received an IP packet that is to be processed by uIP. */ uip_len = dev_poll(); for(j=0;j<500;j++); /* if(uip_len > 0) { printuf("--------------- uip_len = 0x%x", uip_len); printuf("%x ----------\r\n", uip_len); for(i=0;i<uip_len;i++) { printuf("%x ", uip_buf[i]); if((i+1)%16==0) printu("\r\n"); } printu("\r\n"); } */ if(uip_len == 0) { for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(++arptimer == 20) { uip_arp_timer(); arptimer = 0; } } else { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { dev_send(); } } } } return 0; }
void arp_rcv(struct sk_buff *skb) { struct arppkt *ap; struct ethhdr *eh; unsigned int tip, sip; struct arptab *h; int hl; struct net_device *nic; hl = sizeof(struct ethhdr); skb->len -= hl; ap = (struct arppkt *) skb->data; skb->nh.arph = (struct arphdr *) skb->data; eh = (struct ethhdr *) (skb->data - hl); nic = skb->nic; /* skb->data += sizeof(struct arphdr); */ printf("--- ARP: packet received\n"); if (ap->ar_hrd != htons(ARPHRD_ETHER) || ap->ar_pro != htons(ETHERTYPE_IP) || ap->ar_hln != ETH_ALEN || ap->ar_pln != 4) goto bad; switch (ntohs(ap->ar_op)) { case ARPOP_REQUEST: tip = *(unsigned int *)ap->__ar_tip; sip = *(unsigned int *)ap->__ar_sip; if (tip != skb->nic->ip) goto drop; ap->ar_op = htons(ARPOP_REPLY); *(unsigned int *)ap->__ar_sip = skb->nic->ip; *(unsigned int *)ap->__ar_tip = sip; memcpy(ap->__ar_sha, skb->nic->dev_addr, ETH_ALEN); memcpy(ap->__ar_tha, eh->h_source, ETH_ALEN); memcpy(eh->h_dest, eh->h_source, ETH_ALEN); memcpy(eh->h_source, skb->nic->dev_addr, ETH_ALEN); skb->len +=14; skb->ip_summed = 0; skb->protocol = ETHERTYPE_ARP; dev_send(skb); goto reused; break; case ARPOP_REPLY: sip = *(unsigned int *)ap->__ar_sip; tip = *(unsigned int *)ap->__ar_tip; pthread_spin_lock(&arp_lock); h = &arp_table[arp_hash(sip)]; if (/* h->ip == sip && */ nic->ip == tip) { if (ap->__ar_sha[0] & 1) /* why? */ goto unlock_bad; memcpy(h->mac, ap->__ar_sha, ETH_ALEN); /* if (h->hold && (tv.tv_sec - h->time > ARP_MAX_HOLD)) */ /* { */ /* skb_free(h->hold); */ /* h->hold = NULL; */ /* } */ h->time = get_second(); if (h->status == ARP_STATUS_REQUEST) { h->status = ARP_STATUS_OK; pthread_spin_unlock(&arp_lock); pthread_cond_signal(&arp_queue_check); } else { /* received broadcast reply who was not requested */ h->status = ARP_STATUS_OK; pthread_spin_unlock(&arp_lock); } /* if ((skb = h->hold)) */ /* { */ /* h->hold = NULL; */ /* memcpy(eh->h_dest, h->mac, ETH_ALEN); */ /* pthread_spin_unlock(&arp_lock); */ /* /\* fragmentation? *\/ */ /* dev_send(skb); */ /* } */ /* else */ /* pthread_spin_unlock(&arp_lock); */ } else { goto unlock_bad; } break; default: goto bad; } reused: return; bad: printf("arp: packet invalid\n"); drop: skb_free(skb); return; unlock_bad: pthread_spin_unlock(&arp_lock); skb_free(skb); }