This commit is contained in:
U-MobileHooK\Benedikt 2011-06-04 16:04:55 +02:00
parent 0542178e20
commit 2f6ac72484

View file

@ -14,7 +14,7 @@
#ifdef WIN32
#include "mailbox.h" /* mailbox_ptr_t */
#else
#include <metalsvm/mailbox.h> /* mailbox_ptr_t */
#include <metalsvm/mailbox.h> /* mailbox_ptr_t */
#endif
#include <lwip/netif.h> /* lwip netif */
@ -38,9 +38,12 @@
extern HANDLE remote_process_event;
/* HANDLE to the other Process (for WPM and RPM)*/
extern HANDLE hProc;
#else
#define DEBUGPRINTF(x,...) printf(x,__VA_ARGS__)
#else
#define DEBUGPRINTF(x,...) kprintf(x,__VA_ARGS__)
#endif
#define MMNIF_TX_QUEUELEN 4
@ -53,13 +56,17 @@ extern HANDLE hProc;
/* decide whether it's polling mode or not
*/
*/
static int no_irq = 1;
/* this will be set by open() and close() and shows wether the driver is running or not
*/
static int active = 0;
/* decide wheter it's uses locking or not
*/
static int disable_locking = 1;
/* IP address of the local core and the router core to get packets forwarded
*/
static unsigned int own_ip_address = 0xC0A80000; /* 192.168.0.0 */
@ -333,6 +340,51 @@ __inline void* mmnif_shmalloc()
* memory maped interface main functions
*/
/* mmnif_get_destination(): low level transmid helper function
* this function deals with some HW details, it checks to wich core this packet
* should be routed and returns the destination
*/
uint8_t mmnif_get_destination(struct netif* netif, struct pbuf* p)
{
struct ip_hdr* iphdr;
uint8_t core;
uint8_t* ip4addr;
uint8_t addr[4];
uint32_t netmask = 0xFFFFFF00;
/* grab the destination ip address out of the ip header
* for internal routing the last ocet is interpreted as core ID.
*/
iphdr = (struct ip_hdr*)(p->payload);
ip4addr = &iphdr->dest.addr;
/* revert the address to host format */
addr[3] = ip4addr[0]; addr[2] = ip4addr[1];
addr[1] = ip4addr[2]; addr[0] = ip4addr[3];
/* check if the ip address is in the Local Area Network of the 48 cores */
/* if it's not the same network the router core is addressed
* Note: the router core is core 1
*/
if (!((netmask & *(uint32_t*)addr) == (netmask & own_ip_address) ))
return 1;
core = addr[0];
/* check if the address is legitimata else return router core again */
if ((core) < 1 || (core > 48))
core = 1;
return core;
}
/*
* Transmid a packet (called by the lwip)
*/
@ -344,7 +396,7 @@ err_t mmnif_tx(struct netif* netif, struct pbuf* p)
struct pbuf* q; /* interator */
uint8_t queued;
uint8_t pos;
uint32_t dest_ip = -get_my_core_no()+2;
uint32_t dest_ip = mmnif_get_destination(netif,p);
/* take a place in the tx_queue */
mmnif->tx_queue++;
@ -360,13 +412,13 @@ err_t mmnif_tx(struct netif* netif, struct pbuf* p)
if (mmnif->tx_queue >= MMNIF_TX_QUEUELEN)
{
printf("mmnif_tx(): too many packets at once\n");
DEBUGPRINTF("mmnif_tx(): too many packets at once\n");
goto drop_packet;
}
if (p->tot_len > 1792)
{
printf("mmnif_tx(): packet is longer than 1792 bytes\n");
DEBUGPRINTF("mmnif_tx(): packet is longer than 1792 bytes\n");
goto drop_packet;
}
@ -395,7 +447,7 @@ err_t mmnif_tx(struct netif* netif, struct pbuf* p)
mmnif_write_rx_queue(dest_ip, queued);
#ifdef DEBUG_MMNIF
printf("\n SEND 0x%.8X\n",(char*)mmnif->rx_buff + 2 + pos * 1792);
DEBUGPRINTF("\n SEND 0x%.8X\n",(char*)mmnif->rx_buff + 2 + pos * 1792);
hex_dump(p->tot_len +2, mmnif->tx_buff[slot]);
#endif
@ -459,7 +511,7 @@ err_t mmnif_init(struct netif* netif)
#endif
if (!mmnif)
{
printf("mmnif init():out of memory\n");
DEBUGPRINTF("mmnif init():out of memory\n");
return ERR_MEM;
}
memset(mmnif, 0, sizeof(mmnif_t));
@ -469,7 +521,7 @@ err_t mmnif_init(struct netif* netif)
mmnif->rx_buff = mmnif_shmalloc((sizeof(mm_rx_buffer_t) + MMNIF_RX_QUEUELEN * MMNIF_RX_BUFFERLEN) * (MMNIF_CORES-1));
if (!(mmnif->rx_buff))
{
printf("mmnif init(): allocating shared memory failed\n");
DEBUGPRINTF("mmnif init(): allocating shared memory failed\n");
return ERR_MEM;
}
memset(mmnif->rx_buff, 0, (sizeof(mm_rx_buffer_t) + MMNIF_RX_QUEUELEN* MMNIF_RX_BUFFERLEN)* (MMNIF_CORES-1));
@ -483,7 +535,7 @@ err_t mmnif_init(struct netif* netif)
#endif
if (!(mmnif->tx_buff[0]))
{
printf("mmnif init: out of memory tx\n");
DEBUGPRINTF("mmnif init: out of memory tx\n");
#ifdef WIN32
free(mmnif->rx_buff);
free(mmnif);
@ -570,7 +622,7 @@ static void mmnif_rx(struct netif* netif)
}
if (length < sizeof(struct ip_hdr) ||length > netif->mtu)
{
printf("mmnif_rx(): illegal packet length %d => drop the packet",length);
DEBUGPRINTF("mmnif_rx(): illegal packet length %d => drop the packet",length);
goto drop_packet;
}
@ -579,7 +631,7 @@ static void mmnif_rx(struct netif* netif)
*/
#ifdef DEBUG_MMNIF
printf("\n RECIEVED - 0x%.8X\n",data + pos);
DEBUGPRINTF("\n RECIEVED - 0x%.8X\n",data + pos);
hex_dump(length+2,data + pos);
#endif
@ -593,7 +645,7 @@ static void mmnif_rx(struct netif* netif)
p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL);
if (!p)
{
printf("mmnif_rx(): low on mem - packet dropped\n");
DEBUGPRINTF("mmnif_rx(): low on mem - packet dropped\n");
goto drop_packet;
}
@ -664,7 +716,7 @@ static int mmnif_wait(struct netif* netif, uint32_t poll, int budget)
/* full packet send to tcpip_thread to process */
if ((err = mmnif_dev->input(p, mmnif_dev)) != ERR_OK)
{
printf("mmnif_poll: IP input error\n");
DEBUGPRINTF("mmnif_poll: IP input error\n");
pbuf_free(p);
}
@ -717,7 +769,7 @@ int mmnif_open()
struct ip_addr gw;
#ifdef DEBUG_MMNIF
printf("mmnif_dev is open\n");
DEBUGPRINTF("mmnif_dev is open\n");
#endif
/* calculate my own ip address from core number
@ -747,7 +799,7 @@ int mmnif_open()
*/
if (!netif_add(mmnif_dev, &ipaddr, &netmask, &gw, NULL,(netif_init_fn)mmnif_init, tcpip_input/*ethernet_input*/))
{
printf("mmnif_open() : unable to add network interface\n");
DEBUGPRINTF("mmnif_open() : unable to add network interface\n");
return -1;
}
@ -759,7 +811,7 @@ int mmnif_open()
/* test if interface is really up */
if (!netif_is_up(mmnif_dev))
{
printf("mmnif_open(): network interface is not up\n");
DEBUGPRINTF("mmnif_open(): network interface is not up\n");
return -2;
}