This commit is contained in:
2026-04-23 10:50:18 +08:00
commit a436fda935
844 changed files with 272643 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#ifndef __GENERAL_TYPE_H
#define __GENERAL_TYPE_H
typedef signed long s32;
typedef signed short s16;
typedef signed char s8;
typedef signed long const sc32; /* Read Only */
typedef signed short const sc16; /* Read Only */
typedef signed char const sc8; /* Read Only */
typedef volatile signed long vs32;
typedef volatile signed short vs16;
typedef volatile signed char vs8;
typedef volatile signed long const vsc32; /* Read Only */
typedef volatile signed short const vsc16; /* Read Only */
typedef volatile signed char const vsc8; /* Read Only */
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef unsigned long const uc32; /* Read Only */
typedef unsigned short const uc16; /* Read Only */
typedef unsigned char const uc8; /* Read Only */
typedef volatile unsigned long vu32;
typedef volatile unsigned short vu16;
typedef volatile unsigned char vu8;
typedef volatile unsigned long const vuc32; /* Read Only */
typedef volatile unsigned short const vuc16; /* Read Only */
typedef volatile unsigned char const vuc8; /* Read Only */
typedef enum {FALSE = 0, TRUE = !FALSE} bool;
#endif

11
IAPV1.1/Driver/net/hal.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef __HAL_H
#define __HAL_H
static unsigned char myip[4] = {192,168,2,8};
static unsigned char fwip[4];
static unsigned char tempfwip[16];
static unsigned char fwmac[6];
static unsigned char tempfwmac[17];
static unsigned char my_ip[13] = {"192.168.2.8"};
static unsigned char iptemp[4];
#endif

View File

@ -0,0 +1,499 @@
#include "net.h"
#include "ip_arp_udp_tcp.h"
#include "enc28j60.h"
#define pgm_read_byte(ptr) ((char)*(ptr))
//#define unsigned char unsigned char
//#define unsigned int unisgned int
static unsigned char wwwport=80;//80<38>˿<EFBFBD>
static unsigned char macaddr[6];
static unsigned char ipaddr[4];
static unsigned int info_hdr_len=0;
static unsigned int info_data_len=0;
static unsigned char seqnum=0xa; // my initial tcp sequence number
// The Ip checksum is calculated over the ip header only starting
// with the header length field and a total length of 20 bytes
// unitl ip.dst
// You must set the IP checksum field to zero before you start
// the calculation.
// len for ip is 20.
//
// For UDP/TCP we do not make up the required pseudo header. Instead we
// use the ip.src and ip.dst fields of the real packet:
// The udp checksum calculation starts with the ip.src field
// Ip.src=4bytes,Ip.dst=4 bytes,Udp header=8bytes + data length=16+len
// In other words the len here is 8 + length over which you actually
// want to calculate the checksum.
// You must set the checksum field to zero before you start
// the calculation.
// len for udp is: 8 + 8 + data length
// len for tcp is: 4+4 + 20 + option len + data length
//
// For more information on how this algorithm works see:
// http://www.netfor2.com/checksum.html
// http://www.msc.uky.edu/ken/cs471/notes/chap3.htm
// The RFC has also a C code example: http://www.faqs.org/rfcs/rfc1071.html
unsigned int checksum(unsigned char *buf, unsigned int len,unsigned char type)
{
// type 0=ip
// 1=udp
// 2=tcp
unsigned long sum = 0;
//if(type==0){
// // do not add anything
//}
if(type==1)
{
sum+=IP_PROTO_UDP_V; // protocol udp
// the length here is the length of udp (data+header len)
// =length given to this function - (IP.scr+IP.dst length)
sum+=len-8; // = real tcp len
}
if(type==2)
{
sum+=IP_PROTO_TCP_V;
// the length here is the length of tcp (data+header len)
// =length given to this function - (IP.scr+IP.dst length)
sum+=len-8; // = real tcp len
}
// build the sum of 16bit words
while(len >1)
{
sum += 0xFFFF & (*buf<<8|*(buf+1));
buf+=2;
len-=2;
}
// if there is a byte left then add it (padded with zero)
if (len)
{
sum += (0xFF & *buf)<<8;
}
// now calculate the sum over the bytes in the sum
// until the result is only 16bit long
while (sum>>16)
{
sum = (sum & 0xFFFF)+(sum >> 16);
}
// build 1's complement:
return( (unsigned int) sum ^ 0xFFFF);
}
// you must call this function once before you use any of the other functions:
void init_ip_arp_udp_tcp(unsigned char *mymac,unsigned char *myip,unsigned char wwwp)
{
unsigned char i=0;
wwwport=wwwp;
while(i<4)
{
ipaddr[i]=myip[i];
i++;
}
i=0;
while(i<6)
{
macaddr[i]=mymac[i];
i++;
}
// LCD_ShowString(100,100, "13");
}
unsigned char eth_type_is_arp_and_my_ip(unsigned char *buf,unsigned int len)
{
unsigned char i=0;
//
if (len<41)
{
return(0);
}
if(buf[ETH_TYPE_H_P] != ETHTYPE_ARP_H_V || buf[ETH_TYPE_L_P] != ETHTYPE_ARP_L_V)
{
return(0);
}
while(i<4)
{
if(buf[ETH_ARP_DST_IP_P+i] != ipaddr[i])
{
return(0);
}
i++;
}
return(1);
}
unsigned char eth_type_is_ip_and_my_ip(unsigned char *buf,unsigned int len)
{
unsigned char i=0;
//eth+ip+udp header is 42
if (len<42)
{
return(0);
}
if(buf[ETH_TYPE_H_P]!=ETHTYPE_IP_H_V || buf[ETH_TYPE_L_P]!=ETHTYPE_IP_L_V)
{
return(0);
}
if (buf[IP_HEADER_LEN_VER_P]!=0x45)
{
// must be IP V4 and 20 byte header
return(0);
}
while(i<4)
{
if(buf[IP_DST_P+i]!=ipaddr[i])
{
return(0);
}
i++;
}
return(1);
}
// make a return eth header from a received eth packet
void make_eth(unsigned char *buf)
{
unsigned char i=0;
//
//copy the destination mac from the source and fill my mac into src
while(i<6)
{
buf[ETH_DST_MAC +i]=buf[ETH_SRC_MAC +i];
buf[ETH_SRC_MAC +i]=macaddr[i];
i++;
}
}
void fill_ip_hdr_checksum(unsigned char *buf)
{
unsigned int ck;
// clear the 2 byte checksum
buf[IP_CHECKSUM_P]=0;
buf[IP_CHECKSUM_P+1]=0;
buf[IP_FLAGS_P]=0x40; // don't fragment
buf[IP_FLAGS_P+1]=0; // fragement offset
buf[IP_TTL_P]=64; // ttl
// calculate the checksum:
ck=checksum(&buf[IP_P], IP_HEADER_LEN,0);
buf[IP_CHECKSUM_P]=ck>>8;
buf[IP_CHECKSUM_P+1]=ck& 0xff;
}
// make a return ip header from a received ip packet
void make_ip(unsigned char *buf)
{
unsigned char i=0;
while(i<4)
{
buf[IP_DST_P+i]=buf[IP_SRC_P+i];
buf[IP_SRC_P+i]=ipaddr[i];
i++;
}
fill_ip_hdr_checksum(buf);
}
// make a return tcp header from a received tcp packet
// rel_ack_num is how much we must step the seq number received from the
// other side. We do not send more than 255 bytes of text (=data) in the tcp packet.
// If mss=1 then mss is included in the options list
//
// After calling this function you can fill in the first data byte at TCP_OPTIONS_P+4
// If cp_seq=0 then an initial sequence number is used (should be use in synack)
// otherwise it is copied from the packet we received
void make_tcphead(unsigned char *buf,unsigned int rel_ack_num,unsigned char mss,unsigned char cp_seq)
{
unsigned char i=0;
unsigned char tseq;
while(i<2)
{
buf[TCP_DST_PORT_H_P+i]=buf[TCP_SRC_PORT_H_P+i];
buf[TCP_SRC_PORT_H_P+i]=0; // clear source port
i++;
}
// set source port (http):
buf[TCP_SRC_PORT_L_P]=wwwport;
i=4;
// sequence numbers:
// add the rel ack num to SEQACK
while(i>0)
{
rel_ack_num=buf[TCP_SEQ_H_P+i-1]+rel_ack_num;
tseq=buf[TCP_SEQACK_H_P+i-1];
buf[TCP_SEQACK_H_P+i-1]=0xff&rel_ack_num;
if (cp_seq)
{
// copy the acknum sent to us into the sequence number
buf[TCP_SEQ_H_P+i-1]=tseq;
}
else
{
buf[TCP_SEQ_H_P+i-1]= 0; // some preset vallue
}
rel_ack_num=rel_ack_num>>8;
i--;
}
if (cp_seq==0)
{
// put inital seq number
buf[TCP_SEQ_H_P+0]= 0;
buf[TCP_SEQ_H_P+1]= 0;
// we step only the second byte, this allows us to send packts
// with 255 bytes or 512 (if we step the initial seqnum by 2)
buf[TCP_SEQ_H_P+2]= seqnum;
buf[TCP_SEQ_H_P+3]= 0;
// step the inititial seq num by something we will not use
// during this tcp session:
seqnum+=2;
}
// zero the checksum
buf[TCP_CHECKSUM_H_P]=0;
buf[TCP_CHECKSUM_L_P]=0;
// The tcp header length is only a 4 bit field (the upper 4 bits).
// It is calculated in units of 4 bytes.
// E.g 24 bytes: 24/4=6 => 0x60=header len field
//buf[TCP_HEADER_LEN_P]=(((TCP_HEADER_LEN_PLAIN+4)/4)) <<4; // 0x60
if (mss)
{
// the only option we set is MSS to 1408:
// 1408 in hex is 0x580
buf[TCP_OPTIONS_P]=2;
buf[TCP_OPTIONS_P+1]=4;
buf[TCP_OPTIONS_P+2]=0x05;
buf[TCP_OPTIONS_P+3]=0x80;
// 24 bytes:
buf[TCP_HEADER_LEN_P]=0x60;
}
else
{
// no options:
// 20 bytes:
buf[TCP_HEADER_LEN_P]=0x50;
}
}
void make_arp_answer_from_request(unsigned char *buf)
{
unsigned char i=0;
//
make_eth(buf);
buf[ETH_ARP_OPCODE_H_P]=ETH_ARP_OPCODE_REPLY_H_V; //arp <20><>Ӧ
buf[ETH_ARP_OPCODE_L_P]=ETH_ARP_OPCODE_REPLY_L_V;
// fill the mac addresses:
while(i<6)
{
buf[ETH_ARP_DST_MAC_P+i]=buf[ETH_ARP_SRC_MAC_P+i];
buf[ETH_ARP_SRC_MAC_P+i]=macaddr[i];
i++;
}
i=0;
while(i<4)
{
buf[ETH_ARP_DST_IP_P+i]=buf[ETH_ARP_SRC_IP_P+i];
buf[ETH_ARP_SRC_IP_P+i]=ipaddr[i];
i++;
}
// eth+arp is 42 bytes:
enc28j60PacketSend(42,buf);
}
void make_echo_reply_from_request(unsigned char *buf,unsigned int len)
{
make_eth(buf);
make_ip(buf);
buf[ICMP_TYPE_P]=ICMP_TYPE_ECHOREPLY_V; //////<2F><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>////////////////////////////////////////////////////////////////////////////
// we changed only the icmp.type field from request(=8) to reply(=0).
// we can therefore easily correct the checksum:
if (buf[ICMP_CHECKSUM_P] > (0xff-0x08))
{
buf[ICMP_CHECKSUM_P+1]++;
}
buf[ICMP_CHECKSUM_P]+=0x08;
//
enc28j60PacketSend(len,buf);
}
// you can send a max of 220 bytes of data
void make_udp_reply_from_request(unsigned char *buf,char *data,unsigned int datalen,unsigned int port)
{
unsigned int i=0;
unsigned int ck;
make_eth(buf);
//if (datalen>220)
// {
// datalen=220;
// }
// total length field in the IP header must be set:
i= IP_HEADER_LEN+UDP_HEADER_LEN+datalen;
buf[IP_TOTLEN_H_P]=i>>8;
buf[IP_TOTLEN_L_P]=i;
make_ip(buf);
buf[UDP_DST_PORT_H_P]=port>>8;
buf[UDP_DST_PORT_L_P]=port & 0xff;
// source port does not matter and is what the sender used.
// calculte the udp length:
buf[UDP_LEN_H_P]=datalen>>8;
buf[UDP_LEN_L_P]=UDP_HEADER_LEN+datalen;
// zero the checksum
buf[UDP_CHECKSUM_H_P]=0;
buf[UDP_CHECKSUM_L_P]=0;
// copy the data:
while(i<datalen)
{
buf[UDP_DATA_P+i]=data[i];
i++;
}
ck=checksum(&buf[IP_SRC_P], 16 + datalen,1);
buf[UDP_CHECKSUM_H_P]=ck>>8;
buf[UDP_CHECKSUM_L_P]=ck& 0xff;
enc28j60PacketSend(UDP_HEADER_LEN+IP_HEADER_LEN+ETH_HEADER_LEN+datalen,buf);
}
void make_tcp_synack_from_syn(unsigned char *buf)
{
unsigned int ck;
make_eth(buf);
// total length field in the IP header must be set:
// 20 bytes IP + 24 bytes (20tcp+4tcp options)
buf[IP_TOTLEN_H_P]=0;
buf[IP_TOTLEN_L_P]=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+4;
make_ip(buf);
buf[TCP_FLAGS_P]=TCP_FLAGS_SYNACK_V;
make_tcphead(buf,1,1,0);
// calculate the checksum, len=8 (start from ip.src) + TCP_HEADER_LEN_PLAIN + 4 (one option: mss)
ck=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN+4,2);
buf[TCP_CHECKSUM_H_P]=ck>>8;
buf[TCP_CHECKSUM_L_P]=ck& 0xff;
// add 4 for option mss:
enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+4+ETH_HEADER_LEN,buf);
}
// get a pointer to the start of tcp data in buf
// Returns 0 if there is no data
// You must call init_len_info once before calling this function
unsigned int get_tcp_data_pointer(void)
{
if (info_data_len)
{
return((unsigned int)TCP_SRC_PORT_H_P+info_hdr_len);
}
else
{
return(0);
}
}
// do some basic length calculations and store the result in static varibales
void init_len_info(unsigned char *buf)
{
info_data_len=(buf[IP_TOTLEN_H_P]<<8)|(buf[IP_TOTLEN_L_P]&0xff);
info_data_len-=IP_HEADER_LEN;
info_hdr_len=(buf[TCP_HEADER_LEN_P]>>4)*4; // generate len in bytes;
info_data_len-=info_hdr_len;
if (info_data_len<=0)
{
info_data_len=0;
}
}
// fill in tcp data at position pos. pos=0 means start of
// tcp data. Returns the position at which the string after
// this string could be filled.
unsigned int fill_tcp_data_p(unsigned char *buf,unsigned int pos, const unsigned char *progmem_s)
{
char c;
// fill in tcp data at position pos
//
// with no options the data starts after the checksum + 2 more bytes (urgent ptr)
while ((c = pgm_read_byte(progmem_s++)))
{
buf[TCP_CHECKSUM_L_P+3+pos]=c;
pos++;
}
return(pos);
}
// fill in tcp data at position pos. pos=0 means start of
// tcp data. Returns the position at which the string after
// this string could be filled.
unsigned int fill_tcp_data(unsigned char *buf,unsigned int pos, const char *s)
{
// fill in tcp data at position pos
//
// with no options the data starts after the checksum + 2 more bytes (urgent ptr)
while (*s)
{
buf[TCP_CHECKSUM_L_P+3+pos]=*s;
pos++;
s++;
}
return(pos);
}
// Make just an ack packet with no tcp data inside
// This will modify the eth/ip/tcp header
void make_tcp_ack_from_any(unsigned char *buf)
{
unsigned int j;
make_eth(buf);
// fill the header:
buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V;//TCP_FLAGS_P 0x2f TCP_FLAGS_ACK_V 0x10
if (info_data_len==0)
{
// if there is no data then we must still acknoledge one packet
make_tcphead(buf,1,0,1); // no options
}
else
{
make_tcphead(buf,info_data_len,0,1); // no options
}
// total length field in the IP header must be set:
// 20 bytes IP + 20 bytes tcp (when no options)
j=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN; //IP_HEADER_LEN 20 TCP_HEADER_LEN_PLAIN 20
buf[IP_TOTLEN_H_P]=j>>8; //IP_TOTLEN_H_P 0x10
buf[IP_TOTLEN_L_P]=j& 0xff;//IP_TOTLEN_L_P 0x11
make_ip(buf);
// calculate the checksum, len=8 (start from ip.src) + TCP_HEADER_LEN_PLAIN + data len
j=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN,2);
buf[TCP_CHECKSUM_H_P]=j>>8;
buf[TCP_CHECKSUM_L_P]=j& 0xff;
enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+ETH_HEADER_LEN,buf);
}
// you must have called init_len_info at some time before calling this function
// dlen is the amount of tcp data (http data) we send in this packet
// You can use this function only immediately after make_tcp_ack_from_any
// This is because this function will NOT modify the eth/ip/tcp header except for
// length and checksum
void make_tcp_ack_with_data(unsigned char *buf,unsigned int dlen)
{
unsigned int j;
// fill the header:
// This code requires that we send only one data packet
// because we keep no state information. We must therefore set
// the fin here:
buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V|TCP_FLAGS_PUSH_V|TCP_FLAGS_FIN_V;
// total length field in the IP header must be set:
// 20 bytes IP + 20 bytes tcp (when no options) + len of data
j=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+dlen;
buf[IP_TOTLEN_H_P]=j>>8;
buf[IP_TOTLEN_L_P]=j& 0xff;
fill_ip_hdr_checksum(buf);
// zero the checksum
buf[TCP_CHECKSUM_H_P]=0;
buf[TCP_CHECKSUM_L_P]=0;
// calculate the checksum, len=8 (start from ip.src) + TCP_HEADER_LEN_PLAIN + data len
j=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN+dlen,2);
buf[TCP_CHECKSUM_H_P]=j>>8;
buf[TCP_CHECKSUM_L_P]=j& 0xff;
enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+dlen+ETH_HEADER_LEN,buf);
}
/* end of ip_arp_udp.c */

View File

@ -0,0 +1,49 @@
/*********************************************
* vim:sw=8:ts=8:si:et
* To use the above modeline in vim you must have "set modeline" in your .vimrc
* Author: Guido Socher
* Copyright: GPL V2
*
* IP/ARP/UDP/TCP functions
*
* Chip type : ATMEGA88 with ENC28J60
*********************************************/
/*********************************************
* modified: 2007-08-08
* Author : awake
* Copyright: GPL V2
* http://www.icdev.com.cn/?2213/
* Host chip: ADUC7026
**********************************************/
//@{
#ifndef IP_ARP_UDP_TCP_H
#define IP_ARP_UDP_TCP_H
// you must call this function once before you use any of the other functions:
extern void init_ip_arp_udp_tcp(unsigned char *mymac,unsigned char *myip,unsigned char wwwp);
//
extern unsigned char eth_type_is_arp_and_my_ip(unsigned char *buf,unsigned int len);
extern unsigned char eth_type_is_ip_and_my_ip(unsigned char *buf,unsigned int len);
extern void make_arp_answer_from_request(unsigned char *buf);
extern void make_echo_reply_from_request(unsigned char *buf,unsigned int len);
extern void make_udp_reply_from_request(unsigned char *buf,char *data,unsigned int datalen,unsigned int port);
extern void make_tcp_synack_from_syn(unsigned char *buf);
extern void init_len_info(unsigned char *buf);
extern unsigned int get_tcp_data_pointer(void);
extern unsigned int fill_tcp_data_p(unsigned char *buf,unsigned int pos, const unsigned char *progmem_s);
extern unsigned int fill_tcp_data(unsigned char *buf,unsigned int pos, const char *s);
extern void make_tcp_ack_from_any(unsigned char *buf);
extern void make_tcp_ack_with_data(unsigned char *buf,unsigned int dlen);
#endif /* IP_ARP_UDP_TCP_H */
//@}

134
IAPV1.1/Driver/net/net.h Normal file
View File

@ -0,0 +1,134 @@
/*********************************************
* vim:sw=8:ts=8:si:et
* To use the above modeline in vim you must have "set modeline" in your .vimrc
* Author: Guido Socher
* Copyright: GPL V2
*
* Based on the net.h file from the AVRlib library by Pascal Stang.
* For AVRlib See http://www.procyonengineering.com/
* Used with explicit permission of Pascal Stang.
*
* Chip type : ATMEGA88 with ENC28J60
*********************************************/
/*********************************************
* modified: 2007-08-08
* Author : awake
* Copyright: GPL V2
* http://www.icdev.com.cn/?2213/
* Host chip: ADUC7026
**********************************************/
// notation: _P = position of a field
// _V = value of a field
//@{
#ifndef NET_H
#define NET_H
// ******* ETH *******
#define ETH_HEADER_LEN 14
// values of certain bytes:
#define ETHTYPE_ARP_H_V 0x08
#define ETHTYPE_ARP_L_V 0x06
#define ETHTYPE_IP_H_V 0x08
#define ETHTYPE_IP_L_V 0x00
// byte positions in the ethernet frame:
//
// Ethernet type field (2bytes):
#define ETH_TYPE_H_P 12
#define ETH_TYPE_L_P 13
//
#define ETH_DST_MAC 0
#define ETH_SRC_MAC 6
// ******* ARP *******
#define ETH_ARP_OPCODE_REPLY_H_V 0x0
#define ETH_ARP_OPCODE_REPLY_L_V 0x02
//
#define ETHTYPE_ARP_L_V 0x06
// arp.dst.ip
#define ETH_ARP_DST_IP_P 0x26
// arp.opcode
#define ETH_ARP_OPCODE_H_P 0x14
#define ETH_ARP_OPCODE_L_P 0x15
// arp.src.mac
#define ETH_ARP_SRC_MAC_P 0x16
#define ETH_ARP_SRC_IP_P 0x1c
#define ETH_ARP_DST_MAC_P 0x20
#define ETH_ARP_DST_IP_P 0x26
// ******* IP *******
#define IP_HEADER_LEN 20
// ip.src
#define IP_SRC_P 0x1a
#define IP_DST_P 0x1e
#define IP_HEADER_LEN_VER_P 0xe
#define IP_CHECKSUM_P 0x18
#define IP_TTL_P 0x16
#define IP_FLAGS_P 0x14
#define IP_P 0xe
#define IP_TOTLEN_H_P 0x10
#define IP_TOTLEN_L_P 0x11
#define IP_PROTO_P 0x17
#define IP_PROTO_ICMP_V 1
#define IP_PROTO_TCP_V 6
// 17=0x11
#define IP_PROTO_UDP_V 17
// ******* ICMP *******
#define ICMP_TYPE_ECHOREPLY_V 0
#define ICMP_TYPE_ECHOREQUEST_V 8
//
#define ICMP_TYPE_P 0x22
#define ICMP_CHECKSUM_P 0x24
// ******* UDP *******
#define UDP_HEADER_LEN 8
//
#define UDP_SRC_PORT_H_P 0x22
#define UDP_SRC_PORT_L_P 0x23
#define UDP_DST_PORT_H_P 0x24
#define UDP_DST_PORT_L_P 0x25
//
#define UDP_LEN_H_P 0x26
#define UDP_LEN_L_P 0x27
#define UDP_CHECKSUM_H_P 0x28
#define UDP_CHECKSUM_L_P 0x29
#define UDP_DATA_P 0x2a
// ******* TCP *******
#define TCP_SRC_PORT_H_P 0x22
#define TCP_SRC_PORT_L_P 0x23
#define TCP_DST_PORT_H_P 0x24
#define TCP_DST_PORT_L_P 0x25
// the tcp seq number is 4 bytes 0x26-0x29
#define TCP_SEQ_H_P 0x26
#define TCP_SEQACK_H_P 0x2a
// flags: SYN=2
#define TCP_FLAGS_P 0x2f
#define TCP_FLAGS_SYN_V 2
#define TCP_FLAGS_FIN_V 1
#define TCP_FLAGS_PUSH_V 8
#define TCP_FLAGS_SYNACK_V 0x12
#define TCP_FLAGS_ACK_V 0x10
#define TCP_FLAGS_PSHACK_V 0x18
// plain len without the options:
#define TCP_HEADER_LEN_PLAIN 20
#define TCP_HEADER_LEN_P 0x2e
#define TCP_CHECKSUM_H_P 0x32
#define TCP_CHECKSUM_L_P 0x33
#define TCP_OPTIONS_P 0x36
//
#endif
//@}

View File

@ -0,0 +1,443 @@
#include <string.h>
#include "enc28j60.h"
#include "ip_arp_udp_tcp.h"
#include "net.h"
#include "hal.h"
#include "led.h"
//#include "uart.h"
#include "simple_server.h"
#include "general_type.h"
#include "temp.h"
#define PSTR(s) s
unsigned char i_1=0,i_2=0,i_3=0,i_4=0;
unsigned char led1=0,led2=0,led3=0,led4=0,led=0;
unsigned char temp[]={"0123456789ABCDEF"};
unsigned char temp1[]={"0123456789"};
u16 temp_1;
unsigned char temp_2[5];
unsigned char temp_3[7];
//extern void delay_ms(unsigned char ms);
// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static unsigned char mymac[6] = {0x04,0x02,0x35,0x00,0x00,0x01};
//static unsigned char myip[4] = {192,168,0,100};
// base url (you can put a DNS name instead of an IP addr. if you have
// a DNS server (baseurl must end in "/"):
static unsigned int mywwwport =80; // listen port for tcp/www (max range 1-254)
// or on a different port:
//static char baseurl[]="http://10.0.0.24:88/";
//static unsigned int mywwwport =88; // listen port for tcp/www (max range 1-254)
//
static unsigned int myudpport =1200; // listen port for udp
// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX
#define BUFFER_SIZE 1500//400
static unsigned char buf[BUFFER_SIZE+1];
static unsigned char BUF;
// the password string (only the first 5 char checked), (only a-z,0-9,_ characters):
static char password[]="123456"; // must not be longer than 9 char
#define LED1_ON() LED1_RUN(1);
#define LED2_ON() LED2_RUN(1);
#define LED3_ON() LED3_RUN(1);
#define LED4_ON() LED4_RUN(1);
#define LED1_OFF() LED1_RUN(0);
#define LED2_OFF() LED2_RUN(0);
#define LED3_OFF() LED3_RUN(0);
#define LED4_OFF() LED4_RUN(0);
//
unsigned char verify_password(char *str)
{
// the first characters of the received string are
// a simple password/cookie:
//<2F><> <20><>: int strncmp(char *str1, char *str2, int maxlen); <20><><EFBFBD><EFBFBD>
//˵<><CBB5>:<3A>Ƚ<EFBFBD><C8BD>ַ<EFBFBD><D6B7><EFBFBD>str1<72><31>str2<72>Ĵ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>str1С<31><D0A1>str2<72><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><0<><30><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>str1<72><31><EFBFBD><EFBFBD>str2<72><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>>0<><30>
//<2F><><EFBFBD><EFBFBD>str1<72><31><EFBFBD><EFBFBD>str2<72><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>=0<><30>maxlenָ<6E><D6B8><EFBFBD><EFBFBD>str1<72><31>str2<72>ıȽϵ<C8BD><CFB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
//<2F>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD><DCBC>Ƚ<EFBFBD><C8BD>ַ<EFBFBD><D6B7><EFBFBD>str1<72><31>str2<72><32>ǰmaxlen<65><6E><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
if (strncmp(password,str,5)==0)
{
return(1);
}
return(0);
}
// takes a string of the form password/commandNumber and analyse it
// return values: -1 invalid password, otherwise command number
// -2 no command given but password valid
unsigned char analyse_get_url(char *str)
{
unsigned char i=0;
if (verify_password(str)==0) //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><30><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>verify_password(str)==0
{
return(-1); ////<2F><><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷʱ<C8B7>ͽ<EFBFBD>-1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>
}
// find first "/"
// passw not longer than 9 char:
while(*str && i<10 && *str >',' && *str<'{')
{
if (*str=='/')
{
str++;
break;
}
i++;
str++;
}
if (*str < 0x3a && *str > 0x2f) //<2F><><EFBFBD><EFBFBD>ASCII<49><49>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><E4B7B5>
{
// is a ASCII number, return it
return(*str-0x30);
}
return(-2);
}
// prepare the webpage by writing the data to the tcp send buffer
/**********************************************************************
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ӡҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***********************************************************************/
unsigned int print_webpage(unsigned char *buf,unsigned char on_off1,unsigned char on_off2,unsigned char on_off3,unsigned char on_off4)
{
unsigned int plen,j;
unsigned char macmac[17];
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
plen=fill_tcp_data_p(buf,plen,PSTR("<META HTTP-EQUIV=Refresh content=5>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<form action=""/"" method=get>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=7><center><3E><><EFBFBD><EFBFBD>STM32<33><32><EFBFBD><EFBFBD>̫<EFBFBD><CCAB>ͨ<EFBFBD><CDA8>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD></center></font><br><p><p>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<marquee behavior=alternate scrollamount=15>ϵͳ<CFB5><CDB3>Դ<EFBFBD><D4B4>STM32F103RBT6,128K Flash, 64K SRAM</marquee><P>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<marquee behavior=alternate>Ƕ<><C7B6>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP:192.168.1.100 MAC:04-02-35-00-00-01</marquee><P>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led1==0x31)
{
plen=fill_tcp_data_p(buf,plen,PSTR("5><font size=5><3E>ر<EFBFBD>LED1:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED1<44><31></font></center>"));
}
else if (led1==0x35|led1==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("1><font size=5><3E><><EFBFBD><EFBFBD>LED1:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED1<44><31></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led2==0x32)
{
plen=fill_tcp_data_p(buf,plen,PSTR("6><font size=5><3E>ر<EFBFBD>LED2:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED2<44><32></font></center>"));
}
else if(led2==0x36|led2==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("2><font size=5><3E><><EFBFBD><EFBFBD>LED2:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED2<44><32></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led3==0x33)
{
plen=fill_tcp_data_p(buf,plen,PSTR("7><font size=5><3E>ر<EFBFBD>LED3:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED3<44><33></font></center>"));
}
else if(led3==0x37|led3==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("3><font size=5><3E><><EFBFBD><EFBFBD>LED3:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED3<44><33></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led4==0x34)
{
plen=fill_tcp_data_p(buf,plen,PSTR("8><font size=5><3E>ر<EFBFBD>LED4:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED4<44><34></font></center>"));
}
else if(led4==0x38|led4==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("4><font size=5><3E><><EFBFBD><EFBFBD>LED4:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED4<44><34></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5><center > STM32<33>ڲ<EFBFBD><DAB2>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<C2B6> "));
plen=fill_tcp_data_p(buf,plen,PSTR(temp_2));
plen=fill_tcp_data_p(buf,plen,"<EFBFBD><EFBFBD>C</center></font>");
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#ff6600\"><center><hr> <br><3E><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD></center>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"><center><br><3E><><EFBFBD><EFBFBD>ֿɼ<D6BF> һ<>н<EFBFBD><D0BD>п<EFBFBD><D0BF><EFBFBD></center></font>"));
plen=fill_tcp_data_p(buf,plen," <a href=http://mcu-web.taobao.com><center><3E><><EFBFBD>˽<EFBFBD><CBBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7>Ա<EFBFBD><D4B1><EFBFBD>:http://mcu-web.taobao.com</center></a>");
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 ><center><3E><><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>IP<49><50>ַ<EFBFBD><D6B7>"));
plen=fill_tcp_data_p(buf,plen,PSTR(tempfwip));
plen=fill_tcp_data_p(buf,plen,PSTR(" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>"));
for(j=0;j<17;j++)
macmac[j]=tempfwmac[j];
plen=fill_tcp_data_p(buf,plen,PSTR(macmac));
plen=fill_tcp_data_p(buf,plen,"</center></font>");
plen=fill_tcp_data_p(buf,plen,PSTR("</form>")); ////ҳ<><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return(plen);
}
unsigned int simple_server(void)
{
unsigned int plen,i1=0;
unsigned int dat_p;
unsigned char ii;
unsigned char cmd,*buf1;
unsigned int payloadlen=0;
LED1_ON();
LED2_ON();
LED3_ON();
LED4_ON();
plen = enc28j60getrev();
/*initialize enc28j60*/
enc28j60Init(mymac);
// ENC28J60_Init(mymac);
//<2F><>IP<49><50>ַ<EFBFBD><D6B7>MAC<41><43>ַд<D6B7><D0B4><EFBFBD><EFBFBD><EFBFBD>ԵĻ<D4B5><C4BB><EFBFBD><EFBFBD><EFBFBD> ipaddr[] macaddr[]
init_ip_arp_udp_tcp(mymac,myip,mywwwport);
//ָʾ<D6B8><CABE>״̬:0x476 is PHLCON LEDA(<28><>)=links status, LEDB(<28><>)=receive/transmit
//enc28j60PhyWrite(PHLCON,0x7a4);
//PHLCON<4F><4E>PHY ģ<><C4A3>LED <20><><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD>
enc28j60PhyWrite(PHLCON,0x0476);
enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
//init the ethernet/ip layer:
while(1)
{
get_temperature(&temp_1);
temp_2[0]=temp1[temp_1/100];
temp_2[1]=temp1[temp_1%100/10];
temp_2[2]='.';
temp_2[3]=temp1[temp_1%10]; //<2F><>C
plen=0;
plen = enc28j60PacketReceive(BUFFER_SIZE, buf);
/*plen will ne unequal to zero if there is a valid packet (without crc error) */
if(plen==0)
{
continue;
}
// arp is broadcast if unknown but a host may also
// verify the mac address by sending it to
// a unicast address.
//ARP ֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 42
if(eth_type_is_arp_and_my_ip(buf,plen))
{
make_arp_answer_from_request(buf);
continue;
}
// check if ip packets are for us:
if(eth_type_is_ip_and_my_ip(buf,plen)==0)
{
continue;
}
if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V)
{
// a ping packet, let's send pong PING<4E>Ļ<EFBFBD>Ӧ
make_echo_reply_from_request(buf, plen);
/*<2A><>ȡmac<61><63>ַ*/
for(ii=0;ii<6;ii++)
{
fwmac[ii]=buf[ii];
tempfwmac[ii*3+0]=temp[fwmac[ii]/16];
tempfwmac[ii*3+1]=temp[fwmac[ii]%16];
if(ii<5)
tempfwmac[ii*3+2]='-';
}
/*<2A><>ȡip<69><70>ַ*/
for(ii=0;ii<4;ii++)
{
fwip[ii]=buf[ii+30];//0xbf
tempfwip[ii*4+0]=temp1[fwip[ii]/100]; //temp1[]={"0123456789"};
tempfwip[ii*4+1]=temp1[fwip[ii]%100/10];
tempfwip[ii*4+2]=temp1[fwip[ii]%100%10];
if(ii<3)
tempfwip[ii*4+3]='.';
}
continue;
}
// tcp port www start, compare only the lower byte<74>˿<EFBFBD><CBBF><EFBFBD><EFBFBD>ʼ<E7BFAA><CABC><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5>ֽ<EFBFBD>
if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport)
{
/*<2A><>ȡmac<61><63>ַ*/
for(ii=0;ii<6;ii++)
{
fwmac[ii]=buf[ii+6];
tempfwmac[ii*3+0]=temp[fwmac[ii]/16];
tempfwmac[ii*3+1]=temp[fwmac[ii]%16];
if(ii<5)
tempfwmac[ii*3+2]='-';
}
/*<2A><>ȡip<69><70>ַ*/
iptemp[0]=buf[30];
iptemp[1]=buf[27];
iptemp[2]=buf[28];
iptemp[3]=buf[29];
for(ii=0;ii<4;ii++)
{
fwip[ii]=iptemp[ii];
tempfwip[ii*4+0]=temp1[fwip[ii]/100];
tempfwip[ii*4+1]=temp1[fwip[ii]%100/10];
tempfwip[ii*4+2]=temp1[fwip[ii]%100%10];
if(ii<3)
tempfwip[ii*4+3]='.';
}
if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V)
{
make_tcp_synack_from_syn(buf);
// make_tcp_synack_from_syn does already send the syn,ack
continue;
}
if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V)
{
init_len_info(buf); // init some data structures
// we can possibly have no data, just ack:
dat_p=get_tcp_data_pointer();
if (dat_p==0)
{
if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V)
{
// finack, answer with ack
make_tcp_ack_from_any(buf);
}
// just an ack with no data, wait for next packet
continue;
}
if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0)
{
// head, post and other methods:
// for possible status codes see:
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
goto SENDTCP;
}
if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0)
{
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
plen=fill_tcp_data_p(buf,plen,PSTR("<form action=""/"" method=get>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<center><3E><><EFBFBD>룺<input type=password name=""mm"" ></center><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<center><input type=submit value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""><input type=reset value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""></center>"));
plen=fill_tcp_data_p(buf,plen,PSTR("</form>")); ////ҳ<><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
goto SENDTCP;
}
if(strncmp("/?mm=654321",(char *)&(buf[dat_p+4]),11)!=0)
{
if(strncmp("/?led",(char *)&(buf[dat_p+4]),5)==0) goto SENDTCP1;
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
plen=fill_tcp_data_p(buf,plen,PSTR("<form action=""/"" method=get>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<center><3E><><EFBFBD>룺<input type=password name=""mm"" ></center><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<center><input type=submit value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""><input type=reset value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""></center><br><br><br><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=6><center><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3A1></center></font><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("</form>")); ////ҳ<><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
goto SENDTCP;
}
SENDTCP1:
cmd=analyse_get_url((char *)&(buf[dat_p+10]));
BUF=buf[64];
cmd=BUF;
if (cmd==-1)
{
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
goto SENDTCP;
}
if (cmd==0x31)
{
LED1_OFF();
led1=i_1=0x31;
}
else if(cmd==0x35)
{
LED1_ON();
led1=i_1=0x35;
}
if (cmd==0x32)
{
LED2_OFF();
led2=i_2=0x32;
}
else if(cmd==0x36)
{
LED2_ON();
led2=i_2=0x36;
}
if (cmd==0x33)
{
LED3_OFF();
led3=i_3=0x33;
}
else if(cmd==0x37)
{
LED3_ON();
led3=i_3=0x37;
}
if (cmd==0x34)
{
LED4_OFF();
led4=i_4=0x34;
}
else if(cmd==0x38)
{
LED4_ON();
led4=i_4=0x38;
}
// if (cmd==-2) or any other value
// just display the status:
plen=print_webpage(buf,(i_1),(i_2),(i_3),(i_4)); /////////////////////////////////////////////////
SENDTCP:
make_tcp_ack_from_any(buf); // send ack for http get
make_tcp_ack_with_data(buf,plen); // send data
continue;
}
}
// tcp port www end
//
// udp start, we listen on udp port 1200=0x4B0
if (buf[IP_PROTO_P]==IP_PROTO_UDP_V&&buf[UDP_DST_PORT_H_P]==4&&buf[UDP_DST_PORT_L_P]==0xb0)
{
payloadlen= buf[UDP_LEN_H_P];
payloadlen=payloadlen<<8;
payloadlen=(payloadlen+buf[UDP_LEN_L_P])-UDP_HEADER_LEN;
//payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
ANSWER:
//while(1){
for(i1=0; i1<payloadlen; i1++) buf1[i1]=buf[UDP_DATA_P+i1];
//make_udp_reply_from_request(buf,str,strlen(str),myudpport);
make_udp_reply_from_request(buf,buf1,payloadlen,myudpport);
}
}
return 0;
}

View File

@ -0,0 +1,16 @@
#ifndef _TCPIP_H
#define _TCPIP_H
#include "ENC28J60.h"
extern unsigned char verify_password(char *str);
extern unsigned char analyse_get_url(char *str);
extern unsigned int print_webpage(unsigned char *buf,unsigned char on_off1,unsigned char on_off2,unsigned char on_off3,unsigned char on_off4);
extern unsigned int simple_server(void);
#endif