2015-05-19 09:55:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
* Ell-i open source co-operative
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Test application for dev_eth low level ethernet drivers
|
|
|
|
*
|
|
|
|
* This test application will bounce back every received l2 ethernet
|
|
|
|
* frame by exchanging target and destination MAC addresses.
|
|
|
|
*
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "thread.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "vtimer.h"
|
|
|
|
#include "periph/spi.h"
|
|
|
|
#include "periph/gpio.h"
|
|
|
|
|
|
|
|
#include "net/dev_eth.h"
|
|
|
|
#include "dev_eth_autoinit.h"
|
|
|
|
|
2015-04-09 18:45:23 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
2015-05-19 09:55:20 +02:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
kernel_pid_t handler_pid = KERNEL_PID_UNDEF;
|
|
|
|
|
|
|
|
char _rxbuf[2000];
|
|
|
|
|
|
|
|
/* reverse src/dst addresses in raw ethernet packet */
|
|
|
|
void turn_packet(char *pkt) {
|
|
|
|
uint8_t mac[6];
|
|
|
|
/* save old dst addr */
|
|
|
|
memcpy(mac, pkt, 6);
|
|
|
|
|
|
|
|
/* use sender MAC address as new destination */
|
|
|
|
memcpy(pkt, pkt+6, 6);
|
|
|
|
|
|
|
|
/* set our MAC address as sender */
|
|
|
|
memcpy(pkt+6, mac, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dev_eth_isr(dev_eth_t *dev) {
|
|
|
|
(void)dev;
|
|
|
|
thread_wakeup(handler_pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dev_eth_rx_handler(dev_eth_t *dev) {
|
|
|
|
DEBUG("dev_eth_rx_handler dev=0x%08x\n", (unsigned) dev);
|
|
|
|
|
|
|
|
int n = dev->driver->recv(dev, _rxbuf, sizeof(_rxbuf));
|
|
|
|
|
|
|
|
DEBUG("handle_incoming: received %i bytes\n", n);
|
|
|
|
|
|
|
|
if (n>0) {
|
|
|
|
turn_packet(_rxbuf);
|
|
|
|
dev->driver->send(dev, _rxbuf, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dev_eth_linkstate_handler(dev_eth_t *dev, int newstate)
|
|
|
|
{
|
|
|
|
DEBUG("dev_eth: dev=0x%08x link %s\n", (unsigned)dev, newstate ? "UP" : "DOWN");
|
2015-04-09 18:45:23 +02:00
|
|
|
(void)dev; (void)newstate;
|
2015-05-19 09:55:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
handler_pid = thread_getpid();
|
|
|
|
|
|
|
|
/* always use first ethernet device for test */
|
|
|
|
dev_eth_t *const dev = dev_eth_devices[0];
|
|
|
|
|
|
|
|
dev_eth_init(dev);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
dev->driver->isr(dev);
|
|
|
|
thread_sleep();
|
|
|
|
DEBUG("main: woke up\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|