1 /*
2 * Demo for libcoap on lwIP
3 *
4 * partially copied from lwip-contrib/ports/unix/proj/minimal/main.c
5 *
6 *
7 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * Author: Adam Dunkels <adam@sics.se>
33 * RT timer modifications by Christiaan Simons
34 * lwip adaptions: chrysn <chrysn@fsfe.org>
35 * also, https://savannah.nongnu.org/bugs/?40245 was applied */
36
37 #include "server-coap.h"
38
39 #include <lwip/init.h>
40 #include <lwip/timeouts.h>
41
42 #include <netif/etharp.h>
43 #include <netif/tapif.h>
44
45 #include <signal.h>
46
47 static ip4_addr_t ipaddr, netmask, gw;
48
49 int
main(int argc,char ** argv)50 main(int argc, char **argv)
51 {
52 struct netif netif;
53
54 /* startup defaults (may be overridden by one or more opts). this is
55 * hard-coded v4 even in presence of v6, which does auto-discovery and
56 * should thus wind up with an address of fe80::12:34ff:fe56:78ab%tap0
57 * */
58 IP4_ADDR(&gw, 192,168,113,1);
59 IP4_ADDR(&ipaddr, 192,168,113,2);
60 IP4_ADDR(&netmask, 255,255,255,0);
61
62 lwip_init();
63
64 printf("TCP/IP initialized.\n");
65
66 netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input);
67 netif.flags |= NETIF_FLAG_ETHARP;
68 netif_set_default(&netif);
69 netif_set_up(&netif);
70 #if LWIP_IPV6
71 netif_create_ip6_linklocal_address(&netif, 1);
72 #endif
73
74 /* start applications here */
75
76 server_coap_init();
77
78 printf("Applications started.\n");
79
80
81 while (1) {
82 /* poll netif, pass packet to lwIP */
83 tapif_select(&netif);
84
85 sys_check_timeouts();
86
87 server_coap_poll();
88 }
89
90 return 0;
91 }
92