Contiki-NG
enc28j60-ip64-driver.c
1/*
2 * Copyright (c) 2012-2013, 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
32#include "contiki.h"
33#include "dev/ethernet/enc28j60/enc28j60.h"
34#include "dev/ethernet/enc28j60/enc28j60-ip64-driver.h"
35#include "linkaddr.h"
36
37#include "ip64/ip64.h"
38#include "ip64/ip64-eth.h"
39
40#include <string.h>
41#include <stdio.h>
42
43PROCESS(enc28j60_ip64_driver_process, "ENC28J60 IP64 driver");
44
45/*---------------------------------------------------------------------------*/
46static void
47init(void)
48{
49 uint8_t eui64[8];
50 uint8_t macaddr[6];
51
52 /* Assume that linkaddr_node_addr holds the EUI64 of this device. */
53 memcpy(eui64, &linkaddr_node_addr, sizeof(eui64));
54
55 /* Mangle the EUI64 into a 48-bit Ethernet address. */
56 memcpy(&macaddr[0], &eui64[0], 3);
57 memcpy(&macaddr[3], &eui64[5], 3);
58
59 /* In case the OUI happens to contain a broadcast bit, we mask that
60 out here. */
61 macaddr[0] = (macaddr[0] & 0xfe);
62
63 /* Set the U/L bit, in order to create a locally administered MAC address */
64 macaddr[0] = (macaddr[0] | 0x02);
65
66 memcpy(ip64_eth_addr.addr, macaddr, sizeof(macaddr));
67
68 printf("MAC addr %02x:%02x:%02x:%02x:%02x:%02x\n",
69 macaddr[0], macaddr[1], macaddr[2],
70 macaddr[3], macaddr[4], macaddr[5]);
71 enc28j60_init(macaddr);
72 process_start(&enc28j60_ip64_driver_process, NULL);
73}
74/*---------------------------------------------------------------------------*/
75static int
76output(uint8_t *packet, uint16_t len)
77{
78 enc28j60_send(packet, len);
79 return len;
80}
81/*---------------------------------------------------------------------------*/
82PROCESS_THREAD(enc28j60_ip64_driver_process, ev, data)
83{
84 static int len;
85 static struct etimer e;
87
88 while(1) {
89 etimer_set(&e, 1);
91 len = enc28j60_read(ip64_packet_buffer, ip64_packet_buffer_maxlen);
92 if(len > 0) {
93 IP64_INPUT(ip64_packet_buffer, len);
94 }
95 }
96
98}
99/*---------------------------------------------------------------------------*/
100const struct ip64_driver enc28j60_ip64_driver = {
101 init,
102 output
103};
104/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Definition: cc2538-rf.c:1154
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Definition: etimer.c:177
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition: linkaddr.c:48
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#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
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
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:1606
Header file for the link-layer address representation.
A timer.
Definition: etimer.h:76
The Ethernet address.
Definition: ip64-eth.h:40