SAMV71 Xplained Ultra Software Package 1.4

main.c

00001 /*
00002  * Copyright (c) 2001, Adam Dunkels.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by Adam Dunkels.
00016  * 4. The name of the author may not be used to endorse or promote
00017  *    products derived from this software without specific prior
00018  *    written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00021  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00024  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00025  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00026  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00028  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  *
00032  * This file is part of the uIP TCP/IP stack.
00033  *
00034  * $Id: main.c,v 1.16 2006/06/11 21:55:03 adam Exp $
00035  *
00036  */
00037 
00038 
00039 #include "uip.h"
00040 #include "uip_arp.h"
00041 #include "tapdev.h"
00042 
00043 #include "timer.h"
00044 
00045 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00046 
00047 #ifndef NULL
00048 #define NULL (void *)0
00049 #endif /* NULL */
00050 
00051 /*---------------------------------------------------------------------------*/
00052 int
00053 main(void)
00054 {
00055   int i;
00056   uip_ipaddr_t ipaddr;
00057   struct timer periodic_timer, arp_timer;
00058 
00059   timer_set(&periodic_timer, CLOCK_SECOND / 2);
00060   timer_set(&arp_timer, CLOCK_SECOND * 10);
00061   
00062   tapdev_init();
00063   uip_init();
00064 
00065   uip_ipaddr(ipaddr, 192,168,0,2);
00066   uip_sethostaddr(ipaddr);
00067   uip_ipaddr(ipaddr, 192,168,0,1);
00068   uip_setdraddr(ipaddr);
00069   uip_ipaddr(ipaddr, 255,255,255,0);
00070   uip_setnetmask(ipaddr);
00071 
00072   httpd_init();
00073   
00074   /*  telnetd_init();*/
00075   
00076   /*  hello_world_init();*/
00077 
00078   /*  {
00079       u8_t mac[6] = {1,2,3,4,5,6};
00080       dhcpc_init(&mac, 6);
00081       }*/
00082   
00083   /*uip_ipaddr(ipaddr, 127,0,0,1);
00084   smtp_configure("localhost", ipaddr);
00085   SMTP_SEND("adam@sics.se", NULL, "uip-testing@example.com",
00086         "Testing SMTP from uIP",
00087         "Test message sent by uIP\r\n");*/
00088 
00089   /*
00090     webclient_init();
00091     resolv_init();
00092     uip_ipaddr(ipaddr, 195,54,122,204);
00093     resolv_conf(ipaddr);
00094     resolv_query("www.sics.se");*/
00095 
00096 
00097   
00098   while(1) {
00099     uip_len = tapdev_read();
00100     if(uip_len > 0) {
00101       if(BUF->type == htons(UIP_ETHTYPE_IP)) {
00102     uip_arp_ipin();
00103     uip_input();
00104     /* If the above function invocation resulted in data that
00105        should be sent out on the network, the global variable
00106        uip_len is set to a value > 0. */
00107     if(uip_len > 0) {
00108       uip_arp_out();
00109       tapdev_send();
00110     }
00111       } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
00112     uip_arp_arpin();
00113     /* If the above function invocation resulted in data that
00114        should be sent out on the network, the global variable
00115        uip_len is set to a value > 0. */
00116     if(uip_len > 0) {
00117       tapdev_send();
00118     }
00119       }
00120 
00121     } else if(timer_expired(&periodic_timer)) {
00122       timer_reset(&periodic_timer);
00123       for(i = 0; i < UIP_CONNS; i++) {
00124     uip_periodic(i);
00125     /* If the above function invocation resulted in data that
00126        should be sent out on the network, the global variable
00127        uip_len is set to a value > 0. */
00128     if(uip_len > 0) {
00129       uip_arp_out();
00130       tapdev_send();
00131     }
00132       }
00133 
00134 #if UIP_UDP
00135       for(i = 0; i < UIP_UDP_CONNS; i++) {
00136     uip_udp_periodic(i);
00137     /* If the above function invocation resulted in data that
00138        should be sent out on the network, the global variable
00139        uip_len is set to a value > 0. */
00140     if(uip_len > 0) {
00141       uip_arp_out();
00142       tapdev_send();
00143     }
00144       }
00145 #endif /* UIP_UDP */
00146       
00147       /* Call the ARP timer function every 10 seconds. */
00148       if(timer_expired(&arp_timer)) {
00149     timer_reset(&arp_timer);
00150     uip_arp_timer();
00151       }
00152     }
00153   }
00154   return 0;
00155 }
00156 /*---------------------------------------------------------------------------*/
00157 void
00158 uip_log(char *m)
00159 {
00160   printf("uIP log message: %s\n", m);
00161 }
00162 void
00163 resolv_found(char *name, u16_t *ipaddr)
00164 {
00165   u16_t *ipaddr2;
00166   
00167   if(ipaddr == NULL) {
00168     printf("Host '%s' not found.\n", name);
00169   } else {
00170     printf("Found name '%s' = %d.%d.%d.%d\n", name,
00171        htons(ipaddr[0]) >> 8,
00172        htons(ipaddr[0]) & 0xff,
00173        htons(ipaddr[1]) >> 8,
00174        htons(ipaddr[1]) & 0xff);
00175     /*    webclient_get("www.sics.se", 80, "/~adam/uip");*/
00176   }
00177 }
00178 #ifdef __DHCPC_H__
00179 void
00180 dhcpc_configured(const struct dhcpc_state *s)
00181 {
00182   uip_sethostaddr(s->ipaddr);
00183   uip_setnetmask(s->netmask);
00184   uip_setdraddr(s->default_router);
00185   resolv_conf(s->dnsaddr);
00186 }
00187 #endif /* __DHCPC_H__ */
00188 void
00189 smtp_done(unsigned char code)
00190 {
00191   printf("SMTP done with code %d\n", code);
00192 }
00193 void
00194 webclient_closed(void)
00195 {
00196   printf("Webclient: connection closed\n");
00197 }
00198 void
00199 webclient_aborted(void)
00200 {
00201   printf("Webclient: connection aborted\n");
00202 }
00203 void
00204 webclient_timedout(void)
00205 {
00206   printf("Webclient: connection timed out\n");
00207 }
00208 void
00209 webclient_connected(void)
00210 {
00211   printf("Webclient: connected, waiting for data...\n");
00212 }
00213 void
00214 webclient_datahandler(char *data, u16_t len)
00215 {
00216   printf("Webclient: got %d bytes of data.\n", len);
00217 }
00218 /*---------------------------------------------------------------------------*/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines