Add LWIP_NETIF_STATUS_CALLBACK and LWIP_NETIF_LINK_CALLBACK use in Win32 port.

This commit is contained in:
fbernon 2007-12-23 14:28:38 +00:00
parent 04b00f954c
commit 1e68e75581
7 changed files with 133 additions and 259 deletions

View File

@ -44,6 +44,8 @@
#define LWIP_HAVE_LOOPIF 1
#define LWIP_LISTEN_BACKLOG 0
#define LWIP_COMPAT_SOCKETS 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_RCVBUF 1

View File

@ -1078,38 +1078,10 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\etharp.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ethernetif.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\FILES"
@ -1132,38 +1104,10 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\loopif.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\slipif.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<Filter
Name="ppp"
@ -1171,20 +1115,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\auth.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\auth.h"
@ -1207,20 +1137,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\chap.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\chap.h"
@ -1243,20 +1159,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\chpms.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\chpms.h"
@ -1279,20 +1181,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\fsm.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\fsm.h"
@ -1315,20 +1203,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\ipcp.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\ipcp.h"
@ -1351,20 +1225,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\lcp.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\lcp.h"
@ -1387,20 +1247,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\magic.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\magic.h"
@ -1423,20 +1269,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\md5.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\md5.h"
@ -1459,20 +1291,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\pap.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\pap.h"
@ -1495,20 +1313,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\ppp.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\ppp.h"
@ -1531,20 +1335,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\ppp_oe.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\pppdebug.h"
@ -1567,20 +1357,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\randm.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\randm.h"
@ -1603,20 +1379,6 @@
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\vj.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="$(LWIP_DIR)\src\netif\ppp\vj.h"
@ -1716,6 +1478,22 @@
RelativePath="..\include\arch\sys_arch.h"
>
</File>
<Filter
Name="sio"
>
<File
RelativePath="..\Serial.h"
>
</File>
<File
RelativePath="..\Serial.lib"
>
</File>
<File
RelativePath="..\sio.c"
>
</File>
</Filter>
</Filter>
<File
RelativePath="$(LWIP_DIR)\CHANGELOG"

View File

@ -27,7 +27,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* pktif.c - This file is part of lwIPtest
* pktdrv.c - This file is part of lwIP pktif
*
****************************************************************************
*
@ -73,18 +73,20 @@
#include <ntddndis.h>
/** @todo use the lwip header file */
#define ETHARP_HWADDR_LEN 6
#define ETHARP_HWADDR_LEN 6
#define MAX_NUM_ADAPTERS 10
#define ADAPTER_NAME_LEN 4096
#define PACKET_ADAPTER_BUFSIZE 512000
#define PACKET_INPUT_BUFSIZE 256000
/* Packet Adapter informations */
struct packet_adapter {
input_fn input;
void *input_fn_arg;
LPADAPTER lpAdapter;
LPPACKET lpPacket;
input_fn input;
void *input_fn_arg;
LPADAPTER lpAdapter;
LPPACKET lpPacket;
NDIS_MEDIA_STATE fNdisMediaState;
/* buffer to hold the data coming from the driver */
char buffer[PACKET_INPUT_BUFSIZE];
};
@ -108,8 +110,14 @@ init_adapter(int adapter_num, char *mac_addr, input_fn input, void *arg)
int AdapterNum =0;
ULONG AdapterLength;
PPACKET_OID_DATA ppacket_oid_data;
struct packet_adapter *pa = malloc(sizeof(struct packet_adapter));
unsigned char ethaddr[ETHARP_HWADDR_LEN];
struct packet_adapter *pa;
pa = malloc(sizeof(struct packet_adapter));
if (!pa) {
printf("Unable to alloc the adapter!\n");
return NULL;
}
memset(pa, 0, sizeof(struct packet_adapter));
pa->input = input;
@ -309,3 +317,39 @@ update_adapter(void *adapter)
ProcessPackets(adapter, pa->lpPacket);
}
}
/**
* Check for link state changes. Called in the main loop: 'interrupt' mode is not
* really supported :(
*
* @param adapter adapter handle received by a call to init_adapter
* @return one of the link_adapter_event values
*/
enum link_adapter_event
link_adapter(void *adapter)
{
struct packet_adapter *pa = (struct packet_adapter*)adapter;
if (pa != NULL) {
PPACKET_OID_DATA ppacket_oid_data;
NDIS_MEDIA_STATE fNdisMediaState = pa->fNdisMediaState;
/* get the media connect status of the selected adapter */
ppacket_oid_data = malloc(sizeof(PACKET_OID_DATA) + sizeof(NDIS_MEDIA_STATE));
if (ppacket_oid_data) {
ppacket_oid_data->Oid = OID_GEN_MEDIA_CONNECT_STATUS;
ppacket_oid_data->Length = sizeof(NDIS_MEDIA_STATE);
if (PacketRequest(pa->lpAdapter, FALSE, ppacket_oid_data)) {
fNdisMediaState = (*((PNDIS_MEDIA_STATE)(ppacket_oid_data->Data)));
}
free(ppacket_oid_data);
}
if (pa->fNdisMediaState != fNdisMediaState) {
pa->fNdisMediaState = fNdisMediaState;
return ((fNdisMediaState == NdisMediaStateConnected) ? LINKEVENT_UP : LINKEVENT_DOWN);
}
}
return LINKEVENT_UNCHANGED;
}

View File

@ -7,10 +7,17 @@ extern "C" {
typedef void (*input_fn)(void *arg, void *packet, int len);
void *init_adapter(int adapter_num, char *mac_addr, input_fn input, void *arg);
void shutdown_adapter(void *adapter);
int packet_send(void *adapter, void *buffer, int len);
void update_adapter(void *adapter);
enum link_adapter_event {
LINKEVENT_UNCHANGED,
LINKEVENT_UP,
LINKEVENT_DOWN
};
void* init_adapter (int adapter_num, char *mac_addr, input_fn input, void *arg);
void shutdown_adapter(void *adapter);
int packet_send (void *adapter, void *buffer, int len);
void update_adapter (void *adapter);
enum link_adapter_event link_adapter (void *adapter);
#ifdef __cplusplus
}

View File

@ -27,7 +27,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* pktif.c - This file is part of lwIPtest
* pktif.c - This file is part of lwIP pktif
*
****************************************************************************
*
@ -78,6 +78,7 @@
#include "lwip/sys.h"
#include "lwip/ip.h"
#include "lwip/snmp.h"
#include "lwip/tcpip.h"
#include "netif/etharp.h"
#include "pktdrv.h"
@ -85,19 +86,29 @@
/* include the port-dependent configuration */
#include "lwipcfg_msvc.h"
#undef NETIF_DEBUG
#define NETIF_DEBUG 0
/* Define those to better describe your network interface.
For now, we use 'e0', 'e1', 'e2' and so on */
#define IFNAME0 'e'
#define IFNAME1 '0'
#define IFNAME0 'e'
#define IFNAME1 '0'
/* index of the network adapter to use for lwIP */
#ifndef PACKET_LIB_ADAPTER_NR
#define PACKET_LIB_ADAPTER_NR 0
#define PACKET_LIB_ADAPTER_NR 0
#endif
/* Define PHY delay when "link up" */
#ifndef PHY_LINKUP_DELAY
#define PHY_LINKUP_DELAY 5000
#endif
/* link state notification macro */
#if NO_SYS
#define NOTIFY_LINKSTATE(netif,linkfunc) tcpip_timeout(PHY_LINKUP_DELAY, (sys_timeout_handler)linkfunc, netif)
#else /* NO_SYS*/
#define NOTIFY_LINKSTATE(netif,linkfunc) linkfunc(netif)
#endif /* NO_SYS*/
const static struct eth_addr broadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
/* Forward declarations. */
@ -323,6 +334,20 @@ void
ethernetif_poll(struct netif *netif)
{
update_adapter(netif->state);
#if LWIP_NETIF_LINK_CALLBACK
/* Process the link status change */
switch (link_adapter(netif->state)) {
case LINKEVENT_UP: {
NOTIFY_LINKSTATE(netif,netif_set_link_up);
break;
}
case LINKEVENT_DOWN: {
NOTIFY_LINKSTATE(netif,netif_set_link_down);
break;
}
}
#endif /* LWIP_NETIF_LINK_CALLBACK */
}
/*-----------------------------------------------------------------------------------*/

View File

@ -3,8 +3,8 @@
#include "lwip/err.h"
err_t ethernetif_init(struct netif *netif);
void ethernetif_shutdown(struct netif *netif);
void ethernetif_poll(struct netif *netif);
err_t ethernetif_init (struct netif *netif);
void ethernetif_shutdown(struct netif *netif);
void ethernetif_poll (struct netif *netif);
#endif

View File

@ -223,6 +223,18 @@ pppLinkStatusCallback(void *ctx, int errCode, void *arg)
}
#endif /* PPP_SUPPORT */
#if LWIP_NETIF_STATUS_CALLBACK
void status_callback(struct netif *netif)
{ printf("status_callback==%s\n", netif_is_up(netif)?"UP":"DOWN");
}
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
void link_callback(struct netif *netif)
{ printf("link_callback==%s\n", netif_is_link_up(netif)?"UP":"DOWN");
}
#endif /* LWIP_NETIF_LINK_CALLBACK */
/* This function initializes all network interfaces */
static void
msvc_netif_init()
@ -265,6 +277,12 @@ msvc_netif_init()
#else /* NO_SYS */
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));
#endif /* NO_SYS */
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(&netif, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
netif_set_link_callback(&netif, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
#if PPP_SUPPORT
{ sio_fd_t ppp_sio;