uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Committer:
ban4jp
Date:
Mon Jun 30 16:00:08 2014 +0000
Revision:
3:a2715e9c7737
Parent:
2:4da9ed411bdc
backported from Contiki 2.7

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