New IPC interface, lwip receives data from rndis.
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
#define IFNAME0 'e'
|
||||
#define IFNAME1 'n'
|
||||
|
||||
/* the lwip network interface */
|
||||
struct netif *g_netif = NULL;
|
||||
|
||||
/* IPC rndis client */
|
||||
struct Session *g_session_rndis = NULL;
|
||||
|
||||
@@ -137,13 +140,27 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
|
||||
* packet from the interface into the pbuf.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @param dataptr the received data
|
||||
* @param len the length of received data
|
||||
* @return a pbuf filled with the received packet (including MAC header)
|
||||
* NULL on memory error
|
||||
*/
|
||||
static struct pbuf* low_level_input(struct netif *netif)
|
||||
static struct pbuf* low_level_input(struct netif *netif, void *dataptr, size_t len)
|
||||
{
|
||||
struct pbuf *p=NULL, *q=NULL;
|
||||
return p;
|
||||
struct pbuf *p=NULL, *q=NULL;
|
||||
int payload_offset = 0;
|
||||
|
||||
/* allocate buffer */
|
||||
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); //cherryusb 0.10.2
|
||||
if (p != NULL) {
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
/* Copy the received frame into buffer from memory pointed by the current ETHERNET DMA Rx descriptor */
|
||||
memcpy(q->payload, dataptr + payload_offset, q->len);
|
||||
payload_offset += q->len;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,13 +171,15 @@ static struct pbuf* low_level_input(struct netif *netif)
|
||||
* the appropriate input function is called.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @param dataptr the received data
|
||||
* @param len the length of received data
|
||||
*/
|
||||
void ethernetif_input(struct netif *netif)
|
||||
void ethernetif_input(struct netif *netif, void *dataptr, size_t len)
|
||||
{
|
||||
struct pbuf *p;
|
||||
|
||||
/* move received packet into a new pbuf */
|
||||
p = low_level_input(netif);
|
||||
p = low_level_input(netif, dataptr, len);
|
||||
/* if no packet could be read, silently ignore this */
|
||||
if (p != NULL) {
|
||||
/* pass all packets to ethernet_input, which decides what packets it supports */
|
||||
@@ -172,6 +191,22 @@ void ethernetif_input(struct netif *netif)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should be called when a packet is ready to be read
|
||||
* from the interface. It uses the function ethernetif_input() that
|
||||
* should handle the received data.
|
||||
*
|
||||
* @param dataptr received data
|
||||
* @param len length of received data
|
||||
* @return lwIP error code
|
||||
*/
|
||||
int lwip_rndis_data_recv(void *dataptr, size_t len)
|
||||
{
|
||||
struct netif *netif = g_netif;
|
||||
ethernetif_input(netif, dataptr, len);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* In this function, get session info.
|
||||
* Called from ethernetif_init().
|
||||
@@ -233,7 +268,10 @@ err_t ethernetif_init(struct netif *netif)
|
||||
/* initialize the hardware */
|
||||
low_level_init(netif);
|
||||
|
||||
g_netif = netif;
|
||||
|
||||
ipc_rndis_client_init();
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,6 @@
|
||||
#define NETIF_ENET_INIT_FUNC ethernetif_init
|
||||
|
||||
err_t ethernetif_init(struct netif *netif);
|
||||
void ethernetif_input(struct netif *netif);
|
||||
int lwip_rndis_data_recv(void *dataptr, size_t len);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "netif/ethernet.h"
|
||||
#include "sys_arch.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "arch/ethernetif.h"
|
||||
|
||||
extern struct netif gnetif;
|
||||
|
||||
@@ -89,6 +90,10 @@ int IPC_DO_SERVE_FUNC(Ipc_setsockopt)(int *s, int *level, int *optname, const vo
|
||||
return setsockopt(*s, *level, *optname, optval, *optlen);
|
||||
}
|
||||
|
||||
// The interface between lwip and rndis
|
||||
int IPC_DO_SERVE_FUNC(Ipc_lwip_rndis_data_recv)(void *dataptr, size_t *len){
|
||||
return lwip_rndis_data_recv(dataptr, *len);
|
||||
}
|
||||
|
||||
IPC_SERVER_INTERFACE(Ipc_socket, 3);
|
||||
IPC_SERVER_INTERFACE(Ipc_bind, 3);
|
||||
@@ -103,6 +108,8 @@ IPC_SERVER_INTERFACE(Ipc_send, 4);
|
||||
IPC_SERVER_INTERFACE(Ipc_write, 3);
|
||||
IPC_SERVER_INTERFACE(Ipc_close, 1);
|
||||
IPC_SERVER_INTERFACE(Ipc_setsockopt, 5);
|
||||
// The interface between lwip and rndis
|
||||
IPC_SERVER_INTERFACE(Ipc_lwip_rndis_data_recv, 2);
|
||||
|
||||
IPC_SERVER_REGISTER_INTERFACES(IpcLWIPServer, 12,
|
||||
Ipc_socket,
|
||||
@@ -117,7 +124,8 @@ IPC_SERVER_REGISTER_INTERFACES(IpcLWIPServer, 12,
|
||||
Ipc_send,
|
||||
Ipc_write,
|
||||
Ipc_close,
|
||||
Ipc_setsockopt);
|
||||
Ipc_setsockopt,
|
||||
Ipc_lwip_rndis_data_recv);
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
char lwip_ipaddr[4] = { 192, 168, 130, 77 };
|
||||
|
||||
Reference in New Issue
Block a user