uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Committer:
ban4jp
Date:
Sat Jun 14 16:02:21 2014 +0000
Revision:
0:685224d2f66d
Child:
2:4da9ed411bdc
initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ban4jp 0:685224d2f66d 1 #include "mbed.h"
ban4jp 0:685224d2f66d 2
ban4jp 0:685224d2f66d 3 extern "C" {
ban4jp 0:685224d2f66d 4 #include "uip.h"
ban4jp 0:685224d2f66d 5 #include "uip_arp.h"
ban4jp 0:685224d2f66d 6 }
ban4jp 0:685224d2f66d 7 #include "tapdev.h"
ban4jp 0:685224d2f66d 8
ban4jp 0:685224d2f66d 9 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
ban4jp 0:685224d2f66d 10
ban4jp 0:685224d2f66d 11 #ifndef NULL
ban4jp 0:685224d2f66d 12 #define NULL (void *)0
ban4jp 0:685224d2f66d 13 #endif /* NULL */
ban4jp 0:685224d2f66d 14
ban4jp 0:685224d2f66d 15 DigitalOut myled(LED1);
ban4jp 0:685224d2f66d 16
ban4jp 0:685224d2f66d 17 /* Ethernet Pin configuration
ban4jp 0:685224d2f66d 18 => /dev-enc28j60/tapdev.cpp
ban4jp 0:685224d2f66d 19 */
ban4jp 0:685224d2f66d 20
ban4jp 0:685224d2f66d 21 int main() {
ban4jp 0:685224d2f66d 22 int i;
ban4jp 0:685224d2f66d 23 uip_ipaddr_t ipaddr;
ban4jp 0:685224d2f66d 24 Timer periodic_timer, arp_timer;
ban4jp 0:685224d2f66d 25
ban4jp 0:685224d2f66d 26 periodic_timer.start();
ban4jp 0:685224d2f66d 27 arp_timer.start();
ban4jp 0:685224d2f66d 28
ban4jp 0:685224d2f66d 29 /* Initialize the device driver. */
ban4jp 0:685224d2f66d 30 printf("tapdev_init()\n");
ban4jp 0:685224d2f66d 31 tapdev_init();
ban4jp 0:685224d2f66d 32
ban4jp 0:685224d2f66d 33 /* Initialize the uIP TCP/IP stack. */
ban4jp 0:685224d2f66d 34 printf("uip_init()\n");
ban4jp 0:685224d2f66d 35 uip_init();
ban4jp 0:685224d2f66d 36
ban4jp 0:685224d2f66d 37 struct uip_eth_addr mac = {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5};
ban4jp 0:685224d2f66d 38 uip_setethaddr(mac);
ban4jp 0:685224d2f66d 39
ban4jp 0:685224d2f66d 40 uip_ipaddr(ipaddr, 192,168,0,12);
ban4jp 0:685224d2f66d 41 uip_sethostaddr(ipaddr);
ban4jp 0:685224d2f66d 42 uip_ipaddr(ipaddr, 192,168,0,1);
ban4jp 0:685224d2f66d 43 uip_setdraddr(ipaddr);
ban4jp 0:685224d2f66d 44 uip_ipaddr(ipaddr, 255,255,255,0);
ban4jp 0:685224d2f66d 45 uip_setnetmask(ipaddr);
ban4jp 0:685224d2f66d 46
ban4jp 0:685224d2f66d 47 printf("httpd_init()\n");
ban4jp 0:685224d2f66d 48 httpd_init();
ban4jp 0:685224d2f66d 49
ban4jp 0:685224d2f66d 50 /* telnetd_init();*/
ban4jp 0:685224d2f66d 51
ban4jp 0:685224d2f66d 52 /* hello_world_init();*/
ban4jp 0:685224d2f66d 53
ban4jp 0:685224d2f66d 54 /* {
ban4jp 0:685224d2f66d 55 u8_t mac[6] = {1,2,3,4,5,6};
ban4jp 0:685224d2f66d 56 dhcpc_init(&mac, 6);
ban4jp 0:685224d2f66d 57 }*/
ban4jp 0:685224d2f66d 58
ban4jp 0:685224d2f66d 59 /*uip_ipaddr(ipaddr, 127,0,0,1);
ban4jp 0:685224d2f66d 60 smtp_configure("localhost", ipaddr);
ban4jp 0:685224d2f66d 61 SMTP_SEND("adam@sics.se", NULL, "uip-testing@example.com",
ban4jp 0:685224d2f66d 62 "Testing SMTP from uIP",
ban4jp 0:685224d2f66d 63 "Test message sent by uIP\r\n");*/
ban4jp 0:685224d2f66d 64
ban4jp 0:685224d2f66d 65 /*
ban4jp 0:685224d2f66d 66 webclient_init();
ban4jp 0:685224d2f66d 67 resolv_init();
ban4jp 0:685224d2f66d 68 uip_ipaddr(ipaddr, 195,54,122,204);
ban4jp 0:685224d2f66d 69 resolv_conf(ipaddr);
ban4jp 0:685224d2f66d 70 resolv_query("www.sics.se");*/
ban4jp 0:685224d2f66d 71
ban4jp 0:685224d2f66d 72
ban4jp 0:685224d2f66d 73 printf("uIP Start.\n");
ban4jp 0:685224d2f66d 74
ban4jp 0:685224d2f66d 75 while(1) {
ban4jp 0:685224d2f66d 76 uip_len = tapdev_read();
ban4jp 0:685224d2f66d 77 if(uip_len > 0) {
ban4jp 0:685224d2f66d 78 //printf("recv = %d\n", uip_len);
ban4jp 0:685224d2f66d 79
ban4jp 0:685224d2f66d 80 if(BUF->type == htons(UIP_ETHTYPE_IP)) {
ban4jp 0:685224d2f66d 81 uip_arp_ipin();
ban4jp 0:685224d2f66d 82 uip_input();
ban4jp 0:685224d2f66d 83 /* If the above function invocation resulted in data that
ban4jp 0:685224d2f66d 84 should be sent out on the network, the global variable
ban4jp 0:685224d2f66d 85 uip_len is set to a value > 0. */
ban4jp 0:685224d2f66d 86 if(uip_len > 0) {
ban4jp 0:685224d2f66d 87 uip_arp_out();
ban4jp 0:685224d2f66d 88 tapdev_send();
ban4jp 0:685224d2f66d 89 }
ban4jp 0:685224d2f66d 90 } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
ban4jp 0:685224d2f66d 91 uip_arp_arpin();
ban4jp 0:685224d2f66d 92 /* If the above function invocation resulted in data that
ban4jp 0:685224d2f66d 93 should be sent out on the network, the global variable
ban4jp 0:685224d2f66d 94 uip_len is set to a value > 0. */
ban4jp 0:685224d2f66d 95 if(uip_len > 0) {
ban4jp 0:685224d2f66d 96 tapdev_send();
ban4jp 0:685224d2f66d 97 }
ban4jp 0:685224d2f66d 98 }
ban4jp 0:685224d2f66d 99
ban4jp 0:685224d2f66d 100 } else if(periodic_timer.read_ms() >= 500) {
ban4jp 0:685224d2f66d 101 periodic_timer.reset();
ban4jp 0:685224d2f66d 102 //printf("periodic_timer tick\n");
ban4jp 0:685224d2f66d 103 for(i = 0; i < UIP_CONNS; i++) {
ban4jp 0:685224d2f66d 104 uip_periodic(i);
ban4jp 0:685224d2f66d 105 /* If the above function invocation resulted in data that
ban4jp 0:685224d2f66d 106 should be sent out on the network, the global variable
ban4jp 0:685224d2f66d 107 uip_len is set to a value > 0. */
ban4jp 0:685224d2f66d 108 if(uip_len > 0) {
ban4jp 0:685224d2f66d 109 uip_arp_out();
ban4jp 0:685224d2f66d 110 tapdev_send();
ban4jp 0:685224d2f66d 111 }
ban4jp 0:685224d2f66d 112 }
ban4jp 0:685224d2f66d 113
ban4jp 0:685224d2f66d 114 #if UIP_UDP
ban4jp 0:685224d2f66d 115 for(i = 0; i < UIP_UDP_CONNS; i++) {
ban4jp 0:685224d2f66d 116 uip_udp_periodic(i);
ban4jp 0:685224d2f66d 117 /* If the above function invocation resulted in data that
ban4jp 0:685224d2f66d 118 should be sent out on the network, the global variable
ban4jp 0:685224d2f66d 119 uip_len is set to a value > 0. */
ban4jp 0:685224d2f66d 120 if(uip_len > 0) {
ban4jp 0:685224d2f66d 121 uip_arp_out();
ban4jp 0:685224d2f66d 122 tapdev_send();
ban4jp 0:685224d2f66d 123 }
ban4jp 0:685224d2f66d 124 }
ban4jp 0:685224d2f66d 125 #endif /* UIP_UDP */
ban4jp 0:685224d2f66d 126
ban4jp 0:685224d2f66d 127 /* Call the ARP timer function every 10 seconds. */
ban4jp 0:685224d2f66d 128 if(arp_timer.read_ms() >= 10000) {
ban4jp 0:685224d2f66d 129 arp_timer.reset();
ban4jp 0:685224d2f66d 130 //printf("arp_timer tick\n");
ban4jp 0:685224d2f66d 131 uip_arp_timer();
ban4jp 0:685224d2f66d 132 }
ban4jp 0:685224d2f66d 133 }
ban4jp 0:685224d2f66d 134 }
ban4jp 0:685224d2f66d 135 //return 0;
ban4jp 0:685224d2f66d 136 }
ban4jp 0:685224d2f66d 137 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 138 void
ban4jp 0:685224d2f66d 139 uip_log(char *m)
ban4jp 0:685224d2f66d 140 {
ban4jp 0:685224d2f66d 141 printf("uIP log message: %s\n", m);
ban4jp 0:685224d2f66d 142 }
ban4jp 0:685224d2f66d 143 /*---------------------------------------------------------------------------*/