source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifiHD/src/lwip_setup.c @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 3.9 KB
Line 
1/*! \page License
2 * Copyright (C) 2009, H&D Wireless AB All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * 3. The name of H&D Wireless AB may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY H&D WIRELESS AB ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
20 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*!
30 * \file lwIP setup code
31 *
32 * \brief Collects the lwIP setup code that an application has to
33 *        execute in a standalone environment.
34 *
35 * \author               H&D Wireless AB \n
36 *
37 */
38
39#include <lwip/init.h>
40#include <lwip/dhcp.h>
41#include <lwip/tcp.h>
42#include <ipv4/lwip/ip_frag.h>
43#include <netif/etharp.h>
44#include <netif/wlif.h>
45#include <timer.h>
46
47#include "lwip_setup.h"
48#include "lwip/dns.h"
49
50
51/**
52 *
53 */
54static void
55tcp_tmr_cb(void *ctx)
56{
57        tcp_tmr();
58}
59
60/**
61 *
62 */
63static void
64ip_tmr_cb(void *ctx)
65{
66        ip_reass_tmr();
67}
68
69/**
70 *
71 */
72static void
73dns_tmr_cb(void *ctx)
74{
75        dns_tmr();
76}
77
78/**
79 *
80 */
81static void
82etharp_tmr_cb(void *ctx)
83{
84        etharp_tmr();
85}
86
87
88/**
89 *
90 */
91static void
92dhcp_fine_tmr_cb(void *ctx)
93{
94    dhcp_fine_tmr();
95}
96
97/**
98 *
99 */
100static void
101dhcp_coarse_tmr_cb(void *ctx)
102{
103        dhcp_coarse_tmr();
104}
105
106int start_ip_stack(struct net_cfg *cfg, 
107                   struct ip_addr ipaddr, 
108                   struct ip_addr netmask,
109                   struct ip_addr gw) {
110
111        if (cfg->dhcp_enabled) {
112                IP4_ADDR(&gw, 0,0,0,0);
113                IP4_ADDR(&ipaddr, 0,0,0,0);
114                IP4_ADDR(&netmask, 0,0,0,0);
115        }
116       
117        /* add wl to lwip interface list and set as default */
118        cfg->netif = netif_add(cfg->netif, 
119                               &ipaddr, 
120                               &netmask, 
121                               &gw, 
122                               NULL,
123                               wlif_init, /* init */
124                               ethernet_input /* handles ARP and IP packets */);
125
126        if (cfg->netif == NULL)
127            return -1;
128        netif_set_default(cfg->netif);
129
130        /* register lwip timer callbacks for tcp, arp and dhcp protocols */
131        timer_sched_timeout_cb(5000, TIMEOUT_PERIODIC, 
132                               etharp_tmr_cb, NULL);
133        timer_sched_timeout_cb(TCP_TMR_INTERVAL, TIMEOUT_PERIODIC, 
134                               tcp_tmr_cb, NULL);
135        timer_sched_timeout_cb(DHCP_FINE_TIMER_MSECS, TIMEOUT_PERIODIC, 
136                               dhcp_fine_tmr_cb, NULL);
137        timer_sched_timeout_cb(DHCP_COARSE_TIMER_MSECS, TIMEOUT_PERIODIC,
138                               dhcp_coarse_tmr_cb, NULL);
139        timer_sched_timeout_cb(IP_TMR_INTERVAL, TIMEOUT_PERIODIC,
140                               ip_tmr_cb, NULL);
141        timer_sched_timeout_cb(DNS_TMR_INTERVAL, TIMEOUT_PERIODIC,
142                                      dns_tmr_cb, NULL);
143
144        return 1;
145}
Note: See TracBrowser for help on using the repository browser.