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