225 lines
6.7 KiB
C
225 lines
6.7 KiB
C
/*
|
|
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
* are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
|
* OF SUCH DAMAGE.
|
|
*
|
|
* This file is part of the lwIP TCP/IP stack.
|
|
*
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
*
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <zlog.h>
|
|
|
|
#include "lwip/opt.h"
|
|
#include "lwip/tcpip.h"
|
|
#include "lwip/debug.h"
|
|
#include "lwip/def.h"
|
|
|
|
#include "lwip/mem.h"
|
|
|
|
#include "lwip/snmp.h"
|
|
#include "lwip/pbuf.h"
|
|
|
|
#include "netif/etharp.h"
|
|
|
|
#include "netif/pppoeif.h"
|
|
#include "netif/rawif.h"
|
|
#include "pppoe_session.h"
|
|
#include "netif/pcapif.h"
|
|
|
|
#if defined(LWIP_UNIX_LINUX)
|
|
|
|
/* Define those to better describe your network interface. */
|
|
#define IFNAME0 'p'
|
|
#define IFNAME1 'e'
|
|
|
|
#ifndef PPPOEIF_DEBUG
|
|
#define PPPOEIF_DEBUG LWIP_DBG_OFF
|
|
#endif
|
|
|
|
#define DEFAULT_GW_IPADDR (0xC0A80001)
|
|
|
|
static unsigned int g_localIpAddrBegin = DEFAULT_GW_IPADDR + 1;
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
#if NO_SYS
|
|
|
|
int pppoeif_select(struct netif *netif) {
|
|
fd_set fdset;
|
|
int ret;
|
|
struct timeval tv;
|
|
struct pppoeif *pppoeif;
|
|
u32_t msecs = sys_timeouts_sleeptime();
|
|
|
|
pppoeif = (struct pppoeif *)netif->state;
|
|
|
|
tv.tv_sec = msecs / 1000;
|
|
tv.tv_usec = (msecs % 1000) * 1000;
|
|
|
|
FD_ZERO(&fdset);
|
|
FD_SET(pppoeif->fd, &fdset);
|
|
|
|
ret = select(pppoeif->fd + 1, &fdset, NULL, NULL, &tv);
|
|
if (ret > 0) {
|
|
pppoeif_input(netif);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#else /* NO_SYS */
|
|
#endif /* NO_SYS */
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
static void low_level_init(struct netif *netif) {
|
|
PUSER_INFO_CONTEXT pUser = (PUSER_INFO_CONTEXT)netif->state;
|
|
|
|
LWIP_DEBUGF(PPPOEIF_DEBUG, ("<%p>pppoeif_init\n", (void *)pUser));
|
|
|
|
/* Obtain MAC address from network interface. */
|
|
netif->hwaddr[0] = pUser->user_info.mac_addr[0];
|
|
netif->hwaddr[1] = pUser->user_info.mac_addr[1];
|
|
netif->hwaddr[2] = pUser->user_info.mac_addr[2];
|
|
netif->hwaddr[3] = pUser->user_info.mac_addr[3];
|
|
netif->hwaddr[4] = pUser->user_info.mac_addr[4];
|
|
netif->hwaddr[5] = pUser->user_info.mac_addr[5];
|
|
netif->hwaddr_len = 6;
|
|
|
|
/* device capabilities */
|
|
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
|
|
|
|
netif_set_link_up(netif);
|
|
}
|
|
/*-----------------------------------------------------------------------------------*/
|
|
/*
|
|
* low_level_output():
|
|
*
|
|
* Should do the actual transmission of the packet. The packet is
|
|
* contained in the pbuf that is passed to the function. This pbuf
|
|
* might be chained.
|
|
*
|
|
*/
|
|
/*-----------------------------------------------------------------------------------*/
|
|
|
|
static err_t low_level_output(struct netif *netif, struct pbuf *p) {
|
|
struct netif *rs_if = get_rawsocket_if();
|
|
p->extra = netif->state;
|
|
return pcapif_output(rs_if, p);
|
|
}
|
|
|
|
/*-----------------------------------------------------------------------------------*/
|
|
/*
|
|
* pppoeif_init():
|
|
*
|
|
* Should be called at the beginning of the program to set up the
|
|
* network interface. It calls the function low_level_init() to do the
|
|
* actual setup of the hardware.
|
|
*
|
|
*/
|
|
/*-----------------------------------------------------------------------------------*/
|
|
err_t pppoeif_init(struct netif *netif) {
|
|
|
|
netif->name[0] = 'p';
|
|
netif->name[1] = 'e';
|
|
#if LWIP_IPV4
|
|
netif->output = etharp_output;
|
|
#endif /* LWIP_IPV4 */
|
|
#if LWIP_IPV6
|
|
netif->output_ip6 = ethip6_output;
|
|
#endif /* LWIP_IPV6 */
|
|
netif->linkoutput = low_level_output;
|
|
netif->mtu = 1500;
|
|
|
|
low_level_init(netif);
|
|
|
|
return ERR_OK;
|
|
}
|
|
|
|
#if LWIP_NETIF_STATUS_CALLBACK
|
|
static void status_callback(struct netif *state_netif) {
|
|
if (netif_is_up(state_netif)) {
|
|
#if LWIP_IPV4
|
|
dzlog_info("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif)));
|
|
#else
|
|
printf("status_callback==UP\n");
|
|
#endif
|
|
} else {
|
|
dzlog_error("status_callback==DOWN\n");
|
|
}
|
|
}
|
|
#endif /* LWIP_NETIF_STATUS_CALLBACK */
|
|
|
|
#if LWIP_NETIF_LINK_CALLBACK
|
|
static void link_callback(struct netif *state_netif) {
|
|
if (netif_is_link_up(state_netif)) {
|
|
dzlog_info("link_callback==UP\n");
|
|
} else {
|
|
dzlog_error("link_callback==DOWN\n");
|
|
}
|
|
}
|
|
#endif /* LWIP_NETIF_LINK_CALLBACK */
|
|
|
|
struct netif *create_pppoe_if(PUSER_INFO_CONTEXT pUser) {
|
|
struct netif *netif;
|
|
ip4_addr_t ipaddr, netmask, gw;
|
|
|
|
ip4_addr_set_zero(&gw);
|
|
ip4_addr_set_zero(&ipaddr);
|
|
ip4_addr_set_zero(&netmask);
|
|
|
|
IP4_ADDR(&netmask, 255, 255, 0, 0);
|
|
IP4_ADDR(&gw,
|
|
(DEFAULT_GW_IPADDR & 0xFF000000),
|
|
(DEFAULT_GW_IPADDR & 0xFF0000),
|
|
(DEFAULT_GW_IPADDR & 0xFF00),
|
|
(DEFAULT_GW_IPADDR & 0xFF));
|
|
|
|
IP4_ADDR(&ipaddr,
|
|
(g_localIpAddrBegin & 0xFF000000),
|
|
(g_localIpAddrBegin & 0xFF0000),
|
|
(g_localIpAddrBegin & 0xFF00),
|
|
(g_localIpAddrBegin & 0xFF));
|
|
g_localIpAddrBegin++;
|
|
|
|
netif = (struct netif *)mem_malloc(sizeof(struct netif));
|
|
|
|
if (!netif) {
|
|
dzlog_error("Create PPPoE netif error\n");
|
|
return NULL;
|
|
}
|
|
|
|
netif_add(netif, &ipaddr, &netmask, &gw, pUser, pppoeif_init, tcpip_input);
|
|
|
|
#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 */
|
|
|
|
return netif;
|
|
}
|
|
#endif
|