Contiki 3.x
ip64-ipv4-dhcp.c
1 /*
2  * Copyright (c) 2012, Thingsquare, http://www.thingsquare.com/.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  */
31 #include "contiki.h"
32 #include "contiki-net.h"
33 #include "ip64-dhcpc.h"
34 
35 #include "ip64.h"
36 #include "ip64-eth.h"
37 #include "ip64-addr.h"
38 
39 #include <stdio.h>
40 
41 PROCESS(ip64_ipv4_dhcp_process, "IPv4 DHCP");
42 
43 uip_ipaddr_t uip_hostaddr; /* Needed because it is referenced by dhcpc.c */
44 
45 
46 /*---------------------------------------------------------------------------*/
47 void
48 ip64_ipv4_dhcp_init(void)
49 {
50  printf("Starting DHCPv4\n");
51  process_start(&ip64_ipv4_dhcp_process, NULL);
52 }
53 /*---------------------------------------------------------------------------*/
54 PROCESS_THREAD(ip64_ipv4_dhcp_process, ev, data)
55 {
56  PROCESS_BEGIN();
57 
58  ip64_dhcpc_init(&ip64_eth_addr, sizeof(ip64_eth_addr));
59 
60  printf("Inited\n");
61 
62  ip64_dhcpc_request();
63  printf("Requested\n");
64  while(1) {
66 
67  if(ev == tcpip_event ||
68  ev == PROCESS_EVENT_TIMER) {
69  ip64_dhcpc_appcall(ev, data);
70  }
71  }
72 
73  PROCESS_END();
74 }
75 /*---------------------------------------------------------------------------*/
76 void
77 ip64_dhcpc_configured(const struct ip64_dhcpc_state *s)
78 {
79  uip_ip6addr_t ip6dnsaddr;
80  printf("DHCP Configured with %d.%d.%d.%d\n",
81  s->ipaddr.u8[0], s->ipaddr.u8[1],
82  s->ipaddr.u8[2], s->ipaddr.u8[3]);
83 
84  ip64_set_hostaddr((uip_ip4addr_t *)&s->ipaddr);
85  ip64_set_netmask((uip_ip4addr_t *)&s->netmask);
86  ip64_set_draddr((uip_ip4addr_t *)&s->default_router);
87  ip64_addr_4to6((uip_ip4addr_t *)&s->dnsaddr, &ip6dnsaddr);
88  // mdns_conf(&ip6dnsaddr);
89 }
90 /*---------------------------------------------------------------------------*/
91 void
92 ip64_dhcpc_unconfigured(const struct ip64_dhcpc_state *s)
93 {
94 }
95 /*---------------------------------------------------------------------------*/
The Ethernet address.
Definition: ip64-eth.h:39
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
#define NULL
The null pointer.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
Representation of an IP address.
Definition: uip.h:101
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
Definition: process.h:141
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
process_event_t tcpip_event
The uIP event.
Definition: tcpip.c:75
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99