Contiki-NG
ip64-eth-interface.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 "net/ipv6/uip.h"
33#include "net/ipv6/uip-ds6.h"
34#include "dev/slip.h"
35
36#include "ip64/ip64.h"
37#include "ip64/ip64-arp.h"
38#include "ip64/ip64-eth-interface.h"
39
40#include <string.h>
41
42#define DEBUG DEBUG_NONE
43#include "net/ipv6/uip-debug.h"
44#define printf(...)
45/*---------------------------------------------------------------------------*/
46void
47ip64_eth_interface_input(uint8_t *packet, uint16_t len)
48{
49 struct ip64_eth_hdr *ethhdr;
50 ethhdr = (struct ip64_eth_hdr *)packet;
51
52 if(ethhdr->type == UIP_HTONS(IP64_ETH_TYPE_ARP)) {
53 len = ip64_arp_arp_input(packet, len);
54
55 if(len > 0) {
56 IP64_ETH_DRIVER.output(packet, len);
57 }
58 } else if(ethhdr->type == UIP_HTONS(IP64_ETH_TYPE_IP) &&
59 len > sizeof(struct ip64_eth_hdr)) {
60 printf("-------------->\n");
61 uip_len = ip64_4to6(&packet[sizeof(struct ip64_eth_hdr)],
62 len - sizeof(struct ip64_eth_hdr),
63 uip_buf);
64 if(uip_len > 0) {
65 printf("ip64_interface_process: converted %d bytes\n", uip_len);
66
67 printf("ip64-interface: input source ");
68 PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
69 PRINTF(" destination ");
70 PRINT6ADDR(&UIP_IP_BUF->destipaddr);
71 PRINTF("\n");
72
74 printf("Done\n");
75 }
76 }
77}
78/*---------------------------------------------------------------------------*/
79static void
80init(void)
81{
82 printf("ip64-eth-interface: init\n");
83}
84/*---------------------------------------------------------------------------*/
85static int
86output(void)
87{
88 int len, ret;
89
90 printf("ip64-interface: output source ");
91 PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
92 PRINTF(" destination ");
93 PRINT6ADDR(&UIP_IP_BUF->destipaddr);
94 PRINTF("\n");
95
96 printf("<--------------\n");
97 len = ip64_6to4(uip_buf, uip_len,
98 &ip64_packet_buffer[sizeof(struct ip64_eth_hdr)]);
99
100 printf("ip64-interface: output len %d\n", len);
101 if(len > 0) {
102 if(ip64_arp_check_cache(&ip64_packet_buffer[sizeof(struct ip64_eth_hdr)])) {
103 printf("Create header\n");
104 ret = ip64_arp_create_ethhdr(ip64_packet_buffer,
105 &ip64_packet_buffer[sizeof(struct ip64_eth_hdr)]);
106 if(ret > 0) {
107 len += ret;
108 IP64_ETH_DRIVER.output(ip64_packet_buffer, len);
109 }
110 } else {
111 printf("Create request\n");
112 len = ip64_arp_create_arp_request(ip64_packet_buffer,
113 &ip64_packet_buffer[sizeof(struct ip64_eth_hdr)]);
114 return IP64_ETH_DRIVER.output(ip64_packet_buffer, len);
115 }
116 }
117
118 return 0;
119}
120/*---------------------------------------------------------------------------*/
121const struct uip_fallback_interface ip64_eth_interface = {
122 init,
123 output
124};
125/*---------------------------------------------------------------------------*/
static uint8_t output(const linkaddr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
Definition: sicslowpan.c:1621
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.
Definition: tcpip.c:445
#define UIP_IP_BUF
Direct access to IPv6 header.
Definition: uip.h:71
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
Definition: uip.h:1157
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
Definition: uip.h:465
uint16_t uip_len
The length of the packet in the uip_buf buffer.
Definition: uip6.c:159
The Ethernet header.
Definition: ip64-eth.h:51
A set of debugging macros for the IP stack.
Header file for IPv6-related data structures.
Header file for the uIP TCP/IP stack.