static uint8_t network_send(void) { #if TCPDUMP printf_P(PSTR("OUT: ")); tcpdump(uip_buf, uip_len); #endif #if CONFIG_DRIVERS_ENC28J60 if (uip_len <= UIP_LLH_LEN + 40) { enc28j60PacketSend( uip_len, (uint8_t *)uip_buf, 0, 0); } else { enc28j60PacketSend( 54, (uint8_t *)uip_buf, uip_len - UIP_LLH_LEN - 40, (uint8_t*)uip_appdata); } #endif #if CONFIG_DRIVERS_ENC424J600 enc424j600PacketSend(uip_len, (uint8_t *)uip_buf); #endif uip_len = 0; return 0; }
void network_send(void){ if(uip_len <= UIP_LLH_LEN + 40){ enc28j60PacketSend(uip_len, (uint8_t *)uip_buf, 0, 0); }else{ enc28j60PacketSend(54, (uint8_t *)uip_buf , uip_len - UIP_LLH_LEN - 40, (uint8_t*)uip_appdata); } }
void NanodeUIP::poll(void) { int i; uip_len = enc28j60PacketReceive(UIP_BUFSIZE,uip_buf); if(uip_len > 0) { if(BUF->type == UIP_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(); enc28j60PacketSend(uip_len,uip_buf); } } else if(BUF->type == UIP_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) { enc28j60PacketSend(uip_len,uip_buf); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); 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(); enc28j60PacketSend(uip_len,uip_buf); } } #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(); enc28j60PacketSend(uip_len,uip_buf); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } }
/** * This function should do the actual transmission of the packet. The packet is * contained in the pbuf that is passed to the function. This pbuf * might be chained. * * @param netif the lwip network interface structure for this ethernetif * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) * @return ERR_OK if the packet could be sent * an err_t value if the packet couldn't be sent * * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to * strange results. You might consider waiting for space in the DMA queue * to become availale since the stack doesn't retry to send a packet * dropped because of memory failure (except for the TCP timers). */ static err_t low_level_output( struct netif *netif, struct pbuf *p ) /*底层发送数据函数*/ { struct ethernetif *ethernetif = netif->state; struct pbuf *q; int i = 0; err_t xReturn = ERR_OK; #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* Parameter not used. */ for(q = p; q != NULL; q = q->next) { /* Send the data from the pbuf to the interface, one pbuf at a time. The size of the data in each pbuf is kept in the ->len variable. */ memcpy(&Tx_Data_Buf[i], (u8_t*)q->payload, q->len); // ping -t 192.168.1.15 i = i + q->len; } enc28j60PacketSend(i,Tx_Data_Buf); //发送数据包 #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif return xReturn; }
static err_t low_level_output(struct netif *netif, struct pbuf *p) { struct ethernetif *ethernetif = netif->state; struct pbuf *q; #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif enc28j60BeginPacketSend(p->tot_len); for(q = p; q != NULL; q = q->next) { /* Send the data from the pbuf to the interface, one pbuf at a time. The size of the data in each pbuf is kept in the ->len variable. */ enc28j60PacketSend(q->payload, q->len); } enc28j60EndPacketSend(); #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.xmit); return ERR_OK; }
static err_t PacketSend (struct pbuf *p) { struct pbuf *q = NULL; unsigned int templen = 0; for(q = p;q!=NULL;q = q->next) { memcpy(&MySendbuf[templen],q->payload,q->len); //将pbuf中的数据拷贝到全局数组MyDatabuf中 templen += q->len ; if(templen > 1500 || templen > p->tot_len) //有效性校验,防止数据溢出 { LWIP_PLATFORM_DIAG(("PacketSend: error,tmplen=%"U32_F",tot_len=%"U32_F"\n\t", templen, p->tot_len)); return ERR_BUF; } } //拷贝完毕,下面进行数据的发送工作 if(templen == p->tot_len) { enc28j60PacketSend(templen, MySendbuf); //调用网卡发送函数 return ERR_OK; } LWIP_PLATFORM_DIAG(("PacketSend: length mismatch ,tmplen=%"U32_F",tot_len=%"U32_F"\n\t", templen, p->tot_len)); return ERR_BUF; }
void nic_send(void) { #if DEBUG_SERIAL printf_P(PSTR("Sending %d bytes\r\n"),(int)uip_len); #endif enc28j60PacketSend((u8 *)uip_buf, uip_len); }
static err_t low_level_output(struct netif *netif, struct pbuf *p) { //static xSemaphoreHandle xTxSemaphore = NULL; struct pbuf *q; //uint32_t l = 0; //u8_t *buffer ; #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* drop the padding word */ #endif enc28j60BeginPacketSend(p->tot_len); for(q = p; q != NULL; q = q->next) { /* Send the data from the pbuf to the interface, one pbuf at a time. The size of the data in each pbuf is kept in the ->len variable. */ enc28j60PacketSend(q->payload, q->len); } enc28j60EndPacketSend(); //LINK_STATS_INC(link.xmit); return ERR_OK; }
void nic_send(void) { #ifdef DEBUG_SERIAL printf("Sending %i bytes\r\n",(int)uip_len); #endif enc28j60PacketSend((u8 *)uip_buf, uip_len); }
void nic_send(void) { if(uip_len<=UIP_BUFSIZE) { // Transfer the message to the Ethernet controller enc28j60PacketSend(uip_len, (U8 *)uip_buf); } }
//Documentation in header file void dhcp_sendDiscover() { //dhcpState = DHCP_STATE_DISCOVER; //Build ethernet header eth_makeHeader(ns.pbuf, ns.MAC, bcastMAC, ETH_IP); //Build IP header ip_makeHeader(ns.pbuf, IP_UDP, zeroIP, bcastIP); //Build UDP header udp_makeHeader(ns.pbuf, DHCP_CLIENT_PORT, DHCP_SERVER_PORT); //Build DHCP Packet dhcp_buildPacket(ns.pbuf); //Fill in op-codes uint8_t *dhcp_op = ns.pbuf+DHCP_OP_START; //Set message type to DHCP_DISCOVER dhcp_op[0] = DHCP_OP_MESSAGETYPE; dhcp_op[1] = 1;//Length dhcp_op[2] = DHCP_STATE_DISCOVER; dhcp_op[3] = DHCP_OP_CLIENTID; dhcp_op[4] = 7;//Length dhcp_op[5] = 0x01;//Hardware type: ethernet for(uint8_t i = 0; i < 6; i++)//Copy MAC dhcp_op[i+6] = ns.MAC[i]; dhcp_op[12] = DHCP_OP_REQIPADDR; dhcp_op[13] = 4;//Length #ifdef SETIP dhcp_op[12] = 192; dhcp_op[13] = 168; dhcp_op[14] = 1; dhcp_op[15] = IP_BASE + tileNum; #else dhcp_op[12] = 0; dhcp_op[13] = 0; dhcp_op[14] = 0; dhcp_op[15] = 0; #endif dhcp_op[16] = DHCP_OP_HOSTNAME; dhcp_op[17] = 3;//Length dhcp_op[18] = 'D'; dhcp_op[19] = 'F'; dhcp_op[20] = ns.MAC[5]; dhcp_op[21] = DHCP_END; ns.plength += 22; udp_setDataLength(ns.pbuf, sizeof(DHCP_Data_t)+22); udp_computeChecksum(ns.pbuf); ip_setDataLength(ns.pbuf, sizeof(UDP_Data_t)+sizeof(DHCP_Data_t)+22); ip_computeChecksum(ns.pbuf); enc28j60PacketSend(ns.pbuf, ns.plength); }
static err_t low_level_2_output(struct netif *netif, struct pbuf *p) { SYS_ARCH_DECL_PROTECT(sr); /* Interrupts are disabled through this whole thing to support multi-threading transmit calls. Also this function might be called from an ISR. */ SYS_ARCH_PROTECT(sr); enc28j60PacketSend(p); SYS_ARCH_UNPROTECT(sr); return ERR_OK; }
/*********************************************************************************** * @fn cc2520_packetReceivedISR * * @brief Interrupt service routine for received frame from radio * (either data or acknowlegdement) * * @param rxi - file scope variable info extracted from the last incoming * frame * txState - file scope variable that keeps tx state info * * @return none */ static void cc2520_packetReceivedISR(void) { uint8_t len; // Clear interrupt and disable new RX frame done interrupt cc2520_disableRxInterrupt(); // Read payload length. cc2520_readRxBuf(&len, 1); len &= CC2520_PLD_LEN_MASK; // Ignore MSB cc2520_readRxBuf(ð_tx_buf[14], len); enc28j60PacketSend(len + 14, ð_tx_buf[0]); // Flush the cc2520 rx buffer to prevent residual data CC2520_SFLUSHRX(); // Enable RX frame done interrupt again cc2520_enableRxInterrupt(); }
void send_udp_transmit(uint8_t *buf,uint16_t datalen) { uint16_t tmp16; tmp16=IP_HEADER_LEN+UDP_HEADER_LEN+datalen; buf[IP_TOTLEN_L_P]=tmp16& 0xff; buf[IP_TOTLEN_H_P]=tmp16>>8; fill_ip_hdr_checksum(buf); tmp16=UDP_HEADER_LEN+datalen; buf[UDP_LEN_L_P]=tmp16& 0xff; buf[UDP_LEN_H_P]=tmp16>>8; // tmp16=checksum(&buf[IP_SRC_P], 16 + datalen,1); buf[UDP_CHECKSUM_L_P]=tmp16& 0xff; buf[UDP_CHECKSUM_H_P]=tmp16>>8; enc28j60PacketSend(UDP_HEADER_LEN+IP_HEADER_LEN+ETH_HEADER_LEN+datalen,buf); }
void client_ntp_request(uint8_t *buf,uint8_t *ntpip,uint8_t srcport,uint8_t *dstmac) { uint8_t i=0; uint16_t ck; // while(i<6){ buf[ETH_DST_MAC +i]=dstmac[i]; // gw mac in local lan or host mac buf[ETH_SRC_MAC +i]=macaddr[i]; i++; } buf[ETH_TYPE_H_P] = ETHTYPE_IP_H_V; buf[ETH_TYPE_L_P] = ETHTYPE_IP_L_V; fill_buf_p(&buf[IP_P],9,iphdr); buf[IP_ID_L_P]=ipid; ipid++; buf[IP_TOTLEN_L_P]=0x4c; buf[IP_PROTO_P]=IP_PROTO_UDP_V; i=0; while(i<4){ buf[IP_DST_P+i]=ntpip[i]; buf[IP_SRC_P+i]=ipaddr[i]; i++; } fill_ip_hdr_checksum(buf); buf[UDP_DST_PORT_H_P]=0; buf[UDP_DST_PORT_L_P]=0x7b; // ntp=123 buf[UDP_SRC_PORT_H_P]=10; buf[UDP_SRC_PORT_L_P]=srcport; // lower 8 bit of src port buf[UDP_LEN_H_P]=0; buf[UDP_LEN_L_P]=56; // fixed len // zero the checksum buf[UDP_CHECKSUM_H_P]=0; buf[UDP_CHECKSUM_L_P]=0; // copy the data: i=0; // most fields are zero, here we zero everything and fill later while(i<48){ buf[UDP_DATA_P+i]=0; i++; } fill_buf_p(&buf[UDP_DATA_P],10,ntpreqhdr); // ck=checksum(&buf[IP_SRC_P], 16 + 48,1); buf[UDP_CHECKSUM_H_P]=ck>>8; buf[UDP_CHECKSUM_L_P]=ck& 0xff; enc28j60PacketSend(90,buf); }
/* * low_level_output(): Should do the actual transmission of the packet. The * packet is contained in the pbuf that is passed to the function. This pbuf * might be chained. */ static err_t low_level_output( struct netif *netif, struct pbuf *p ) /*底层发送数据函数*/ { struct pbuf *q; int i = 0; err_t xReturn = ERR_OK; /* Parameter not used. */ for(q = p; q != NULL; q = q->next) { memcpy(&Tx_Data_Buf[i], (u8_t*)q->payload, q->len); // ping -t 192.168.1.15 i = i + q->len; } enc28j60PacketSend(i,Tx_Data_Buf); //发送数据包 return xReturn; }
void icmp_sendPingReply() { //Temp data uint8_t destMAC[6]; uint8_t destIP[4]; ETH_Data ed = (ETH_Data)(ns.pbuf); IPv4_Data id = (IPv4_Data)(ns.pbuf + sizeof(ETH_Data_t)); ICMP_Data d = (ICMP_Data)(ns.pbuf + sizeof(ETH_Data_t) + sizeof(IPv4_Data_t)); for(uint8_t i = 0; i < 6; i++) destMAC[i] = ed->srcMAC[i]; for(uint8_t i = 0; i < 4; i++) destIP[i] = id->senderIP[i]; for(uint8_t i = 0; i < 6; i++) { ed->srcMAC[i] = ns.MAC[i]; ed->destMAC[i] = destMAC[i]; } for(uint8_t i = 0; i < 4; i++) { id->senderIP[i] = ns.IP[i]; id->targetIP[i] = destIP[i]; } d->type = PING_REPLY; icmp_computeChecksum(); ip_computeChecksum(ns.pbuf); enc28j60PacketSend(ns.pbuf, ns.plength); }
void nicSend(unsigned int len, unsigned char* packet) { enc28j60PacketSend(len, packet); }
void vuIP_TASK( void *pvParameters ) { int i; struct uip_eth_addr MacAddr = *(struct uip_eth_addr *)pvParameters; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); /* Initialise the Enc28j60*/ enc28j60Init(MacAddr.addr); /* Initialize the uIP TCP/IP stack. */ uip_init(); uip_arp_init(); /*init mac addr to uip*/ uip_setethaddr(MacAddr); uip_ipaddr(ipaddr, 192,168,1,101); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,1,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); /* Initialize the HTTP server. */ telnetd_init(); while(1) { uip_len = enc28j60PacketReceive(); if(uip_len > 0) { if(pucUIP_Buffer->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(); enc28j60PacketSend(); } } else if(pucUIP_Buffer->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) { enc28j60PacketSend(); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); 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(); enc28j60PacketSend(); } } #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(); enc28j60PacketSend(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }
void EtherShield::ES_enc28j60PacketSend(uint16_t len, uint8_t* packet){ enc28j60PacketSend(len, packet); }
for(i = 0; i < uip_len + ETHERNET_LLH_LEN; i++) { if ( i < ETHERNET_LLH_LEN ) { printf("%02x", ll_header[i]); } else { printf("%02x", uip_buf[i - ETHERNET_LLH_LEN]); } if((i & 3) == 3) printf(" "); if((i & 15) == 15) printf("\n "); } #endif printf("\n"); ) disable_int(enc28j60PacketSend (uip_len + sizeof(struct uip_eth_hdr), uip_buf)); } void eth_drv_input(void) { LOG6LBR_PRINTF(PACKET, ETH_IN, "read: %d\n", uip_len + ETHERNET_LLH_LEN); LOG6LBR_COND_FUNC(DUMP, ETH_IN, int i; #if WIRESHARK_IMPORT_FORMAT printf("0000"); for(i = 0; i < ETHERNET_LLH_LEN; i++) printf(" %02x", ll_header[i]); for(i = 0; i < uip_len; i++) printf(" %02x", uip_buf[i]); #else
void network_send(uint16_t size, uint8_t * buffer){ enc28j60PacketSend(size, buffer); }
/******************************************************************************* * 函数名: etherdev_send * 参 数: p_char : 数据缓冲区 * length : 数据长度 * 返 回: 无 * 功 能: uIP 接口函数,发送一包数据 */ void etherdev_send(uint8_t *p_char, uint16_t length) { enc28j60PacketSend(length,p_char); }
//Documentation in header file void dhcp_sendRequest() { //Get the IP of the DHCP server from the OFFER packet in the buffer ipd = (IPv4_Data)(ns.pbuf + IP_START); for(uint8_t i = 0; i < 4; i++) ns.dhcpServerIP[i] = ipd->senderIP[i]; //dhcpState = DHCP_STATE_REQUEST; //Build ethernet header eth_makeHeader(ns.pbuf, ns.MAC, bcastMAC, ETH_IP); //Build IP header ip_makeHeader(ns.pbuf, IP_UDP, zeroIP, bcastIP); //Build UDP header udp_makeHeader(ns.pbuf, DHCP_CLIENT_PORT, DHCP_SERVER_PORT); //Build DHCP Packet dhcp_buildPacket(ns.pbuf); //Fill in op-codes uint8_t *dhcp_op = ns.pbuf+DHCP_OP_START; //Set message type to DHCP_REQUEST dhcp_op[0] = DHCP_OP_MESSAGETYPE; dhcp_op[1] = 1; dhcp_op[2] = DHCP_STATE_REQUEST; dhcp_op[3] = DHCP_OP_CLIENTID; dhcp_op[4] = 7;//Length dhcp_op[5] = 0x01;//Hardware type: ethernet for(uint8_t i = 0; i < 6; i++)//Copy MAC dhcp_op[i+6] = ns.MAC[i]; dhcp_op[12] = DHCP_OP_REQIPADDR; dhcp_op[13] = 4;//IP Length dhcp_op[14] = offeredIP[0]; dhcp_op[15] = offeredIP[1]; dhcp_op[16] = offeredIP[2]; dhcp_op[17] = offeredIP[3]; dhcp_op[18] = DHCP_OP_SERVERIP; dhcp_op[19] = 4;//IP Length dhcp_op[20] = ns.dhcpServerIP[0]; dhcp_op[21] = ns.dhcpServerIP[1]; dhcp_op[22] = ns.dhcpServerIP[2]; dhcp_op[23] = ns.dhcpServerIP[3]; dhcp_op[24] = DHCP_OP_HOSTNAME; dhcp_op[25] = 3;//Length dhcp_op[26] = 'D'; dhcp_op[27] = 'F'; dhcp_op[28] = ns.MAC[5]; dhcp_op[29] = DHCP_END; ns.plength += 30; udp_setDataLength(ns.pbuf, sizeof(DHCP_Data_t)+30); udp_computeChecksum(ns.pbuf); ip_setDataLength(ns.pbuf, sizeof(UDP_Data_t)+sizeof(DHCP_Data_t)+30); ip_computeChecksum(ns.pbuf); enc28j60PacketSend(ns.pbuf, ns.plength); }
void net_send() { enc28j60PacketSend(buffer_len(&netwbuff1), netwbuff1.start); }