Upgraded lwIP to 2.0.2-STABLE
This commit is contained in:
55
ext/lwip/src/netif/FILES
Normal file → Executable file
55
ext/lwip/src/netif/FILES
Normal file → Executable file
@@ -1,31 +1,24 @@
|
||||
This directory contains generic network interface device drivers that
|
||||
do not contain any hardware or architecture specific code. The files
|
||||
are:
|
||||
|
||||
etharp.c
|
||||
Implements the ARP (Address Resolution Protocol) over
|
||||
Ethernet. The code in this file should be used together with
|
||||
Ethernet device drivers. Note that this module has been
|
||||
largely made Ethernet independent so you should be able to
|
||||
adapt this for other link layers (such as Firewire).
|
||||
|
||||
ethernetif.c
|
||||
An example of how an Ethernet device driver could look. This
|
||||
file can be used as a "skeleton" for developing new Ethernet
|
||||
network device drivers. It uses the etharp.c ARP code.
|
||||
|
||||
loopif.c
|
||||
A "loopback" network interface driver. It requires configuration
|
||||
through the define LWIP_LOOPIF_MULTITHREADING (see opt.h).
|
||||
|
||||
slipif.c
|
||||
A generic implementation of the SLIP (Serial Line IP)
|
||||
protocol. It requires a sio (serial I/O) module to work.
|
||||
|
||||
lowpan6.c
|
||||
6LoWPAN implementation
|
||||
|
||||
ppp/ Point-to-Point Protocol stack
|
||||
The lwIP PPP support is based from pppd (http://ppp.samba.org) with
|
||||
huge changes to match code size and memory requirements for embedded
|
||||
devices. Please read ppp/PPPD_FOLLOWUP for a detailed explanation.
|
||||
This directory contains generic network interface device drivers that
|
||||
do not contain any hardware or architecture specific code. The files
|
||||
are:
|
||||
|
||||
ethernet.c
|
||||
Shared code for Ethernet based interfaces.
|
||||
|
||||
ethernetif.c
|
||||
An example of how an Ethernet device driver could look. This
|
||||
file can be used as a "skeleton" for developing new Ethernet
|
||||
network device drivers. It uses the etharp.c ARP code.
|
||||
|
||||
lowpan6.c
|
||||
A 6LoWPAN implementation as a netif.
|
||||
|
||||
slipif.c
|
||||
A generic implementation of the SLIP (Serial Line IP)
|
||||
protocol. It requires a sio (serial I/O) module to work.
|
||||
|
||||
ppp/ Point-to-Point Protocol stack
|
||||
The lwIP PPP support is based from pppd (http://ppp.samba.org) with
|
||||
huge changes to match code size and memory requirements for embedded
|
||||
devices. Please read /doc/ppp.txt and ppp/PPPD_FOLLOWUP for a detailed
|
||||
explanation.
|
||||
|
||||
542
ext/lwip/src/netif/ethernet.c
Normal file → Executable file
542
ext/lwip/src/netif/ethernet.c
Normal file → Executable file
@@ -1,228 +1,314 @@
|
||||
/**
|
||||
* @file
|
||||
* Ethernet common functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
|
||||
* Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_ARP || LWIP_ETHERNET
|
||||
|
||||
#include "netif/ethernet.h"
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/snmp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPPOE_SUPPORT
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
|
||||
const struct eth_addr ethzero = {{0,0,0,0,0,0}};
|
||||
|
||||
/**
|
||||
* @ingroup lwip_nosys
|
||||
* Process received ethernet frames. Using this function instead of directly
|
||||
* calling ip_input and passing ARP frames through etharp in ethernetif_input,
|
||||
* the ARP cache is protected from concurrent access.\n
|
||||
* Don't call directly, pass to netif_add() and call netif->input().
|
||||
*
|
||||
* @param p the received packet, p->payload pointing to the ethernet header
|
||||
* @param netif the network interface on which the packet was received
|
||||
*/
|
||||
err_t
|
||||
ethernet_input(struct pbuf *p, struct netif *netif)
|
||||
{
|
||||
LWIP_DEBUGF(IP6_DEBUG, ("ethernet_input: netif = %p\n", (void*)netif));
|
||||
struct eth_hdr* ethhdr;
|
||||
u16_t type;
|
||||
#if LWIP_ARP || ETHARP_SUPPORT_VLAN || LWIP_IPV6
|
||||
s16_t ip_hdr_offset = SIZEOF_ETH_HDR;
|
||||
#endif /* LWIP_ARP || ETHARP_SUPPORT_VLAN */
|
||||
|
||||
if (p->len <= SIZEOF_ETH_HDR) {
|
||||
/* a packet with only an ethernet header (or less) is not valid for us */
|
||||
ETHARP_STATS_INC(etharp.proterr);
|
||||
ETHARP_STATS_INC(etharp.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifinerrors);
|
||||
goto free_and_return;
|
||||
}
|
||||
|
||||
/* points to packet payload, which starts with an Ethernet header */
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
|
||||
("ethernet_input: dest:%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F", src:%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F", type:%"X16_F"\n",
|
||||
(unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], (unsigned)ethhdr->dest.addr[2],
|
||||
(unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], (unsigned)ethhdr->dest.addr[5],
|
||||
(unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], (unsigned)ethhdr->src.addr[2],
|
||||
(unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], (unsigned)ethhdr->src.addr[5],
|
||||
htons(ethhdr->type)));
|
||||
|
||||
type = ethhdr->type;
|
||||
#if ETHARP_SUPPORT_VLAN
|
||||
if (type == PP_HTONS(ETHTYPE_VLAN)) {
|
||||
struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr*)(((char*)ethhdr) + SIZEOF_ETH_HDR);
|
||||
if (p->len <= SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR) {
|
||||
/* a packet with only an ethernet/vlan header (or less) is not valid for us */
|
||||
ETHARP_STATS_INC(etharp.proterr);
|
||||
ETHARP_STATS_INC(etharp.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifinerrors);
|
||||
goto free_and_return;
|
||||
}
|
||||
#if defined(LWIP_HOOK_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK_FN) /* if not, allow all VLANs */
|
||||
#ifdef LWIP_HOOK_VLAN_CHECK
|
||||
if (!LWIP_HOOK_VLAN_CHECK(netif, ethhdr, vlan)) {
|
||||
#elif defined(ETHARP_VLAN_CHECK_FN)
|
||||
if (!ETHARP_VLAN_CHECK_FN(ethhdr, vlan)) {
|
||||
#elif defined(ETHARP_VLAN_CHECK)
|
||||
if (VLAN_ID(vlan) != ETHARP_VLAN_CHECK) {
|
||||
#endif
|
||||
/* silently ignore this packet: not for our VLAN */
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* defined(LWIP_HOOK_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK_FN) */
|
||||
type = vlan->tpid;
|
||||
ip_hdr_offset = SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR;
|
||||
}
|
||||
#endif /* ETHARP_SUPPORT_VLAN */
|
||||
|
||||
#if LWIP_ARP_FILTER_NETIF
|
||||
netif = LWIP_ARP_FILTER_NETIF_FN(p, netif, htons(type));
|
||||
#endif /* LWIP_ARP_FILTER_NETIF*/
|
||||
|
||||
if (ethhdr->dest.addr[0] & 1) {
|
||||
/* this might be a multicast or broadcast packet */
|
||||
if (ethhdr->dest.addr[0] == LL_IP4_MULTICAST_ADDR_0) {
|
||||
#if LWIP_IPV4
|
||||
if ((ethhdr->dest.addr[1] == LL_IP4_MULTICAST_ADDR_1) &&
|
||||
(ethhdr->dest.addr[2] == LL_IP4_MULTICAST_ADDR_2)) {
|
||||
/* mark the pbuf as link-layer multicast */
|
||||
p->flags |= PBUF_FLAG_LLMCAST;
|
||||
}
|
||||
#endif /* LWIP_IPV4 */
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
else if ((ethhdr->dest.addr[0] == LL_IP6_MULTICAST_ADDR_0) &&
|
||||
(ethhdr->dest.addr[1] == LL_IP6_MULTICAST_ADDR_1)) {
|
||||
/* mark the pbuf as link-layer multicast */
|
||||
p->flags |= PBUF_FLAG_LLMCAST;
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
else if (eth_addr_cmp(ðhdr->dest, ðbroadcast)) {
|
||||
/* mark the pbuf as link-layer broadcast */
|
||||
p->flags |= PBUF_FLAG_LLBCAST;
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
#if LWIP_IPV4 && LWIP_ARP
|
||||
/* IP packet? */
|
||||
case PP_HTONS(ETHTYPE_IP):
|
||||
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
|
||||
goto free_and_return;
|
||||
}
|
||||
#if ETHARP_TRUST_IP_MAC
|
||||
/* update ARP table */
|
||||
etharp_ip_input(netif, p);
|
||||
#endif /* ETHARP_TRUST_IP_MAC */
|
||||
/* skip Ethernet header */
|
||||
if ((p->len < ip_hdr_offset) || pbuf_header(p, (s16_t)-ip_hdr_offset)) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
|
||||
("ethernet_input: IPv4 packet dropped, too short (%"S16_F"/%"S16_F")\n",
|
||||
p->tot_len, ip_hdr_offset));
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("Can't move over header in packet"));
|
||||
goto free_and_return;
|
||||
} else {
|
||||
/* pass to IP layer */
|
||||
ip4_input(p, netif);
|
||||
}
|
||||
break;
|
||||
|
||||
case PP_HTONS(ETHTYPE_ARP):
|
||||
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
|
||||
goto free_and_return;
|
||||
}
|
||||
/* pass p to ARP module */
|
||||
etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p);
|
||||
break;
|
||||
#endif /* LWIP_IPV4 && LWIP_ARP */
|
||||
#if PPPOE_SUPPORT
|
||||
case PP_HTONS(ETHTYPE_PPPOEDISC): /* PPP Over Ethernet Discovery Stage */
|
||||
pppoe_disc_input(netif, p);
|
||||
break;
|
||||
|
||||
case PP_HTONS(ETHTYPE_PPPOE): /* PPP Over Ethernet Session Stage */
|
||||
pppoe_data_input(netif, p);
|
||||
break;
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
#if LWIP_IPV6
|
||||
case PP_HTONS(ETHTYPE_IPV6): /* IPv6 */
|
||||
/* skip Ethernet header */
|
||||
if ((p->len < ip_hdr_offset) || pbuf_header(p, (s16_t)-ip_hdr_offset)) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
|
||||
("ethernet_input: IPv6 packet dropped, too short (%"S16_F"/%"S16_F")\n",
|
||||
p->tot_len, ip_hdr_offset));
|
||||
goto free_and_return;
|
||||
} else {
|
||||
/* pass to IPv6 layer */
|
||||
|
||||
LWIP_DEBUGF(IP6_DEBUG, ("calling ip6_input()"));
|
||||
ip6_input(p, netif);
|
||||
}
|
||||
break;
|
||||
#endif /* LWIP_IPV6 */
|
||||
|
||||
default:
|
||||
ETHARP_STATS_INC(etharp.proterr);
|
||||
ETHARP_STATS_INC(etharp.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifinunknownprotos);
|
||||
goto free_and_return;
|
||||
}
|
||||
|
||||
/* This means the pbuf is freed or consumed,
|
||||
so the caller doesn't have to free it again */
|
||||
return ERR_OK;
|
||||
|
||||
free_and_return:
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_ARP || LWIP_ETHERNET */
|
||||
/**
|
||||
* @file
|
||||
* Ethernet common functions
|
||||
*
|
||||
* @defgroup ethernet Ethernet
|
||||
* @ingroup callbackstyle_api
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
|
||||
* Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_ARP || LWIP_ETHERNET
|
||||
|
||||
#include "netif/ethernet.h"
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/snmp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPPOE_SUPPORT
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
#ifdef LWIP_HOOK_FILENAME
|
||||
#include LWIP_HOOK_FILENAME
|
||||
#endif
|
||||
|
||||
const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
|
||||
const struct eth_addr ethzero = {{0,0,0,0,0,0}};
|
||||
|
||||
/**
|
||||
* @ingroup lwip_nosys
|
||||
* Process received ethernet frames. Using this function instead of directly
|
||||
* calling ip_input and passing ARP frames through etharp in ethernetif_input,
|
||||
* the ARP cache is protected from concurrent access.\n
|
||||
* Don't call directly, pass to netif_add() and call netif->input().
|
||||
*
|
||||
* @param p the received packet, p->payload pointing to the ethernet header
|
||||
* @param netif the network interface on which the packet was received
|
||||
*
|
||||
* @see LWIP_HOOK_UNKNOWN_ETH_PROTOCOL
|
||||
* @see ETHARP_SUPPORT_VLAN
|
||||
* @see LWIP_HOOK_VLAN_CHECK
|
||||
*/
|
||||
err_t
|
||||
ethernet_input(struct pbuf *p, struct netif *netif)
|
||||
{
|
||||
struct eth_hdr* ethhdr;
|
||||
u16_t type;
|
||||
#if LWIP_ARP || ETHARP_SUPPORT_VLAN || LWIP_IPV6
|
||||
s16_t ip_hdr_offset = SIZEOF_ETH_HDR;
|
||||
#endif /* LWIP_ARP || ETHARP_SUPPORT_VLAN */
|
||||
|
||||
if (p->len <= SIZEOF_ETH_HDR) {
|
||||
/* a packet with only an ethernet header (or less) is not valid for us */
|
||||
ETHARP_STATS_INC(etharp.proterr);
|
||||
ETHARP_STATS_INC(etharp.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifinerrors);
|
||||
goto free_and_return;
|
||||
}
|
||||
|
||||
/* points to packet payload, which starts with an Ethernet header */
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
|
||||
("ethernet_input: dest:%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F", src:%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F":%"X8_F", type:%"X16_F"\n",
|
||||
(unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], (unsigned)ethhdr->dest.addr[2],
|
||||
(unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], (unsigned)ethhdr->dest.addr[5],
|
||||
(unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], (unsigned)ethhdr->src.addr[2],
|
||||
(unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], (unsigned)ethhdr->src.addr[5],
|
||||
lwip_htons(ethhdr->type)));
|
||||
|
||||
type = ethhdr->type;
|
||||
#if ETHARP_SUPPORT_VLAN
|
||||
if (type == PP_HTONS(ETHTYPE_VLAN)) {
|
||||
struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr*)(((char*)ethhdr) + SIZEOF_ETH_HDR);
|
||||
if (p->len <= SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR) {
|
||||
/* a packet with only an ethernet/vlan header (or less) is not valid for us */
|
||||
ETHARP_STATS_INC(etharp.proterr);
|
||||
ETHARP_STATS_INC(etharp.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifinerrors);
|
||||
goto free_and_return;
|
||||
}
|
||||
#if defined(LWIP_HOOK_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK_FN) /* if not, allow all VLANs */
|
||||
#ifdef LWIP_HOOK_VLAN_CHECK
|
||||
if (!LWIP_HOOK_VLAN_CHECK(netif, ethhdr, vlan)) {
|
||||
#elif defined(ETHARP_VLAN_CHECK_FN)
|
||||
if (!ETHARP_VLAN_CHECK_FN(ethhdr, vlan)) {
|
||||
#elif defined(ETHARP_VLAN_CHECK)
|
||||
if (VLAN_ID(vlan) != ETHARP_VLAN_CHECK) {
|
||||
#endif
|
||||
/* silently ignore this packet: not for our VLAN */
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* defined(LWIP_HOOK_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK_FN) */
|
||||
type = vlan->tpid;
|
||||
ip_hdr_offset = SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR;
|
||||
}
|
||||
#endif /* ETHARP_SUPPORT_VLAN */
|
||||
|
||||
#if LWIP_ARP_FILTER_NETIF
|
||||
netif = LWIP_ARP_FILTER_NETIF_FN(p, netif, lwip_htons(type));
|
||||
#endif /* LWIP_ARP_FILTER_NETIF*/
|
||||
|
||||
if (ethhdr->dest.addr[0] & 1) {
|
||||
/* this might be a multicast or broadcast packet */
|
||||
if (ethhdr->dest.addr[0] == LL_IP4_MULTICAST_ADDR_0) {
|
||||
#if LWIP_IPV4
|
||||
if ((ethhdr->dest.addr[1] == LL_IP4_MULTICAST_ADDR_1) &&
|
||||
(ethhdr->dest.addr[2] == LL_IP4_MULTICAST_ADDR_2)) {
|
||||
/* mark the pbuf as link-layer multicast */
|
||||
p->flags |= PBUF_FLAG_LLMCAST;
|
||||
}
|
||||
#endif /* LWIP_IPV4 */
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
else if ((ethhdr->dest.addr[0] == LL_IP6_MULTICAST_ADDR_0) &&
|
||||
(ethhdr->dest.addr[1] == LL_IP6_MULTICAST_ADDR_1)) {
|
||||
/* mark the pbuf as link-layer multicast */
|
||||
p->flags |= PBUF_FLAG_LLMCAST;
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
else if (eth_addr_cmp(ðhdr->dest, ðbroadcast)) {
|
||||
/* mark the pbuf as link-layer broadcast */
|
||||
p->flags |= PBUF_FLAG_LLBCAST;
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
#if LWIP_IPV4 && LWIP_ARP
|
||||
/* IP packet? */
|
||||
case PP_HTONS(ETHTYPE_IP):
|
||||
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
|
||||
goto free_and_return;
|
||||
}
|
||||
/* skip Ethernet header */
|
||||
if ((p->len < ip_hdr_offset) || pbuf_header(p, (s16_t)-ip_hdr_offset)) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
|
||||
("ethernet_input: IPv4 packet dropped, too short (%"S16_F"/%"S16_F")\n",
|
||||
p->tot_len, ip_hdr_offset));
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("Can't move over header in packet"));
|
||||
goto free_and_return;
|
||||
} else {
|
||||
/* pass to IP layer */
|
||||
ip4_input(p, netif);
|
||||
}
|
||||
break;
|
||||
|
||||
case PP_HTONS(ETHTYPE_ARP):
|
||||
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
|
||||
goto free_and_return;
|
||||
}
|
||||
/* skip Ethernet header */
|
||||
if ((p->len < ip_hdr_offset) || pbuf_header(p, (s16_t)-ip_hdr_offset)) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
|
||||
("ethernet_input: ARP response packet dropped, too short (%"S16_F"/%"S16_F")\n",
|
||||
p->tot_len, ip_hdr_offset));
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("Can't move over header in packet"));
|
||||
ETHARP_STATS_INC(etharp.lenerr);
|
||||
ETHARP_STATS_INC(etharp.drop);
|
||||
goto free_and_return;
|
||||
} else {
|
||||
/* pass p to ARP module */
|
||||
etharp_input(p, netif);
|
||||
}
|
||||
break;
|
||||
#endif /* LWIP_IPV4 && LWIP_ARP */
|
||||
#if PPPOE_SUPPORT
|
||||
case PP_HTONS(ETHTYPE_PPPOEDISC): /* PPP Over Ethernet Discovery Stage */
|
||||
pppoe_disc_input(netif, p);
|
||||
break;
|
||||
|
||||
case PP_HTONS(ETHTYPE_PPPOE): /* PPP Over Ethernet Session Stage */
|
||||
pppoe_data_input(netif, p);
|
||||
break;
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
#if LWIP_IPV6
|
||||
case PP_HTONS(ETHTYPE_IPV6): /* IPv6 */
|
||||
/* skip Ethernet header */
|
||||
if ((p->len < ip_hdr_offset) || pbuf_header(p, (s16_t)-ip_hdr_offset)) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
|
||||
("ethernet_input: IPv6 packet dropped, too short (%"S16_F"/%"S16_F")\n",
|
||||
p->tot_len, ip_hdr_offset));
|
||||
goto free_and_return;
|
||||
} else {
|
||||
/* pass to IPv6 layer */
|
||||
ip6_input(p, netif);
|
||||
}
|
||||
break;
|
||||
#endif /* LWIP_IPV6 */
|
||||
|
||||
default:
|
||||
#ifdef LWIP_HOOK_UNKNOWN_ETH_PROTOCOL
|
||||
if(LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(p, netif) == ERR_OK) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
ETHARP_STATS_INC(etharp.proterr);
|
||||
ETHARP_STATS_INC(etharp.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifinunknownprotos);
|
||||
goto free_and_return;
|
||||
}
|
||||
|
||||
/* This means the pbuf is freed or consumed,
|
||||
so the caller doesn't have to free it again */
|
||||
return ERR_OK;
|
||||
|
||||
free_and_return:
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup ethernet
|
||||
* Send an ethernet packet on the network using netif->linkoutput().
|
||||
* The ethernet header is filled in before sending.
|
||||
*
|
||||
* @see LWIP_HOOK_VLAN_SET
|
||||
*
|
||||
* @param netif the lwIP network interface on which to send the packet
|
||||
* @param p the packet to send. pbuf layer must be @ref PBUF_LINK.
|
||||
* @param src the source MAC address to be copied into the ethernet header
|
||||
* @param dst the destination MAC address to be copied into the ethernet header
|
||||
* @param eth_type ethernet type (@ref eth_type)
|
||||
* @return ERR_OK if the packet was sent, any other err_t on failure
|
||||
*/
|
||||
err_t
|
||||
ethernet_output(struct netif* netif, struct pbuf* p,
|
||||
const struct eth_addr* src, const struct eth_addr* dst,
|
||||
u16_t eth_type)
|
||||
{
|
||||
struct eth_hdr* ethhdr;
|
||||
u16_t eth_type_be = lwip_htons(eth_type);
|
||||
|
||||
#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET)
|
||||
s32_t vlan_prio_vid = LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type);
|
||||
if (vlan_prio_vid >= 0) {
|
||||
struct eth_vlan_hdr* vlanhdr;
|
||||
|
||||
LWIP_ASSERT("prio_vid must be <= 0xFFFF", vlan_prio_vid <= 0xFFFF);
|
||||
|
||||
if (pbuf_header(p, SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR) != 0) {
|
||||
goto pbuf_header_failed;
|
||||
}
|
||||
vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)p->payload) + SIZEOF_ETH_HDR);
|
||||
vlanhdr->tpid = eth_type_be;
|
||||
vlanhdr->prio_vid = lwip_htons((u16_t)vlan_prio_vid);
|
||||
|
||||
eth_type_be = PP_HTONS(ETHTYPE_VLAN);
|
||||
} else
|
||||
#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */
|
||||
{
|
||||
if (pbuf_header(p, SIZEOF_ETH_HDR) != 0) {
|
||||
goto pbuf_header_failed;
|
||||
}
|
||||
}
|
||||
|
||||
ethhdr = (struct eth_hdr*)p->payload;
|
||||
ethhdr->type = eth_type_be;
|
||||
ETHADDR32_COPY(ðhdr->dest, dst);
|
||||
ETHADDR16_COPY(ðhdr->src, src);
|
||||
|
||||
LWIP_ASSERT("netif->hwaddr_len must be 6 for ethernet_output!",
|
||||
(netif->hwaddr_len == ETH_HWADDR_LEN));
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
|
||||
("ethernet_output: sending packet %p\n", (void *)p));
|
||||
|
||||
/* send the packet */
|
||||
return netif->linkoutput(netif, p);
|
||||
|
||||
pbuf_header_failed:
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
|
||||
("ethernet_output: could not allocate room for header.\n"));
|
||||
LINK_STATS_INC(link.lenerr);
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
#endif /* LWIP_ARP || LWIP_ETHERNET */
|
||||
|
||||
670
ext/lwip/src/netif/ethernetif.c
Normal file → Executable file
670
ext/lwip/src/netif/ethernetif.c
Normal file → Executable file
@@ -1,335 +1,335 @@
|
||||
/**
|
||||
* @file
|
||||
* Ethernet Interface Skeleton
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 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>
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is a skeleton for developing Ethernet network interface
|
||||
* drivers for lwIP. Add code to the low_level functions and do a
|
||||
* search-and-replace for the word "ethernetif" to replace it with
|
||||
* something that better describes your network interface.
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if 0 /* don't build, this is only a skeleton, see previous comment */
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/snmp.h"
|
||||
#include "lwip/ethip6.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "netif/ppp/pppoe.h"
|
||||
|
||||
/* Define those to better describe your network interface. */
|
||||
#define IFNAME0 'e'
|
||||
#define IFNAME1 'n'
|
||||
|
||||
/**
|
||||
* Helper struct to hold private data used to operate your ethernet interface.
|
||||
* Keeping the ethernet address of the MAC in this struct is not necessary
|
||||
* as it is already kept in the struct netif.
|
||||
* But this is only an example, anyway...
|
||||
*/
|
||||
struct ethernetif {
|
||||
struct eth_addr *ethaddr;
|
||||
/* Add whatever per-interface state that is needed here. */
|
||||
};
|
||||
|
||||
/* Forward declarations. */
|
||||
static void ethernetif_input(struct netif *netif);
|
||||
|
||||
/**
|
||||
* In this function, the hardware should be initialized.
|
||||
* Called from ethernetif_init().
|
||||
*
|
||||
* @param netif the already initialized lwip network interface structure
|
||||
* for this ethernetif
|
||||
*/
|
||||
static void
|
||||
low_level_init(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
|
||||
/* set MAC hardware address length */
|
||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||
|
||||
/* set MAC hardware address */
|
||||
netif->hwaddr[0] = ;
|
||||
...
|
||||
netif->hwaddr[5] = ;
|
||||
|
||||
/* maximum transfer unit */
|
||||
netif->mtu = 1500;
|
||||
|
||||
/* device capabilities */
|
||||
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
|
||||
|
||||
#if LWIP_IPV6 && LWIP_IPV6_MLD
|
||||
/*
|
||||
* For hardware/netifs that implement MAC filtering.
|
||||
* All-nodes link-local is handled by default, so we must let the hardware know
|
||||
* to allow multicast packets in.
|
||||
* Should set mld_mac_filter previously. */
|
||||
if (netif->mld_mac_filter != NULL) {
|
||||
ip6_addr_t ip6_allnodes_ll;
|
||||
ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll);
|
||||
netif->mld_mac_filter(netif, &ip6_allnodes_ll, MLD6_ADD_MAC_FILTER);
|
||||
}
|
||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
|
||||
|
||||
/* Do whatever else is needed to initialize interface. */
|
||||
}
|
||||
|
||||
/**
|
||||
* This function 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.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
|
||||
* @return ERR_OK if the packet could be sent
|
||||
* an err_t value if the packet couldn't be sent
|
||||
*
|
||||
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
|
||||
* strange results. You might consider waiting for space in the DMA queue
|
||||
* to become available since the stack doesn't retry to send a packet
|
||||
* dropped because of memory failure (except for the TCP timers).
|
||||
*/
|
||||
|
||||
static err_t
|
||||
low_level_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
struct pbuf *q;
|
||||
|
||||
initiate transfer();
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
|
||||
#endif
|
||||
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
/* Send the data from the pbuf to the interface, one pbuf at a
|
||||
time. The size of the data in each pbuf is kept in the ->len
|
||||
variable. */
|
||||
send data from(q->payload, q->len);
|
||||
}
|
||||
|
||||
signal that packet should be sent();
|
||||
|
||||
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
|
||||
if (((u8_t*)p->payload)[0] & 1) {
|
||||
/* broadcast or multicast packet*/
|
||||
MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts);
|
||||
} else {
|
||||
/* unicast packet */
|
||||
MIB2_STATS_NETIF_INC(netif, ifoutucastpkts);
|
||||
}
|
||||
/* increase ifoutdiscards or ifouterrors on error */
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
|
||||
#endif
|
||||
|
||||
LINK_STATS_INC(link.xmit);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should allocate a pbuf and transfer the bytes of the incoming
|
||||
* packet from the interface into the pbuf.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return a pbuf filled with the received packet (including MAC header)
|
||||
* NULL on memory error
|
||||
*/
|
||||
static struct pbuf *
|
||||
low_level_input(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
struct pbuf *p, *q;
|
||||
u16_t len;
|
||||
|
||||
/* Obtain the size of the packet and put it into the "len"
|
||||
variable. */
|
||||
len = ;
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
|
||||
#endif
|
||||
|
||||
/* We allocate a pbuf chain of pbufs from the pool. */
|
||||
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
|
||||
|
||||
if (p != NULL) {
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
|
||||
#endif
|
||||
|
||||
/* We iterate over the pbuf chain until we have read the entire
|
||||
* packet into the pbuf. */
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
/* Read enough bytes to fill this pbuf in the chain. The
|
||||
* available data in the pbuf is given by the q->len
|
||||
* variable.
|
||||
* This does not necessarily have to be a memcpy, you can also preallocate
|
||||
* pbufs for a DMA-enabled MAC and after receiving truncate it to the
|
||||
* actually received size. In this case, ensure the tot_len member of the
|
||||
* pbuf is the sum of the chained pbuf len members.
|
||||
*/
|
||||
read data into(q->payload, q->len);
|
||||
}
|
||||
acknowledge that packet has been read();
|
||||
|
||||
MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
|
||||
if (((u8_t*)p->payload)[0] & 1) {
|
||||
/* broadcast or multicast packet*/
|
||||
MIB2_STATS_NETIF_INC(netif, ifinnucastpkts);
|
||||
} else {
|
||||
/* unicast packet*/
|
||||
MIB2_STATS_NETIF_INC(netif, ifinucastpkts);
|
||||
}
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
|
||||
#endif
|
||||
|
||||
LINK_STATS_INC(link.recv);
|
||||
} else {
|
||||
drop packet();
|
||||
LINK_STATS_INC(link.memerr);
|
||||
LINK_STATS_INC(link.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifindiscards);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should be called when a packet is ready to be read
|
||||
* from the interface. It uses the function low_level_input() that
|
||||
* should handle the actual reception of bytes from the network
|
||||
* interface. Then the type of the received packet is determined and
|
||||
* the appropriate input function is called.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
*/
|
||||
static void
|
||||
ethernetif_input(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif;
|
||||
struct eth_hdr *ethhdr;
|
||||
struct pbuf *p;
|
||||
|
||||
ethernetif = netif->state;
|
||||
|
||||
/* move received packet into a new pbuf */
|
||||
p = low_level_input(netif);
|
||||
/* if no packet could be read, silently ignore this */
|
||||
if (p != NULL) {
|
||||
/* pass all packets to ethernet_input, which decides what packets it supports */
|
||||
if (netif->input(p, netif) != ERR_OK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* This function should be passed as a parameter to netif_add().
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return ERR_OK if the loopif is initialized
|
||||
* ERR_MEM if private data couldn't be allocated
|
||||
* any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
ethernetif_init(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif;
|
||||
|
||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||
|
||||
ethernetif = mem_malloc(sizeof(struct ethernetif));
|
||||
if (ethernetif == NULL) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
/* Initialize interface hostname */
|
||||
netif->hostname = "lwip";
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
/*
|
||||
* Initialize the snmp variables and counters inside the struct netif.
|
||||
* The last argument should be replaced with your link speed, in units
|
||||
* of bits per second.
|
||||
*/
|
||||
MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
|
||||
|
||||
netif->state = ethernetif;
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
/* We directly use etharp_output() here to save a function call.
|
||||
* You can instead declare your own function an call etharp_output()
|
||||
* from it if you have to do some checks before sending (e.g. if link
|
||||
* is available...) */
|
||||
netif->output = etharp_output;
|
||||
#if LWIP_IPV6
|
||||
netif->output_ip6 = ethip6_output;
|
||||
#endif /* LWIP_IPV6 */
|
||||
netif->linkoutput = low_level_output;
|
||||
|
||||
ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
|
||||
|
||||
/* initialize the hardware */
|
||||
low_level_init(netif);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#endif /* 0 */
|
||||
/**
|
||||
* @file
|
||||
* Ethernet Interface Skeleton
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 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>
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is a skeleton for developing Ethernet network interface
|
||||
* drivers for lwIP. Add code to the low_level functions and do a
|
||||
* search-and-replace for the word "ethernetif" to replace it with
|
||||
* something that better describes your network interface.
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if 0 /* don't build, this is only a skeleton, see previous comment */
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/snmp.h"
|
||||
#include "lwip/ethip6.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "netif/ppp/pppoe.h"
|
||||
|
||||
/* Define those to better describe your network interface. */
|
||||
#define IFNAME0 'e'
|
||||
#define IFNAME1 'n'
|
||||
|
||||
/**
|
||||
* Helper struct to hold private data used to operate your ethernet interface.
|
||||
* Keeping the ethernet address of the MAC in this struct is not necessary
|
||||
* as it is already kept in the struct netif.
|
||||
* But this is only an example, anyway...
|
||||
*/
|
||||
struct ethernetif {
|
||||
struct eth_addr *ethaddr;
|
||||
/* Add whatever per-interface state that is needed here. */
|
||||
};
|
||||
|
||||
/* Forward declarations. */
|
||||
static void ethernetif_input(struct netif *netif);
|
||||
|
||||
/**
|
||||
* In this function, the hardware should be initialized.
|
||||
* Called from ethernetif_init().
|
||||
*
|
||||
* @param netif the already initialized lwip network interface structure
|
||||
* for this ethernetif
|
||||
*/
|
||||
static void
|
||||
low_level_init(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
|
||||
/* set MAC hardware address length */
|
||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||
|
||||
/* set MAC hardware address */
|
||||
netif->hwaddr[0] = ;
|
||||
...
|
||||
netif->hwaddr[5] = ;
|
||||
|
||||
/* maximum transfer unit */
|
||||
netif->mtu = 1500;
|
||||
|
||||
/* device capabilities */
|
||||
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
|
||||
|
||||
#if LWIP_IPV6 && LWIP_IPV6_MLD
|
||||
/*
|
||||
* For hardware/netifs that implement MAC filtering.
|
||||
* All-nodes link-local is handled by default, so we must let the hardware know
|
||||
* to allow multicast packets in.
|
||||
* Should set mld_mac_filter previously. */
|
||||
if (netif->mld_mac_filter != NULL) {
|
||||
ip6_addr_t ip6_allnodes_ll;
|
||||
ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll);
|
||||
netif->mld_mac_filter(netif, &ip6_allnodes_ll, NETIF_ADD_MAC_FILTER);
|
||||
}
|
||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
|
||||
|
||||
/* Do whatever else is needed to initialize interface. */
|
||||
}
|
||||
|
||||
/**
|
||||
* This function 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.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
|
||||
* @return ERR_OK if the packet could be sent
|
||||
* an err_t value if the packet couldn't be sent
|
||||
*
|
||||
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
|
||||
* strange results. You might consider waiting for space in the DMA queue
|
||||
* to become available since the stack doesn't retry to send a packet
|
||||
* dropped because of memory failure (except for the TCP timers).
|
||||
*/
|
||||
|
||||
static err_t
|
||||
low_level_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
struct pbuf *q;
|
||||
|
||||
initiate transfer();
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
|
||||
#endif
|
||||
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
/* Send the data from the pbuf to the interface, one pbuf at a
|
||||
time. The size of the data in each pbuf is kept in the ->len
|
||||
variable. */
|
||||
send data from(q->payload, q->len);
|
||||
}
|
||||
|
||||
signal that packet should be sent();
|
||||
|
||||
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
|
||||
if (((u8_t*)p->payload)[0] & 1) {
|
||||
/* broadcast or multicast packet*/
|
||||
MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts);
|
||||
} else {
|
||||
/* unicast packet */
|
||||
MIB2_STATS_NETIF_INC(netif, ifoutucastpkts);
|
||||
}
|
||||
/* increase ifoutdiscards or ifouterrors on error */
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
|
||||
#endif
|
||||
|
||||
LINK_STATS_INC(link.xmit);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should allocate a pbuf and transfer the bytes of the incoming
|
||||
* packet from the interface into the pbuf.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return a pbuf filled with the received packet (including MAC header)
|
||||
* NULL on memory error
|
||||
*/
|
||||
static struct pbuf *
|
||||
low_level_input(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
struct pbuf *p, *q;
|
||||
u16_t len;
|
||||
|
||||
/* Obtain the size of the packet and put it into the "len"
|
||||
variable. */
|
||||
len = ;
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
|
||||
#endif
|
||||
|
||||
/* We allocate a pbuf chain of pbufs from the pool. */
|
||||
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
|
||||
|
||||
if (p != NULL) {
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
|
||||
#endif
|
||||
|
||||
/* We iterate over the pbuf chain until we have read the entire
|
||||
* packet into the pbuf. */
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
/* Read enough bytes to fill this pbuf in the chain. The
|
||||
* available data in the pbuf is given by the q->len
|
||||
* variable.
|
||||
* This does not necessarily have to be a memcpy, you can also preallocate
|
||||
* pbufs for a DMA-enabled MAC and after receiving truncate it to the
|
||||
* actually received size. In this case, ensure the tot_len member of the
|
||||
* pbuf is the sum of the chained pbuf len members.
|
||||
*/
|
||||
read data into(q->payload, q->len);
|
||||
}
|
||||
acknowledge that packet has been read();
|
||||
|
||||
MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
|
||||
if (((u8_t*)p->payload)[0] & 1) {
|
||||
/* broadcast or multicast packet*/
|
||||
MIB2_STATS_NETIF_INC(netif, ifinnucastpkts);
|
||||
} else {
|
||||
/* unicast packet*/
|
||||
MIB2_STATS_NETIF_INC(netif, ifinucastpkts);
|
||||
}
|
||||
#if ETH_PAD_SIZE
|
||||
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
|
||||
#endif
|
||||
|
||||
LINK_STATS_INC(link.recv);
|
||||
} else {
|
||||
drop packet();
|
||||
LINK_STATS_INC(link.memerr);
|
||||
LINK_STATS_INC(link.drop);
|
||||
MIB2_STATS_NETIF_INC(netif, ifindiscards);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should be called when a packet is ready to be read
|
||||
* from the interface. It uses the function low_level_input() that
|
||||
* should handle the actual reception of bytes from the network
|
||||
* interface. Then the type of the received packet is determined and
|
||||
* the appropriate input function is called.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
*/
|
||||
static void
|
||||
ethernetif_input(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif;
|
||||
struct eth_hdr *ethhdr;
|
||||
struct pbuf *p;
|
||||
|
||||
ethernetif = netif->state;
|
||||
|
||||
/* move received packet into a new pbuf */
|
||||
p = low_level_input(netif);
|
||||
/* if no packet could be read, silently ignore this */
|
||||
if (p != NULL) {
|
||||
/* pass all packets to ethernet_input, which decides what packets it supports */
|
||||
if (netif->input(p, netif) != ERR_OK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* This function should be passed as a parameter to netif_add().
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return ERR_OK if the loopif is initialized
|
||||
* ERR_MEM if private data couldn't be allocated
|
||||
* any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
ethernetif_init(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif;
|
||||
|
||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||
|
||||
ethernetif = mem_malloc(sizeof(struct ethernetif));
|
||||
if (ethernetif == NULL) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
/* Initialize interface hostname */
|
||||
netif->hostname = "lwip";
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
/*
|
||||
* Initialize the snmp variables and counters inside the struct netif.
|
||||
* The last argument should be replaced with your link speed, in units
|
||||
* of bits per second.
|
||||
*/
|
||||
MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
|
||||
|
||||
netif->state = ethernetif;
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
/* We directly use etharp_output() here to save a function call.
|
||||
* You can instead declare your own function an call etharp_output()
|
||||
* from it if you have to do some checks before sending (e.g. if link
|
||||
* is available...) */
|
||||
netif->output = etharp_output;
|
||||
#if LWIP_IPV6
|
||||
netif->output_ip6 = ethip6_output;
|
||||
#endif /* LWIP_IPV6 */
|
||||
netif->linkoutput = low_level_output;
|
||||
|
||||
ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
|
||||
|
||||
/* initialize the hardware */
|
||||
low_level_init(netif);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#endif /* 0 */
|
||||
|
||||
2397
ext/lwip/src/netif/lowpan6.c
Normal file → Executable file
2397
ext/lwip/src/netif/lowpan6.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
946
ext/lwip/src/netif/ppp/PPPD_FOLLOWUP
Normal file → Executable file
946
ext/lwip/src/netif/ppp/PPPD_FOLLOWUP
Normal file → Executable file
@@ -1,473 +1,473 @@
|
||||
The lwIP PPP support is based from pppd 2.4.5 (http://ppp.samba.org) with
|
||||
huge changes to match code size and memory requirements for embedded devices.
|
||||
|
||||
Anyway, pppd has a mature codebase for years and the average commit count
|
||||
is getting low on their Git repository, meaning that we can follow what
|
||||
is happening on their side and merge what is relevant for lwIP.
|
||||
|
||||
So, here is the pppd follow up, so that we don't get away too far from pppd.
|
||||
|
||||
|
||||
== Patch fetched from from pppd Debian packages ==
|
||||
|
||||
This has nothing to do with pppd, but we merged some good patch from
|
||||
Debian and this is a good place to be.
|
||||
|
||||
- LCP adaptive echo, so that we don't send LCP echo request if we
|
||||
are receiving data from peer, can be enabled by setting PPP_LCP_ADAPTIVE
|
||||
to true.
|
||||
|
||||
- IPCP no/replace default route option, were added in the early stage of
|
||||
the ppp port, but it wasn't really helpful and was disabled when adding
|
||||
the new API ppp_set_default() call, which gives the lwIP user control over
|
||||
which one is the default interface, it was actually a requirement if you
|
||||
are doing PPP over PPP (i.e. PPPoL2TP, VPN link, over PPPoE, ADSL link).
|
||||
|
||||
- using rp-pppoe pppd exits with EXIT_OK after receiving a timeout waiting
|
||||
for PADO due to no modem attached, bug reported to pppd bug tracker, fixed
|
||||
in Debian but not in the latest (at the time when the port were started)
|
||||
pppd release.
|
||||
|
||||
|
||||
== Commits on pppd ==
|
||||
|
||||
2010-03-06 - Document +ipv6 and ipv6cp-accept-local
|
||||
e7537958aee79b3f653c601e903cb31d78fb7dcc
|
||||
|
||||
Don't care.
|
||||
|
||||
|
||||
2010-03-06 - Install pppol2tp plugins with sane permissions
|
||||
406215672cfadc03017341fe03802d1c7294b903
|
||||
|
||||
Don't care.
|
||||
|
||||
|
||||
2010-03-07 - pppd: Terminate correctly if lcp_lowerup delayed calling
|
||||
fsm_lowerup
|
||||
3eb9e810cfa515543655659b72dde30c54fea0a5
|
||||
|
||||
Merged 2012-05-17.
|
||||
|
||||
|
||||
2010-03-07 - rp_pppoe: Copy acName and pppd_pppoe_service after option parsing
|
||||
cab58617fd9d328029fffabc788020264b4fa91f
|
||||
|
||||
Don't care, is a patch for pppd/plugins/rp-pppoe/plugin.c which is not part
|
||||
of the port.
|
||||
|
||||
|
||||
2010-08-23 - set and reset options to control environment variables
|
||||
for scripts.
|
||||
2b6310fd24dba8e0fca8999916a162f0a1842a84
|
||||
|
||||
We can't fork processes in embedded, therefore all the pppd process run
|
||||
feature is disabled in the port, so we don't care about the new
|
||||
"environment variables" pppd feature.
|
||||
|
||||
|
||||
2010-08-23 - Nit: use _exit when exec fails and restrict values to 0-255
|
||||
per POSIX.
|
||||
2b4ea140432eeba5a007c0d4e6236bd0e0c12ba4
|
||||
|
||||
Again, we are not running as a heavy process, so all exit() or _exit() calls
|
||||
were removed.
|
||||
|
||||
|
||||
2010-08-23 - Fix quote handling in configuration files to be more like shell
|
||||
quoting.
|
||||
3089132cdf5b58dbdfc2daf08ec5c08eb47f8aca
|
||||
|
||||
We are not parsing config file, all the filesystem I/O stuff were disabled
|
||||
in our port.
|
||||
|
||||
|
||||
2010-08-24 - rp-pppoe: allow MTU to be increased up to 1500
|
||||
fd1dcdf758418f040da3ed801ab001b5e46854e7
|
||||
|
||||
Only concern changes on RP-PPPoE plugin, which we don't use.
|
||||
|
||||
|
||||
2010-09-11 - chat: Allow TIMEOUT value to come from environment variable
|
||||
ae80bf833e48a6202f44a935a68083ae52ad3824
|
||||
|
||||
See 2b6310fd24dba8e0fca8999916a162f0a1842a84.
|
||||
|
||||
|
||||
2011-03-05 - pppdump: Fix printfs with insufficient arguments
|
||||
7b8db569642c83ba3283745034f2e2c95e459423
|
||||
|
||||
pppdump is a ppp tool outside pppd source tree.
|
||||
|
||||
|
||||
2012-05-06 - pppd: Don't unconditionally disable VJ compression under Linux
|
||||
d8a66adf98a0e525cf38031b42098d539da6eeb6
|
||||
|
||||
Patch for sys-linux.c, which we don't use.
|
||||
|
||||
|
||||
2012-05-20 - Remove old version of Linux if_pppol2tp.h
|
||||
c41092dd4c49267f232f6cba3d31c6c68bfdf68d
|
||||
|
||||
Not in the port.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Make MSCHAP-v2 cope better with packet loss
|
||||
08ef47ca532294eb428238c831616748940e24a2
|
||||
|
||||
This is an interesting patch. However it consumes much more memory for
|
||||
MSCHAP and I am not sure if the benefit worth it. The PPP client can
|
||||
always start the authentication again if it failed for whatever reason.
|
||||
|
||||
|
||||
2012-05-20 - scripts: Make poff ignore extra arguments to pppd
|
||||
18f515f32c9f5723a9c2c912601e04335106534b
|
||||
|
||||
Again, we are not running scripts.
|
||||
|
||||
|
||||
2012-05-20 - rp-pppoe plugin: Print leading zeros in MAC address
|
||||
f5dda0cfc220c4b52e26144096d729e27b30f0f7
|
||||
|
||||
Again, we are not using the RP-PPPoE plugin.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Notify IPv6 up/down as we do for IPv4
|
||||
845cda8fa18939cf56e60b073f63a7efa65336fc
|
||||
|
||||
This is just a patch that adds plugins hooks for IPv6, the plugin interface
|
||||
was disabled because we don't have .so plugins in embedded.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Enable IPV6 by default and fix some warnings
|
||||
0b6118239615e98959f7e0b4e746bdd197533248
|
||||
|
||||
Change on Makefile for IPv6, warnings were already cleared during port.
|
||||
|
||||
|
||||
2012-05-20 - contrib: Fix pppgetpass.gtk compilation
|
||||
80a8e2ce257ca12cce723519a0f20ea1d663b14a
|
||||
|
||||
Change on Makefile, don't care.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Don't crash if crypt() returns NULL
|
||||
04c4348108d847e034dd91066cc6843f60d71731
|
||||
|
||||
We are using the PolarSSL DES implementation that does not return NULL.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Eliminate some warnings
|
||||
c44ae5e6a7338c96eb463881fe709b2dfaffe568
|
||||
|
||||
Again, we are handling compilation warnings on our own.
|
||||
|
||||
|
||||
2012-05-20 - rp-pppoe plugin: Import some fixes from rp-pppoe-3.10
|
||||
1817d83e51a411044e730ba89ebdb0480e1c8cd4
|
||||
|
||||
Once more, we are not using the RP-PPPoE plugin.
|
||||
|
||||
|
||||
2013-01-23 - pppd: Clarify circumstances where DNS1/DNS2 environment variables are set
|
||||
cf2f5c9538b9400ade23446a194729b0a4113b3a
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-02-03 - ppp: ignore unrecognised radiusclient configuration directives
|
||||
7f736dde0da3c19855997d9e67370e351e15e923
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2013-02-03 - pppd: Take out unused %r conversion completely
|
||||
356d8d558d844412119aa18c8e5a113bc6459c7b
|
||||
|
||||
Merged 2014-04-15.
|
||||
|
||||
|
||||
2013-02-03 - pppd: Arrange to use logwtmp from libutil on Linux
|
||||
9617a7eb137f4fee62799a677a9ecf8d834db3f5
|
||||
|
||||
Patch for sys-linux.c, which we don't use.
|
||||
|
||||
|
||||
2013-02-03 - pppdump: Eliminate some compiler warnings
|
||||
3e3acf1ba2b3046c072a42c19164788a9e419bd1
|
||||
|
||||
pppdump is a ppp tool outside pppd source tree.
|
||||
|
||||
|
||||
2013-02-03 - chat: Correct spelling errors in the man page
|
||||
8dea1b969d266ccbf6f3a8c5474eb6dcd8838e3b
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-02-03 - pppd: Fix spelling errors in man page
|
||||
9e05a25d76b3f83096c661678010320df673df6b
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-02-03 - plugins/passprompt: Fix potential out-of-bounds array reference
|
||||
8edb889b753056a691a3e4b217a110a35f9fdedb
|
||||
|
||||
Plugin patch, we do not have plugins.
|
||||
|
||||
|
||||
2013-02-03 - chat: Fix *roff errors in the man page
|
||||
a7c3489eeaf44e83ce592143c7c8a5b5c29f4c48
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-03-02 - pppd: Fix man page description of case when remote IP address isn't known
|
||||
224841f4799f4f1e2e71bc490c54448d66740f4f
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-03-02 - pppd: Add master_detach option
|
||||
398ed2585640d198c53e736ee5bbd67f7ce8168e
|
||||
|
||||
Option for multilink support, we do not support multilink and this option
|
||||
is about detaching from the terminal, which is out of the embedded scope.
|
||||
|
||||
|
||||
2013-03-11 - pppd: Default exit status to EXIT_CONNECT_FAILED during connection phase
|
||||
225361d64ae737afdc8cb57579a2f33525461bc9
|
||||
|
||||
Commented out in our port, and already fixed by a previously applied Debian patch.
|
||||
|
||||
|
||||
2013-03-11 - pppstats: Fix undefined macro in man page
|
||||
d16a3985eade5280b8e171f5dd0670a91cba0d39
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-05-11 - plugins/radius: Handle bindaddr keyword in radiusclient.conf
|
||||
d883b2dbafeed3ebd9d7a56ab1469373bd001a3b
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2013-06-09 - pppoatm: Remove explicit loading of pppoatm kernel module
|
||||
52cd43a84bea524033b918b603698104f221bbb7
|
||||
|
||||
PPPoATM plugin, not in the port.
|
||||
|
||||
|
||||
2013-06-09 - pppd: Fix segfault in update_db_entry()
|
||||
37476164f15a45015310b9d4b197c2d7db1f7f8f
|
||||
|
||||
We do not use the samba db.
|
||||
|
||||
|
||||
2013-06-09 - chat: Fix some text that was intended to be literal
|
||||
cd9683676618adcee8add2c3cfa3382341b5a1f6
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-06-09 - README.pppoe: Minor semantic fix
|
||||
b5b8898af6fd3d44e873cfc66810ace5f1f47e17
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-06-10 - radius: Handle additional attributes
|
||||
2f581cd986a56f2ec4a95abad4f8297a1b10d7e2
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2013-06-10 - chat, pppd: Use \e instead of \\ in man pages
|
||||
8d6942415d22f6ca4377340ca26e345c3f5fa5db
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2014-01-02 - pppd: Don't crash if NULL pointer passed to vslprintf for %q or %v
|
||||
906814431bddeb2061825fa1ebad1a967b6d87a9
|
||||
|
||||
Merged 2014-04-15.
|
||||
|
||||
|
||||
2014-01-02 - pppd: Accept IPCP ConfAck packets containing MS-WINS options
|
||||
a243f217f1c6ac1aa7793806bc88590d077f490a
|
||||
|
||||
Merged 2014-04-15.
|
||||
|
||||
|
||||
2014-01-02 - config: Update Solaris compiler options and enable CHAPMS and IPV6
|
||||
99c46caaed01b7edba87962aa52b77fad61bfd7b
|
||||
|
||||
Solaris port, don't care.
|
||||
|
||||
|
||||
2014-01-02 - Update README and patchlevel for 2.4.6 release
|
||||
4043750fca36e7e0eb90d702e048ad1da4929418
|
||||
|
||||
Just release stuff.
|
||||
|
||||
|
||||
2014-02-18 - pppd: Add option "stop-bits" to set number of serial port stop bits.
|
||||
ad993a20ee485f0d0e2ac4105221641b200da6e2
|
||||
|
||||
Low level serial port, not in the port.
|
||||
|
||||
|
||||
2014-03-09 - pppd: Separate IPv6 handling for sifup/sifdown
|
||||
b04d2dc6df5c6b5650fea44250d58757ee3dac4a
|
||||
|
||||
Reimplemented.
|
||||
|
||||
|
||||
2014-03-09 - pppol2tp: Connect up/down events to notifiers and add IPv6 ones
|
||||
fafbe50251efc7d6b4a8be652d085316e112b34f
|
||||
|
||||
Not in the port.
|
||||
|
||||
|
||||
2014-03-09 - pppd: Add declarations to eliminate compile warnings
|
||||
50967962addebe15c7a7e63116ff46a0441dc464
|
||||
|
||||
We are handling compilation warnings on our own
|
||||
|
||||
|
||||
2014-03-09 - pppd: Eliminate some unnecessary ifdefs
|
||||
de8da14d845ee6db9236ccfddabf1d8ebf045ddb
|
||||
|
||||
We mostly did that previously. Anyway, merged 2014-12-24.
|
||||
|
||||
|
||||
2014-08-01 - radius: Fix realms-config-file option
|
||||
880a81be7c8e0fe8567227bc17a1bff3ea035943
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2014-08-01 - pppd: Eliminate potential integer overflow in option parsing
|
||||
7658e8257183f062dc01f87969c140707c7e52cb
|
||||
|
||||
pppd config file parser, not in the port.
|
||||
|
||||
|
||||
2014-08-01 - pppd: Eliminate memory leak with multiple instances of a string option
|
||||
b94b7fbbaa0589aa6ec5fdc733aeb9ff294d2656
|
||||
|
||||
pppd config file parser, not in the port.
|
||||
|
||||
|
||||
2014-08-01 - pppd: Fix a stack variable overflow in MSCHAP-v2
|
||||
36733a891fb56594fcee580f667b33a64b990981
|
||||
|
||||
This fixes a bug introduced in 08ef47ca ("pppd: Make MSCHAP-v2 cope better with packet loss").
|
||||
|
||||
We didn't merge 08ef47ca ;-)
|
||||
|
||||
|
||||
2014-08-01 - winbind plugin: Add -DMPPE=1 to eliminate compiler warnings
|
||||
2b05e22c62095e97dd0a97e4b5588402c2185071
|
||||
|
||||
Linux plugin, not in the port.
|
||||
|
||||
|
||||
2014-08-09 - Update README and patchlevel for 2.4.7 release
|
||||
6e8eaa7a78b31cdab2edf140a9c8afdb02ffaca5
|
||||
|
||||
Just release stuff.
|
||||
|
||||
|
||||
2014-08-10 - abort on errors in subdir builds
|
||||
5e90783d11a59268e05f4cfb29ce2343b13e8ab2
|
||||
|
||||
Linux Makefile, not in the port.
|
||||
|
||||
|
||||
2014-06-03 - pppd: add support for defaultroute-metric option
|
||||
35e5a569c988b1ff865b02a24d9a727a00db4da9
|
||||
|
||||
Only necessary for Linux, lwIP does not support route metrics.
|
||||
|
||||
|
||||
2014-12-13 - scripts: Avoid killing wrong pppd
|
||||
67811a647d399db5d188a242827760615a0f86b5
|
||||
|
||||
pppd helper script, not in the port.
|
||||
|
||||
|
||||
2014-12-20 - pppd: Fix sign-extension when displaying bytes in octal
|
||||
5e8c3cb256a7e86e3572a82a75d51c6850efdbdc
|
||||
|
||||
Merged 2016-07-02.
|
||||
|
||||
|
||||
2015-03-01 - Suppress false error message on PPPoE disconnect
|
||||
219aac3b53d0827549377f1bfe22853ee52d4405
|
||||
|
||||
PPPoE plugin, not in the port.
|
||||
|
||||
|
||||
2015-03-01 - Send PADT on PPPoE disconnect
|
||||
cd2c14f998c57bbe6a01dc5854f2763c0d7f31fb
|
||||
|
||||
PPPoE plugin, not in the port. And our PPPoE implementation already does
|
||||
that: pppoe_disconnect() calls pppoe_send_padt().
|
||||
|
||||
|
||||
2015-08-14 - pppd: ipxcp: Prevent buffer overrun on remote router name
|
||||
fe149de624f96629a7f46732055d8f718c74b856
|
||||
|
||||
We never ported IPX support. lwIP does not support IPX.
|
||||
|
||||
|
||||
2015-03-25 - pppd: Fix ccp_options.mppe type
|
||||
234edab99a6bb250cc9ecd384cca27b0c8b475ce
|
||||
|
||||
We found that while working on MPPE support in lwIP, that's our patch ;-)
|
||||
|
||||
|
||||
2015-03-24 - pppd: Fix ccp_cilen calculated size if both deflate_correct and deflate_draft are enabled
|
||||
094cb8ae4c61db225e67fedadb4964f846dd0c27
|
||||
|
||||
We found that while working on MPPE support in lwIP, that's our patch ;-)
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'master' of https://github.com/ncopa/ppp
|
||||
3a5c9a8fbc8970375cd881151d44e4b6fe249c6a
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'master' of git://github.com/vapier/ppp
|
||||
912e4fc6665aca188dced7ea7fdc663ce5a2dd24
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'bug_fix' of git://github.com/radaiming/ppp
|
||||
dfd33d7f526ecd7b39dd1bba8101260d02af5ebb
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'master' of git://github.com/pprindeville/ppp
|
||||
aa4a985f6114d08cf4e47634fb6325da71016473
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'no-error-on-already-closed' of git://github.com/farnz/ppp
|
||||
6edf252483b30dbcdcc5059f01831455365d5b6e
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'send-padt-on-disconnect' of git://github.com/farnz/ppp
|
||||
84684243d651f55f6df69d2a6707b52fbbe62bb9
|
||||
|
||||
Merge commit, we don't care.
|
||||
The lwIP PPP support is based from pppd 2.4.5 (http://ppp.samba.org) with
|
||||
huge changes to match code size and memory requirements for embedded devices.
|
||||
|
||||
Anyway, pppd has a mature codebase for years and the average commit count
|
||||
is getting low on their Git repository, meaning that we can follow what
|
||||
is happening on their side and merge what is relevant for lwIP.
|
||||
|
||||
So, here is the pppd follow up, so that we don't get away too far from pppd.
|
||||
|
||||
|
||||
== Patch fetched from from pppd Debian packages ==
|
||||
|
||||
This has nothing to do with pppd, but we merged some good patch from
|
||||
Debian and this is a good place to be.
|
||||
|
||||
- LCP adaptive echo, so that we don't send LCP echo request if we
|
||||
are receiving data from peer, can be enabled by setting PPP_LCP_ADAPTIVE
|
||||
to true.
|
||||
|
||||
- IPCP no/replace default route option, were added in the early stage of
|
||||
the ppp port, but it wasn't really helpful and was disabled when adding
|
||||
the new API ppp_set_default() call, which gives the lwIP user control over
|
||||
which one is the default interface, it was actually a requirement if you
|
||||
are doing PPP over PPP (i.e. PPPoL2TP, VPN link, over PPPoE, ADSL link).
|
||||
|
||||
- using rp-pppoe pppd exits with EXIT_OK after receiving a timeout waiting
|
||||
for PADO due to no modem attached, bug reported to pppd bug tracker, fixed
|
||||
in Debian but not in the latest (at the time when the port were started)
|
||||
pppd release.
|
||||
|
||||
|
||||
== Commits on pppd ==
|
||||
|
||||
2010-03-06 - Document +ipv6 and ipv6cp-accept-local
|
||||
e7537958aee79b3f653c601e903cb31d78fb7dcc
|
||||
|
||||
Don't care.
|
||||
|
||||
|
||||
2010-03-06 - Install pppol2tp plugins with sane permissions
|
||||
406215672cfadc03017341fe03802d1c7294b903
|
||||
|
||||
Don't care.
|
||||
|
||||
|
||||
2010-03-07 - pppd: Terminate correctly if lcp_lowerup delayed calling
|
||||
fsm_lowerup
|
||||
3eb9e810cfa515543655659b72dde30c54fea0a5
|
||||
|
||||
Merged 2012-05-17.
|
||||
|
||||
|
||||
2010-03-07 - rp_pppoe: Copy acName and pppd_pppoe_service after option parsing
|
||||
cab58617fd9d328029fffabc788020264b4fa91f
|
||||
|
||||
Don't care, is a patch for pppd/plugins/rp-pppoe/plugin.c which is not part
|
||||
of the port.
|
||||
|
||||
|
||||
2010-08-23 - set and reset options to control environment variables
|
||||
for scripts.
|
||||
2b6310fd24dba8e0fca8999916a162f0a1842a84
|
||||
|
||||
We can't fork processes in embedded, therefore all the pppd process run
|
||||
feature is disabled in the port, so we don't care about the new
|
||||
"environment variables" pppd feature.
|
||||
|
||||
|
||||
2010-08-23 - Nit: use _exit when exec fails and restrict values to 0-255
|
||||
per POSIX.
|
||||
2b4ea140432eeba5a007c0d4e6236bd0e0c12ba4
|
||||
|
||||
Again, we are not running as a heavy process, so all exit() or _exit() calls
|
||||
were removed.
|
||||
|
||||
|
||||
2010-08-23 - Fix quote handling in configuration files to be more like shell
|
||||
quoting.
|
||||
3089132cdf5b58dbdfc2daf08ec5c08eb47f8aca
|
||||
|
||||
We are not parsing config file, all the filesystem I/O stuff were disabled
|
||||
in our port.
|
||||
|
||||
|
||||
2010-08-24 - rp-pppoe: allow MTU to be increased up to 1500
|
||||
fd1dcdf758418f040da3ed801ab001b5e46854e7
|
||||
|
||||
Only concern changes on RP-PPPoE plugin, which we don't use.
|
||||
|
||||
|
||||
2010-09-11 - chat: Allow TIMEOUT value to come from environment variable
|
||||
ae80bf833e48a6202f44a935a68083ae52ad3824
|
||||
|
||||
See 2b6310fd24dba8e0fca8999916a162f0a1842a84.
|
||||
|
||||
|
||||
2011-03-05 - pppdump: Fix printfs with insufficient arguments
|
||||
7b8db569642c83ba3283745034f2e2c95e459423
|
||||
|
||||
pppdump is a ppp tool outside pppd source tree.
|
||||
|
||||
|
||||
2012-05-06 - pppd: Don't unconditionally disable VJ compression under Linux
|
||||
d8a66adf98a0e525cf38031b42098d539da6eeb6
|
||||
|
||||
Patch for sys-linux.c, which we don't use.
|
||||
|
||||
|
||||
2012-05-20 - Remove old version of Linux if_pppol2tp.h
|
||||
c41092dd4c49267f232f6cba3d31c6c68bfdf68d
|
||||
|
||||
Not in the port.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Make MSCHAP-v2 cope better with packet loss
|
||||
08ef47ca532294eb428238c831616748940e24a2
|
||||
|
||||
This is an interesting patch. However it consumes much more memory for
|
||||
MSCHAP and I am not sure if the benefit worth it. The PPP client can
|
||||
always start the authentication again if it failed for whatever reason.
|
||||
|
||||
|
||||
2012-05-20 - scripts: Make poff ignore extra arguments to pppd
|
||||
18f515f32c9f5723a9c2c912601e04335106534b
|
||||
|
||||
Again, we are not running scripts.
|
||||
|
||||
|
||||
2012-05-20 - rp-pppoe plugin: Print leading zeros in MAC address
|
||||
f5dda0cfc220c4b52e26144096d729e27b30f0f7
|
||||
|
||||
Again, we are not using the RP-PPPoE plugin.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Notify IPv6 up/down as we do for IPv4
|
||||
845cda8fa18939cf56e60b073f63a7efa65336fc
|
||||
|
||||
This is just a patch that adds plugins hooks for IPv6, the plugin interface
|
||||
was disabled because we don't have .so plugins in embedded.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Enable IPV6 by default and fix some warnings
|
||||
0b6118239615e98959f7e0b4e746bdd197533248
|
||||
|
||||
Change on Makefile for IPv6, warnings were already cleared during port.
|
||||
|
||||
|
||||
2012-05-20 - contrib: Fix pppgetpass.gtk compilation
|
||||
80a8e2ce257ca12cce723519a0f20ea1d663b14a
|
||||
|
||||
Change on Makefile, don't care.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Don't crash if crypt() returns NULL
|
||||
04c4348108d847e034dd91066cc6843f60d71731
|
||||
|
||||
We are using the PolarSSL DES implementation that does not return NULL.
|
||||
|
||||
|
||||
2012-05-20 - pppd: Eliminate some warnings
|
||||
c44ae5e6a7338c96eb463881fe709b2dfaffe568
|
||||
|
||||
Again, we are handling compilation warnings on our own.
|
||||
|
||||
|
||||
2012-05-20 - rp-pppoe plugin: Import some fixes from rp-pppoe-3.10
|
||||
1817d83e51a411044e730ba89ebdb0480e1c8cd4
|
||||
|
||||
Once more, we are not using the RP-PPPoE plugin.
|
||||
|
||||
|
||||
2013-01-23 - pppd: Clarify circumstances where DNS1/DNS2 environment variables are set
|
||||
cf2f5c9538b9400ade23446a194729b0a4113b3a
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-02-03 - ppp: ignore unrecognised radiusclient configuration directives
|
||||
7f736dde0da3c19855997d9e67370e351e15e923
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2013-02-03 - pppd: Take out unused %r conversion completely
|
||||
356d8d558d844412119aa18c8e5a113bc6459c7b
|
||||
|
||||
Merged 2014-04-15.
|
||||
|
||||
|
||||
2013-02-03 - pppd: Arrange to use logwtmp from libutil on Linux
|
||||
9617a7eb137f4fee62799a677a9ecf8d834db3f5
|
||||
|
||||
Patch for sys-linux.c, which we don't use.
|
||||
|
||||
|
||||
2013-02-03 - pppdump: Eliminate some compiler warnings
|
||||
3e3acf1ba2b3046c072a42c19164788a9e419bd1
|
||||
|
||||
pppdump is a ppp tool outside pppd source tree.
|
||||
|
||||
|
||||
2013-02-03 - chat: Correct spelling errors in the man page
|
||||
8dea1b969d266ccbf6f3a8c5474eb6dcd8838e3b
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-02-03 - pppd: Fix spelling errors in man page
|
||||
9e05a25d76b3f83096c661678010320df673df6b
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-02-03 - plugins/passprompt: Fix potential out-of-bounds array reference
|
||||
8edb889b753056a691a3e4b217a110a35f9fdedb
|
||||
|
||||
Plugin patch, we do not have plugins.
|
||||
|
||||
|
||||
2013-02-03 - chat: Fix *roff errors in the man page
|
||||
a7c3489eeaf44e83ce592143c7c8a5b5c29f4c48
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-03-02 - pppd: Fix man page description of case when remote IP address isn't known
|
||||
224841f4799f4f1e2e71bc490c54448d66740f4f
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-03-02 - pppd: Add master_detach option
|
||||
398ed2585640d198c53e736ee5bbd67f7ce8168e
|
||||
|
||||
Option for multilink support, we do not support multilink and this option
|
||||
is about detaching from the terminal, which is out of the embedded scope.
|
||||
|
||||
|
||||
2013-03-11 - pppd: Default exit status to EXIT_CONNECT_FAILED during connection phase
|
||||
225361d64ae737afdc8cb57579a2f33525461bc9
|
||||
|
||||
Commented out in our port, and already fixed by a previously applied Debian patch.
|
||||
|
||||
|
||||
2013-03-11 - pppstats: Fix undefined macro in man page
|
||||
d16a3985eade5280b8e171f5dd0670a91cba0d39
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-05-11 - plugins/radius: Handle bindaddr keyword in radiusclient.conf
|
||||
d883b2dbafeed3ebd9d7a56ab1469373bd001a3b
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2013-06-09 - pppoatm: Remove explicit loading of pppoatm kernel module
|
||||
52cd43a84bea524033b918b603698104f221bbb7
|
||||
|
||||
PPPoATM plugin, not in the port.
|
||||
|
||||
|
||||
2013-06-09 - pppd: Fix segfault in update_db_entry()
|
||||
37476164f15a45015310b9d4b197c2d7db1f7f8f
|
||||
|
||||
We do not use the samba db.
|
||||
|
||||
|
||||
2013-06-09 - chat: Fix some text that was intended to be literal
|
||||
cd9683676618adcee8add2c3cfa3382341b5a1f6
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-06-09 - README.pppoe: Minor semantic fix
|
||||
b5b8898af6fd3d44e873cfc66810ace5f1f47e17
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2013-06-10 - radius: Handle additional attributes
|
||||
2f581cd986a56f2ec4a95abad4f8297a1b10d7e2
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2013-06-10 - chat, pppd: Use \e instead of \\ in man pages
|
||||
8d6942415d22f6ca4377340ca26e345c3f5fa5db
|
||||
|
||||
Documentation only.
|
||||
|
||||
|
||||
2014-01-02 - pppd: Don't crash if NULL pointer passed to vslprintf for %q or %v
|
||||
906814431bddeb2061825fa1ebad1a967b6d87a9
|
||||
|
||||
Merged 2014-04-15.
|
||||
|
||||
|
||||
2014-01-02 - pppd: Accept IPCP ConfAck packets containing MS-WINS options
|
||||
a243f217f1c6ac1aa7793806bc88590d077f490a
|
||||
|
||||
Merged 2014-04-15.
|
||||
|
||||
|
||||
2014-01-02 - config: Update Solaris compiler options and enable CHAPMS and IPV6
|
||||
99c46caaed01b7edba87962aa52b77fad61bfd7b
|
||||
|
||||
Solaris port, don't care.
|
||||
|
||||
|
||||
2014-01-02 - Update README and patchlevel for 2.4.6 release
|
||||
4043750fca36e7e0eb90d702e048ad1da4929418
|
||||
|
||||
Just release stuff.
|
||||
|
||||
|
||||
2014-02-18 - pppd: Add option "stop-bits" to set number of serial port stop bits.
|
||||
ad993a20ee485f0d0e2ac4105221641b200da6e2
|
||||
|
||||
Low level serial port, not in the port.
|
||||
|
||||
|
||||
2014-03-09 - pppd: Separate IPv6 handling for sifup/sifdown
|
||||
b04d2dc6df5c6b5650fea44250d58757ee3dac4a
|
||||
|
||||
Reimplemented.
|
||||
|
||||
|
||||
2014-03-09 - pppol2tp: Connect up/down events to notifiers and add IPv6 ones
|
||||
fafbe50251efc7d6b4a8be652d085316e112b34f
|
||||
|
||||
Not in the port.
|
||||
|
||||
|
||||
2014-03-09 - pppd: Add declarations to eliminate compile warnings
|
||||
50967962addebe15c7a7e63116ff46a0441dc464
|
||||
|
||||
We are handling compilation warnings on our own
|
||||
|
||||
|
||||
2014-03-09 - pppd: Eliminate some unnecessary ifdefs
|
||||
de8da14d845ee6db9236ccfddabf1d8ebf045ddb
|
||||
|
||||
We mostly did that previously. Anyway, merged 2014-12-24.
|
||||
|
||||
|
||||
2014-08-01 - radius: Fix realms-config-file option
|
||||
880a81be7c8e0fe8567227bc17a1bff3ea035943
|
||||
|
||||
Radius plugin, not in the port.
|
||||
|
||||
|
||||
2014-08-01 - pppd: Eliminate potential integer overflow in option parsing
|
||||
7658e8257183f062dc01f87969c140707c7e52cb
|
||||
|
||||
pppd config file parser, not in the port.
|
||||
|
||||
|
||||
2014-08-01 - pppd: Eliminate memory leak with multiple instances of a string option
|
||||
b94b7fbbaa0589aa6ec5fdc733aeb9ff294d2656
|
||||
|
||||
pppd config file parser, not in the port.
|
||||
|
||||
|
||||
2014-08-01 - pppd: Fix a stack variable overflow in MSCHAP-v2
|
||||
36733a891fb56594fcee580f667b33a64b990981
|
||||
|
||||
This fixes a bug introduced in 08ef47ca ("pppd: Make MSCHAP-v2 cope better with packet loss").
|
||||
|
||||
We didn't merge 08ef47ca ;-)
|
||||
|
||||
|
||||
2014-08-01 - winbind plugin: Add -DMPPE=1 to eliminate compiler warnings
|
||||
2b05e22c62095e97dd0a97e4b5588402c2185071
|
||||
|
||||
Linux plugin, not in the port.
|
||||
|
||||
|
||||
2014-08-09 - Update README and patchlevel for 2.4.7 release
|
||||
6e8eaa7a78b31cdab2edf140a9c8afdb02ffaca5
|
||||
|
||||
Just release stuff.
|
||||
|
||||
|
||||
2014-08-10 - abort on errors in subdir builds
|
||||
5e90783d11a59268e05f4cfb29ce2343b13e8ab2
|
||||
|
||||
Linux Makefile, not in the port.
|
||||
|
||||
|
||||
2014-06-03 - pppd: add support for defaultroute-metric option
|
||||
35e5a569c988b1ff865b02a24d9a727a00db4da9
|
||||
|
||||
Only necessary for Linux, lwIP does not support route metrics.
|
||||
|
||||
|
||||
2014-12-13 - scripts: Avoid killing wrong pppd
|
||||
67811a647d399db5d188a242827760615a0f86b5
|
||||
|
||||
pppd helper script, not in the port.
|
||||
|
||||
|
||||
2014-12-20 - pppd: Fix sign-extension when displaying bytes in octal
|
||||
5e8c3cb256a7e86e3572a82a75d51c6850efdbdc
|
||||
|
||||
Merged 2016-07-02.
|
||||
|
||||
|
||||
2015-03-01 - Suppress false error message on PPPoE disconnect
|
||||
219aac3b53d0827549377f1bfe22853ee52d4405
|
||||
|
||||
PPPoE plugin, not in the port.
|
||||
|
||||
|
||||
2015-03-01 - Send PADT on PPPoE disconnect
|
||||
cd2c14f998c57bbe6a01dc5854f2763c0d7f31fb
|
||||
|
||||
PPPoE plugin, not in the port. And our PPPoE implementation already does
|
||||
that: pppoe_disconnect() calls pppoe_send_padt().
|
||||
|
||||
|
||||
2015-08-14 - pppd: ipxcp: Prevent buffer overrun on remote router name
|
||||
fe149de624f96629a7f46732055d8f718c74b856
|
||||
|
||||
We never ported IPX support. lwIP does not support IPX.
|
||||
|
||||
|
||||
2015-03-25 - pppd: Fix ccp_options.mppe type
|
||||
234edab99a6bb250cc9ecd384cca27b0c8b475ce
|
||||
|
||||
We found that while working on MPPE support in lwIP, that's our patch ;-)
|
||||
|
||||
|
||||
2015-03-24 - pppd: Fix ccp_cilen calculated size if both deflate_correct and deflate_draft are enabled
|
||||
094cb8ae4c61db225e67fedadb4964f846dd0c27
|
||||
|
||||
We found that while working on MPPE support in lwIP, that's our patch ;-)
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'master' of https://github.com/ncopa/ppp
|
||||
3a5c9a8fbc8970375cd881151d44e4b6fe249c6a
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'master' of git://github.com/vapier/ppp
|
||||
912e4fc6665aca188dced7ea7fdc663ce5a2dd24
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'bug_fix' of git://github.com/radaiming/ppp
|
||||
dfd33d7f526ecd7b39dd1bba8101260d02af5ebb
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'master' of git://github.com/pprindeville/ppp
|
||||
aa4a985f6114d08cf4e47634fb6325da71016473
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'no-error-on-already-closed' of git://github.com/farnz/ppp
|
||||
6edf252483b30dbcdcc5059f01831455365d5b6e
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
|
||||
2015-08-14 - Merge branch 'send-padt-on-disconnect' of git://github.com/farnz/ppp
|
||||
84684243d651f55f6df69d2a6707b52fbbe62bb9
|
||||
|
||||
Merge commit, we don't care.
|
||||
|
||||
5013
ext/lwip/src/netif/ppp/auth.c
Normal file → Executable file
5013
ext/lwip/src/netif/ppp/auth.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
3480
ext/lwip/src/netif/ppp/ccp.c
Normal file → Executable file
3480
ext/lwip/src/netif/ppp/ccp.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
252
ext/lwip/src/netif/ppp/chap-md5.c
Normal file → Executable file
252
ext/lwip/src/netif/ppp/chap-md5.c
Normal file → Executable file
@@ -1,126 +1,126 @@
|
||||
/*
|
||||
* chap-md5.c - New CHAP/MD5 implementation.
|
||||
*
|
||||
* Copyright (c) 2003 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 3. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Paul Mackerras
|
||||
* <paulus@samba.org>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "netif/ppp/chap-md5.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
#define MD5_HASH_SIZE 16
|
||||
#define MD5_MIN_CHALLENGE 17
|
||||
#define MD5_MAX_CHALLENGE 24
|
||||
#define MD5_MIN_MAX_POWER_OF_TWO_CHALLENGE 3 /* 2^3-1 = 7, 17+7 = 24 */
|
||||
|
||||
#if PPP_SERVER
|
||||
static void chap_md5_generate_challenge(ppp_pcb *pcb, unsigned char *cp) {
|
||||
int clen;
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
clen = MD5_MIN_CHALLENGE + magic_pow(MD5_MIN_MAX_POWER_OF_TWO_CHALLENGE);
|
||||
*cp++ = clen;
|
||||
magic_random_bytes(cp, clen);
|
||||
}
|
||||
|
||||
static int chap_md5_verify_response(ppp_pcb *pcb, int id, const char *name,
|
||||
const unsigned char *secret, int secret_len,
|
||||
const unsigned char *challenge, const unsigned char *response,
|
||||
char *message, int message_space) {
|
||||
lwip_md5_context ctx;
|
||||
unsigned char idbyte = id;
|
||||
unsigned char hash[MD5_HASH_SIZE];
|
||||
int challenge_len, response_len;
|
||||
LWIP_UNUSED_ARG(name);
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
challenge_len = *challenge++;
|
||||
response_len = *response++;
|
||||
if (response_len == MD5_HASH_SIZE) {
|
||||
/* Generate hash of ID, secret, challenge */
|
||||
lwip_md5_init(&ctx);
|
||||
lwip_md5_starts(&ctx);
|
||||
lwip_md5_update(&ctx, &idbyte, 1);
|
||||
lwip_md5_update(&ctx, secret, secret_len);
|
||||
lwip_md5_update(&ctx, challenge, challenge_len);
|
||||
lwip_md5_finish(&ctx, hash);
|
||||
lwip_md5_free(&ctx);
|
||||
|
||||
/* Test if our hash matches the peer's response */
|
||||
if (memcmp(hash, response, MD5_HASH_SIZE) == 0) {
|
||||
ppp_slprintf(message, message_space, "Access granted");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ppp_slprintf(message, message_space, "Access denied");
|
||||
return 0;
|
||||
}
|
||||
#endif /* PPP_SERVER */
|
||||
|
||||
static void chap_md5_make_response(ppp_pcb *pcb, unsigned char *response, int id, const char *our_name,
|
||||
const unsigned char *challenge, const char *secret, int secret_len,
|
||||
unsigned char *private_) {
|
||||
lwip_md5_context ctx;
|
||||
unsigned char idbyte = id;
|
||||
int challenge_len = *challenge++;
|
||||
LWIP_UNUSED_ARG(our_name);
|
||||
LWIP_UNUSED_ARG(private_);
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
lwip_md5_init(&ctx);
|
||||
lwip_md5_starts(&ctx);
|
||||
lwip_md5_update(&ctx, &idbyte, 1);
|
||||
lwip_md5_update(&ctx, (const u_char *)secret, secret_len);
|
||||
lwip_md5_update(&ctx, challenge, challenge_len);
|
||||
lwip_md5_finish(&ctx, &response[1]);
|
||||
lwip_md5_free(&ctx);
|
||||
response[0] = MD5_HASH_SIZE;
|
||||
}
|
||||
|
||||
const struct chap_digest_type md5_digest = {
|
||||
CHAP_MD5, /* code */
|
||||
#if PPP_SERVER
|
||||
chap_md5_generate_challenge,
|
||||
chap_md5_verify_response,
|
||||
#endif /* PPP_SERVER */
|
||||
chap_md5_make_response,
|
||||
NULL, /* check_success */
|
||||
NULL, /* handle_failure */
|
||||
};
|
||||
|
||||
#endif /* PPP_SUPPORT && CHAP_SUPPORT */
|
||||
/*
|
||||
* chap-md5.c - New CHAP/MD5 implementation.
|
||||
*
|
||||
* Copyright (c) 2003 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 3. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Paul Mackerras
|
||||
* <paulus@samba.org>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "netif/ppp/chap-md5.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
#define MD5_HASH_SIZE 16
|
||||
#define MD5_MIN_CHALLENGE 17
|
||||
#define MD5_MAX_CHALLENGE 24
|
||||
#define MD5_MIN_MAX_POWER_OF_TWO_CHALLENGE 3 /* 2^3-1 = 7, 17+7 = 24 */
|
||||
|
||||
#if PPP_SERVER
|
||||
static void chap_md5_generate_challenge(ppp_pcb *pcb, unsigned char *cp) {
|
||||
int clen;
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
clen = MD5_MIN_CHALLENGE + magic_pow(MD5_MIN_MAX_POWER_OF_TWO_CHALLENGE);
|
||||
*cp++ = clen;
|
||||
magic_random_bytes(cp, clen);
|
||||
}
|
||||
|
||||
static int chap_md5_verify_response(ppp_pcb *pcb, int id, const char *name,
|
||||
const unsigned char *secret, int secret_len,
|
||||
const unsigned char *challenge, const unsigned char *response,
|
||||
char *message, int message_space) {
|
||||
lwip_md5_context ctx;
|
||||
unsigned char idbyte = id;
|
||||
unsigned char hash[MD5_HASH_SIZE];
|
||||
int challenge_len, response_len;
|
||||
LWIP_UNUSED_ARG(name);
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
challenge_len = *challenge++;
|
||||
response_len = *response++;
|
||||
if (response_len == MD5_HASH_SIZE) {
|
||||
/* Generate hash of ID, secret, challenge */
|
||||
lwip_md5_init(&ctx);
|
||||
lwip_md5_starts(&ctx);
|
||||
lwip_md5_update(&ctx, &idbyte, 1);
|
||||
lwip_md5_update(&ctx, secret, secret_len);
|
||||
lwip_md5_update(&ctx, challenge, challenge_len);
|
||||
lwip_md5_finish(&ctx, hash);
|
||||
lwip_md5_free(&ctx);
|
||||
|
||||
/* Test if our hash matches the peer's response */
|
||||
if (memcmp(hash, response, MD5_HASH_SIZE) == 0) {
|
||||
ppp_slprintf(message, message_space, "Access granted");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ppp_slprintf(message, message_space, "Access denied");
|
||||
return 0;
|
||||
}
|
||||
#endif /* PPP_SERVER */
|
||||
|
||||
static void chap_md5_make_response(ppp_pcb *pcb, unsigned char *response, int id, const char *our_name,
|
||||
const unsigned char *challenge, const char *secret, int secret_len,
|
||||
unsigned char *private_) {
|
||||
lwip_md5_context ctx;
|
||||
unsigned char idbyte = id;
|
||||
int challenge_len = *challenge++;
|
||||
LWIP_UNUSED_ARG(our_name);
|
||||
LWIP_UNUSED_ARG(private_);
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
lwip_md5_init(&ctx);
|
||||
lwip_md5_starts(&ctx);
|
||||
lwip_md5_update(&ctx, &idbyte, 1);
|
||||
lwip_md5_update(&ctx, (const u_char *)secret, secret_len);
|
||||
lwip_md5_update(&ctx, challenge, challenge_len);
|
||||
lwip_md5_finish(&ctx, &response[1]);
|
||||
lwip_md5_free(&ctx);
|
||||
response[0] = MD5_HASH_SIZE;
|
||||
}
|
||||
|
||||
const struct chap_digest_type md5_digest = {
|
||||
CHAP_MD5, /* code */
|
||||
#if PPP_SERVER
|
||||
chap_md5_generate_challenge,
|
||||
chap_md5_verify_response,
|
||||
#endif /* PPP_SERVER */
|
||||
chap_md5_make_response,
|
||||
NULL, /* check_success */
|
||||
NULL, /* handle_failure */
|
||||
};
|
||||
|
||||
#endif /* PPP_SUPPORT && CHAP_SUPPORT */
|
||||
|
||||
1354
ext/lwip/src/netif/ppp/chap-new.c
Normal file → Executable file
1354
ext/lwip/src/netif/ppp/chap-new.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
1924
ext/lwip/src/netif/ppp/chap_ms.c
Normal file → Executable file
1924
ext/lwip/src/netif/ppp/chap_ms.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
930
ext/lwip/src/netif/ppp/demand.c
Normal file → Executable file
930
ext/lwip/src/netif/ppp/demand.c
Normal file → Executable file
@@ -1,465 +1,465 @@
|
||||
/*
|
||||
* demand.c - Support routines for demand-dialling.
|
||||
*
|
||||
* Copyright (c) 1996-2002 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 3. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Paul Mackerras
|
||||
* <paulus@samba.org>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && DEMAND_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#ifdef PPP_FILTER
|
||||
#include <pcap-bpf.h>
|
||||
#endif
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ipcp.h"
|
||||
#include "netif/ppp/lcp.h"
|
||||
|
||||
char *frame;
|
||||
int framelen;
|
||||
int framemax;
|
||||
int escape_flag;
|
||||
int flush_flag;
|
||||
int fcs;
|
||||
|
||||
struct packet {
|
||||
int length;
|
||||
struct packet *next;
|
||||
unsigned char data[1];
|
||||
};
|
||||
|
||||
struct packet *pend_q;
|
||||
struct packet *pend_qtail;
|
||||
|
||||
static int active_packet (unsigned char *, int);
|
||||
|
||||
/*
|
||||
* demand_conf - configure the interface for doing dial-on-demand.
|
||||
*/
|
||||
void
|
||||
demand_conf()
|
||||
{
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
/* framemax = lcp_allowoptions[0].mru;
|
||||
if (framemax < PPP_MRU) */
|
||||
framemax = PPP_MRU;
|
||||
framemax += PPP_HDRLEN + PPP_FCSLEN;
|
||||
frame = malloc(framemax);
|
||||
if (frame == NULL)
|
||||
novm("demand frame");
|
||||
framelen = 0;
|
||||
pend_q = NULL;
|
||||
escape_flag = 0;
|
||||
flush_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
|
||||
netif_set_mtu(pcb, LWIP_MIN(lcp_allowoptions[0].mru, PPP_MRU));
|
||||
if (ppp_send_config(pcb, PPP_MRU, (u32_t) 0, 0, 0) < 0
|
||||
|| ppp_recv_config(pcb, PPP_MRU, (u32_t) 0, 0, 0) < 0)
|
||||
fatal("Couldn't set up demand-dialled PPP interface: %m");
|
||||
|
||||
#ifdef PPP_FILTER
|
||||
set_filters(&pass_filter, &active_filter);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Call the demand_conf procedure for each protocol that's got one.
|
||||
*/
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
((*protp->demand_conf)(pcb));
|
||||
/* FIXME: find a way to die() here */
|
||||
#if 0
|
||||
if (!((*protp->demand_conf)(pcb)))
|
||||
die(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* demand_block - set each network protocol to block further packets.
|
||||
*/
|
||||
void
|
||||
demand_block()
|
||||
{
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
sifnpmode(pcb, protp->protocol & ~0x8000, NPMODE_QUEUE);
|
||||
get_loop_output();
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_discard - set each network protocol to discard packets
|
||||
* with an error.
|
||||
*/
|
||||
void
|
||||
demand_discard()
|
||||
{
|
||||
struct packet *pkt, *nextpkt;
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
sifnpmode(pcb, protp->protocol & ~0x8000, NPMODE_ERROR);
|
||||
get_loop_output();
|
||||
|
||||
/* discard all saved packets */
|
||||
for (pkt = pend_q; pkt != NULL; pkt = nextpkt) {
|
||||
nextpkt = pkt->next;
|
||||
free(pkt);
|
||||
}
|
||||
pend_q = NULL;
|
||||
framelen = 0;
|
||||
flush_flag = 0;
|
||||
escape_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_unblock - set each enabled network protocol to pass packets.
|
||||
*/
|
||||
void
|
||||
demand_unblock()
|
||||
{
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
sifnpmode(pcb, protp->protocol & ~0x8000, NPMODE_PASS);
|
||||
}
|
||||
|
||||
/*
|
||||
* FCS lookup table as calculated by genfcstab.
|
||||
*/
|
||||
static u_short fcstab[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
|
||||
/*
|
||||
* loop_chars - process characters received from the loopback.
|
||||
* Calls loop_frame when a complete frame has been accumulated.
|
||||
* Return value is 1 if we need to bring up the link, 0 otherwise.
|
||||
*/
|
||||
int
|
||||
loop_chars(p, n)
|
||||
unsigned char *p;
|
||||
int n;
|
||||
{
|
||||
int c, rv;
|
||||
|
||||
rv = 0;
|
||||
|
||||
/* check for synchronous connection... */
|
||||
|
||||
if ( (p[0] == 0xFF) && (p[1] == 0x03) ) {
|
||||
rv = loop_frame(p,n);
|
||||
return rv;
|
||||
}
|
||||
|
||||
for (; n > 0; --n) {
|
||||
c = *p++;
|
||||
if (c == PPP_FLAG) {
|
||||
if (!escape_flag && !flush_flag
|
||||
&& framelen > 2 && fcs == PPP_GOODFCS) {
|
||||
framelen -= 2;
|
||||
if (loop_frame((unsigned char *)frame, framelen))
|
||||
rv = 1;
|
||||
}
|
||||
framelen = 0;
|
||||
flush_flag = 0;
|
||||
escape_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
continue;
|
||||
}
|
||||
if (flush_flag)
|
||||
continue;
|
||||
if (escape_flag) {
|
||||
c ^= PPP_TRANS;
|
||||
escape_flag = 0;
|
||||
} else if (c == PPP_ESCAPE) {
|
||||
escape_flag = 1;
|
||||
continue;
|
||||
}
|
||||
if (framelen >= framemax) {
|
||||
flush_flag = 1;
|
||||
continue;
|
||||
}
|
||||
frame[framelen++] = c;
|
||||
fcs = PPP_FCS(fcs, c);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* loop_frame - given a frame obtained from the loopback,
|
||||
* decide whether to bring up the link or not, and, if we want
|
||||
* to transmit this frame later, put it on the pending queue.
|
||||
* Return value is 1 if we need to bring up the link, 0 otherwise.
|
||||
* We assume that the kernel driver has already applied the
|
||||
* pass_filter, so we won't get packets it rejected.
|
||||
* We apply the active_filter to see if we want this packet to
|
||||
* bring up the link.
|
||||
*/
|
||||
int
|
||||
loop_frame(frame, len)
|
||||
unsigned char *frame;
|
||||
int len;
|
||||
{
|
||||
struct packet *pkt;
|
||||
|
||||
/* dbglog("from loop: %P", frame, len); */
|
||||
if (len < PPP_HDRLEN)
|
||||
return 0;
|
||||
if ((PPP_PROTOCOL(frame) & 0x8000) != 0)
|
||||
return 0; /* shouldn't get any of these anyway */
|
||||
if (!active_packet(frame, len))
|
||||
return 0;
|
||||
|
||||
pkt = (struct packet *) malloc(sizeof(struct packet) + len);
|
||||
if (pkt != NULL) {
|
||||
pkt->length = len;
|
||||
pkt->next = NULL;
|
||||
memcpy(pkt->data, frame, len);
|
||||
if (pend_q == NULL)
|
||||
pend_q = pkt;
|
||||
else
|
||||
pend_qtail->next = pkt;
|
||||
pend_qtail = pkt;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_rexmit - Resend all those frames which we got via the
|
||||
* loopback, now that the real serial link is up.
|
||||
*/
|
||||
void
|
||||
demand_rexmit(proto, newip)
|
||||
int proto;
|
||||
u32_t newip;
|
||||
{
|
||||
struct packet *pkt, *prev, *nextpkt;
|
||||
unsigned short checksum;
|
||||
unsigned short pkt_checksum = 0;
|
||||
unsigned iphdr;
|
||||
struct timeval tv;
|
||||
char cv = 0;
|
||||
char ipstr[16];
|
||||
|
||||
prev = NULL;
|
||||
pkt = pend_q;
|
||||
pend_q = NULL;
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
select(0,NULL,NULL,NULL,&tv); /* Sleep for 1 Seconds */
|
||||
for (; pkt != NULL; pkt = nextpkt) {
|
||||
nextpkt = pkt->next;
|
||||
if (PPP_PROTOCOL(pkt->data) == proto) {
|
||||
if ( (proto == PPP_IP) && newip ) {
|
||||
/* Get old checksum */
|
||||
|
||||
iphdr = (pkt->data[4] & 15) << 2;
|
||||
checksum = *((unsigned short *) (pkt->data+14));
|
||||
if (checksum == 0xFFFF) {
|
||||
checksum = 0;
|
||||
}
|
||||
|
||||
|
||||
if (pkt->data[13] == 17) {
|
||||
pkt_checksum = *((unsigned short *) (pkt->data+10+iphdr));
|
||||
if (pkt_checksum) {
|
||||
cv = 1;
|
||||
if (pkt_checksum == 0xFFFF) {
|
||||
pkt_checksum = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pkt->data[13] == 6) {
|
||||
pkt_checksum = *((unsigned short *) (pkt->data+20+iphdr));
|
||||
cv = 1;
|
||||
if (pkt_checksum == 0xFFFF) {
|
||||
pkt_checksum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete old Source-IP-Address */
|
||||
checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
pkt_checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
pkt_checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
/* Change Source-IP-Address */
|
||||
* ((u32_t *) (pkt->data + 16)) = newip;
|
||||
|
||||
/* Add new Source-IP-Address */
|
||||
checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
pkt_checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
pkt_checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
/* Write new checksum */
|
||||
if (!checksum) {
|
||||
checksum = 0xFFFF;
|
||||
}
|
||||
*((unsigned short *) (pkt->data+14)) = checksum;
|
||||
if (pkt->data[13] == 6) {
|
||||
*((unsigned short *) (pkt->data+20+iphdr)) = pkt_checksum;
|
||||
}
|
||||
if (cv && (pkt->data[13] == 17) ) {
|
||||
*((unsigned short *) (pkt->data+10+iphdr)) = pkt_checksum;
|
||||
}
|
||||
|
||||
/* Log Packet */
|
||||
strcpy(ipstr,inet_ntoa(*( (struct in_addr *) (pkt->data+16))));
|
||||
if (pkt->data[13] == 1) {
|
||||
syslog(LOG_INFO,"Open ICMP %s -> %s\n",
|
||||
ipstr,
|
||||
inet_ntoa(*( (struct in_addr *) (pkt->data+20))));
|
||||
} else {
|
||||
syslog(LOG_INFO,"Open %s %s:%d -> %s:%d\n",
|
||||
pkt->data[13] == 6 ? "TCP" : "UDP",
|
||||
ipstr,
|
||||
ntohs(*( (short *) (pkt->data+iphdr+4))),
|
||||
inet_ntoa(*( (struct in_addr *) (pkt->data+20))),
|
||||
ntohs(*( (short *) (pkt->data+iphdr+6))));
|
||||
}
|
||||
}
|
||||
output(pcb, pkt->data, pkt->length);
|
||||
free(pkt);
|
||||
} else {
|
||||
if (prev == NULL)
|
||||
pend_q = pkt;
|
||||
else
|
||||
prev->next = pkt;
|
||||
prev = pkt;
|
||||
}
|
||||
}
|
||||
pend_qtail = prev;
|
||||
if (prev != NULL)
|
||||
prev->next = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan a packet to decide whether it is an "active" packet,
|
||||
* that is, whether it is worth bringing up the link for.
|
||||
*/
|
||||
static int
|
||||
active_packet(p, len)
|
||||
unsigned char *p;
|
||||
int len;
|
||||
{
|
||||
int proto, i;
|
||||
const struct protent *protp;
|
||||
|
||||
if (len < PPP_HDRLEN)
|
||||
return 0;
|
||||
proto = PPP_PROTOCOL(p);
|
||||
#ifdef PPP_FILTER
|
||||
p[0] = 1; /* outbound packet indicator */
|
||||
if ((pass_filter.bf_len != 0
|
||||
&& bpf_filter(pass_filter.bf_insns, p, len, len) == 0)
|
||||
|| (active_filter.bf_len != 0
|
||||
&& bpf_filter(active_filter.bf_insns, p, len, len) == 0)) {
|
||||
p[0] = 0xff;
|
||||
return 0;
|
||||
}
|
||||
p[0] = 0xff;
|
||||
#endif
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i) {
|
||||
if (protp->protocol < 0xC000 && (protp->protocol & ~0x8000) == proto) {
|
||||
if (protp->active_pkt == NULL)
|
||||
return 1;
|
||||
return (*protp->active_pkt)(p, len);
|
||||
}
|
||||
}
|
||||
return 0; /* not a supported protocol !!?? */
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && DEMAND_SUPPORT */
|
||||
/*
|
||||
* demand.c - Support routines for demand-dialling.
|
||||
*
|
||||
* Copyright (c) 1996-2002 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 3. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Paul Mackerras
|
||||
* <paulus@samba.org>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && DEMAND_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#ifdef PPP_FILTER
|
||||
#include <pcap-bpf.h>
|
||||
#endif
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ipcp.h"
|
||||
#include "netif/ppp/lcp.h"
|
||||
|
||||
char *frame;
|
||||
int framelen;
|
||||
int framemax;
|
||||
int escape_flag;
|
||||
int flush_flag;
|
||||
int fcs;
|
||||
|
||||
struct packet {
|
||||
int length;
|
||||
struct packet *next;
|
||||
unsigned char data[1];
|
||||
};
|
||||
|
||||
struct packet *pend_q;
|
||||
struct packet *pend_qtail;
|
||||
|
||||
static int active_packet (unsigned char *, int);
|
||||
|
||||
/*
|
||||
* demand_conf - configure the interface for doing dial-on-demand.
|
||||
*/
|
||||
void
|
||||
demand_conf()
|
||||
{
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
/* framemax = lcp_allowoptions[0].mru;
|
||||
if (framemax < PPP_MRU) */
|
||||
framemax = PPP_MRU;
|
||||
framemax += PPP_HDRLEN + PPP_FCSLEN;
|
||||
frame = malloc(framemax);
|
||||
if (frame == NULL)
|
||||
novm("demand frame");
|
||||
framelen = 0;
|
||||
pend_q = NULL;
|
||||
escape_flag = 0;
|
||||
flush_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
|
||||
netif_set_mtu(pcb, LWIP_MIN(lcp_allowoptions[0].mru, PPP_MRU));
|
||||
if (ppp_send_config(pcb, PPP_MRU, (u32_t) 0, 0, 0) < 0
|
||||
|| ppp_recv_config(pcb, PPP_MRU, (u32_t) 0, 0, 0) < 0)
|
||||
fatal("Couldn't set up demand-dialled PPP interface: %m");
|
||||
|
||||
#ifdef PPP_FILTER
|
||||
set_filters(&pass_filter, &active_filter);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Call the demand_conf procedure for each protocol that's got one.
|
||||
*/
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
((*protp->demand_conf)(pcb));
|
||||
/* FIXME: find a way to die() here */
|
||||
#if 0
|
||||
if (!((*protp->demand_conf)(pcb)))
|
||||
die(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* demand_block - set each network protocol to block further packets.
|
||||
*/
|
||||
void
|
||||
demand_block()
|
||||
{
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
sifnpmode(pcb, protp->protocol & ~0x8000, NPMODE_QUEUE);
|
||||
get_loop_output();
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_discard - set each network protocol to discard packets
|
||||
* with an error.
|
||||
*/
|
||||
void
|
||||
demand_discard()
|
||||
{
|
||||
struct packet *pkt, *nextpkt;
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
sifnpmode(pcb, protp->protocol & ~0x8000, NPMODE_ERROR);
|
||||
get_loop_output();
|
||||
|
||||
/* discard all saved packets */
|
||||
for (pkt = pend_q; pkt != NULL; pkt = nextpkt) {
|
||||
nextpkt = pkt->next;
|
||||
free(pkt);
|
||||
}
|
||||
pend_q = NULL;
|
||||
framelen = 0;
|
||||
flush_flag = 0;
|
||||
escape_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_unblock - set each enabled network protocol to pass packets.
|
||||
*/
|
||||
void
|
||||
demand_unblock()
|
||||
{
|
||||
int i;
|
||||
const struct protent *protp;
|
||||
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i)
|
||||
if (protp->demand_conf != NULL)
|
||||
sifnpmode(pcb, protp->protocol & ~0x8000, NPMODE_PASS);
|
||||
}
|
||||
|
||||
/*
|
||||
* FCS lookup table as calculated by genfcstab.
|
||||
*/
|
||||
static u_short fcstab[256] = {
|
||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
||||
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
||||
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
||||
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
||||
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
||||
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
||||
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
||||
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
||||
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
||||
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
||||
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
||||
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
||||
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
||||
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
||||
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
||||
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
||||
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
||||
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
||||
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
||||
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
||||
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
||||
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
||||
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
||||
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
||||
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
||||
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
||||
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
||||
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
||||
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
||||
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
||||
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
||||
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
||||
};
|
||||
|
||||
/*
|
||||
* loop_chars - process characters received from the loopback.
|
||||
* Calls loop_frame when a complete frame has been accumulated.
|
||||
* Return value is 1 if we need to bring up the link, 0 otherwise.
|
||||
*/
|
||||
int
|
||||
loop_chars(p, n)
|
||||
unsigned char *p;
|
||||
int n;
|
||||
{
|
||||
int c, rv;
|
||||
|
||||
rv = 0;
|
||||
|
||||
/* check for synchronous connection... */
|
||||
|
||||
if ( (p[0] == 0xFF) && (p[1] == 0x03) ) {
|
||||
rv = loop_frame(p,n);
|
||||
return rv;
|
||||
}
|
||||
|
||||
for (; n > 0; --n) {
|
||||
c = *p++;
|
||||
if (c == PPP_FLAG) {
|
||||
if (!escape_flag && !flush_flag
|
||||
&& framelen > 2 && fcs == PPP_GOODFCS) {
|
||||
framelen -= 2;
|
||||
if (loop_frame((unsigned char *)frame, framelen))
|
||||
rv = 1;
|
||||
}
|
||||
framelen = 0;
|
||||
flush_flag = 0;
|
||||
escape_flag = 0;
|
||||
fcs = PPP_INITFCS;
|
||||
continue;
|
||||
}
|
||||
if (flush_flag)
|
||||
continue;
|
||||
if (escape_flag) {
|
||||
c ^= PPP_TRANS;
|
||||
escape_flag = 0;
|
||||
} else if (c == PPP_ESCAPE) {
|
||||
escape_flag = 1;
|
||||
continue;
|
||||
}
|
||||
if (framelen >= framemax) {
|
||||
flush_flag = 1;
|
||||
continue;
|
||||
}
|
||||
frame[framelen++] = c;
|
||||
fcs = PPP_FCS(fcs, c);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* loop_frame - given a frame obtained from the loopback,
|
||||
* decide whether to bring up the link or not, and, if we want
|
||||
* to transmit this frame later, put it on the pending queue.
|
||||
* Return value is 1 if we need to bring up the link, 0 otherwise.
|
||||
* We assume that the kernel driver has already applied the
|
||||
* pass_filter, so we won't get packets it rejected.
|
||||
* We apply the active_filter to see if we want this packet to
|
||||
* bring up the link.
|
||||
*/
|
||||
int
|
||||
loop_frame(frame, len)
|
||||
unsigned char *frame;
|
||||
int len;
|
||||
{
|
||||
struct packet *pkt;
|
||||
|
||||
/* dbglog("from loop: %P", frame, len); */
|
||||
if (len < PPP_HDRLEN)
|
||||
return 0;
|
||||
if ((PPP_PROTOCOL(frame) & 0x8000) != 0)
|
||||
return 0; /* shouldn't get any of these anyway */
|
||||
if (!active_packet(frame, len))
|
||||
return 0;
|
||||
|
||||
pkt = (struct packet *) malloc(sizeof(struct packet) + len);
|
||||
if (pkt != NULL) {
|
||||
pkt->length = len;
|
||||
pkt->next = NULL;
|
||||
memcpy(pkt->data, frame, len);
|
||||
if (pend_q == NULL)
|
||||
pend_q = pkt;
|
||||
else
|
||||
pend_qtail->next = pkt;
|
||||
pend_qtail = pkt;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* demand_rexmit - Resend all those frames which we got via the
|
||||
* loopback, now that the real serial link is up.
|
||||
*/
|
||||
void
|
||||
demand_rexmit(proto, newip)
|
||||
int proto;
|
||||
u32_t newip;
|
||||
{
|
||||
struct packet *pkt, *prev, *nextpkt;
|
||||
unsigned short checksum;
|
||||
unsigned short pkt_checksum = 0;
|
||||
unsigned iphdr;
|
||||
struct timeval tv;
|
||||
char cv = 0;
|
||||
char ipstr[16];
|
||||
|
||||
prev = NULL;
|
||||
pkt = pend_q;
|
||||
pend_q = NULL;
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
select(0,NULL,NULL,NULL,&tv); /* Sleep for 1 Seconds */
|
||||
for (; pkt != NULL; pkt = nextpkt) {
|
||||
nextpkt = pkt->next;
|
||||
if (PPP_PROTOCOL(pkt->data) == proto) {
|
||||
if ( (proto == PPP_IP) && newip ) {
|
||||
/* Get old checksum */
|
||||
|
||||
iphdr = (pkt->data[4] & 15) << 2;
|
||||
checksum = *((unsigned short *) (pkt->data+14));
|
||||
if (checksum == 0xFFFF) {
|
||||
checksum = 0;
|
||||
}
|
||||
|
||||
|
||||
if (pkt->data[13] == 17) {
|
||||
pkt_checksum = *((unsigned short *) (pkt->data+10+iphdr));
|
||||
if (pkt_checksum) {
|
||||
cv = 1;
|
||||
if (pkt_checksum == 0xFFFF) {
|
||||
pkt_checksum = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pkt->data[13] == 6) {
|
||||
pkt_checksum = *((unsigned short *) (pkt->data+20+iphdr));
|
||||
cv = 1;
|
||||
if (pkt_checksum == 0xFFFF) {
|
||||
pkt_checksum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete old Source-IP-Address */
|
||||
checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
pkt_checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
pkt_checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
/* Change Source-IP-Address */
|
||||
* ((u32_t *) (pkt->data + 16)) = newip;
|
||||
|
||||
/* Add new Source-IP-Address */
|
||||
checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
pkt_checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
|
||||
pkt_checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
|
||||
|
||||
/* Write new checksum */
|
||||
if (!checksum) {
|
||||
checksum = 0xFFFF;
|
||||
}
|
||||
*((unsigned short *) (pkt->data+14)) = checksum;
|
||||
if (pkt->data[13] == 6) {
|
||||
*((unsigned short *) (pkt->data+20+iphdr)) = pkt_checksum;
|
||||
}
|
||||
if (cv && (pkt->data[13] == 17) ) {
|
||||
*((unsigned short *) (pkt->data+10+iphdr)) = pkt_checksum;
|
||||
}
|
||||
|
||||
/* Log Packet */
|
||||
strcpy(ipstr,inet_ntoa(*( (struct in_addr *) (pkt->data+16))));
|
||||
if (pkt->data[13] == 1) {
|
||||
syslog(LOG_INFO,"Open ICMP %s -> %s\n",
|
||||
ipstr,
|
||||
inet_ntoa(*( (struct in_addr *) (pkt->data+20))));
|
||||
} else {
|
||||
syslog(LOG_INFO,"Open %s %s:%d -> %s:%d\n",
|
||||
pkt->data[13] == 6 ? "TCP" : "UDP",
|
||||
ipstr,
|
||||
ntohs(*( (short *) (pkt->data+iphdr+4))),
|
||||
inet_ntoa(*( (struct in_addr *) (pkt->data+20))),
|
||||
ntohs(*( (short *) (pkt->data+iphdr+6))));
|
||||
}
|
||||
}
|
||||
output(pcb, pkt->data, pkt->length);
|
||||
free(pkt);
|
||||
} else {
|
||||
if (prev == NULL)
|
||||
pend_q = pkt;
|
||||
else
|
||||
prev->next = pkt;
|
||||
prev = pkt;
|
||||
}
|
||||
}
|
||||
pend_qtail = prev;
|
||||
if (prev != NULL)
|
||||
prev->next = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan a packet to decide whether it is an "active" packet,
|
||||
* that is, whether it is worth bringing up the link for.
|
||||
*/
|
||||
static int
|
||||
active_packet(p, len)
|
||||
unsigned char *p;
|
||||
int len;
|
||||
{
|
||||
int proto, i;
|
||||
const struct protent *protp;
|
||||
|
||||
if (len < PPP_HDRLEN)
|
||||
return 0;
|
||||
proto = PPP_PROTOCOL(p);
|
||||
#ifdef PPP_FILTER
|
||||
p[0] = 1; /* outbound packet indicator */
|
||||
if ((pass_filter.bf_len != 0
|
||||
&& bpf_filter(pass_filter.bf_insns, p, len, len) == 0)
|
||||
|| (active_filter.bf_len != 0
|
||||
&& bpf_filter(active_filter.bf_insns, p, len, len) == 0)) {
|
||||
p[0] = 0xff;
|
||||
return 0;
|
||||
}
|
||||
p[0] = 0xff;
|
||||
#endif
|
||||
for (i = 0; (protp = protocols[i]) != NULL; ++i) {
|
||||
if (protp->protocol < 0xC000 && (protp->protocol & ~0x8000) == proto) {
|
||||
if (protp->active_pkt == NULL)
|
||||
return 1;
|
||||
return (*protp->active_pkt)(p, len);
|
||||
}
|
||||
}
|
||||
return 0; /* not a supported protocol !!?? */
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && DEMAND_SUPPORT */
|
||||
|
||||
4846
ext/lwip/src/netif/ppp/eap.c
Normal file → Executable file
4846
ext/lwip/src/netif/ppp/eap.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
382
ext/lwip/src/netif/ppp/ecp.c
Normal file → Executable file
382
ext/lwip/src/netif/ppp/ecp.c
Normal file → Executable file
@@ -1,191 +1,191 @@
|
||||
/*
|
||||
* ecp.c - PPP Encryption Control Protocol.
|
||||
*
|
||||
* Copyright (c) 2002 Google, Inc.
|
||||
* 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(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Derived from ccp.c, which is:
|
||||
*
|
||||
* Copyright (c) 1994-2002 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 3. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Paul Mackerras
|
||||
* <paulus@samba.org>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ecp.h"
|
||||
|
||||
#if PPP_OPTIONS
|
||||
static option_t ecp_option_list[] = {
|
||||
{ "noecp", o_bool, &ecp_protent.enabled_flag,
|
||||
"Disable ECP negotiation" },
|
||||
{ "-ecp", o_bool, &ecp_protent.enabled_flag,
|
||||
"Disable ECP negotiation", OPT_ALIAS },
|
||||
|
||||
{ NULL }
|
||||
};
|
||||
#endif /* PPP_OPTIONS */
|
||||
|
||||
/*
|
||||
* Protocol entry points from main code.
|
||||
*/
|
||||
static void ecp_init (int unit);
|
||||
/*
|
||||
static void ecp_open (int unit);
|
||||
static void ecp_close (int unit, char *);
|
||||
static void ecp_lowerup (int unit);
|
||||
static void ecp_lowerdown (int);
|
||||
static void ecp_input (int unit, u_char *pkt, int len);
|
||||
static void ecp_protrej (int unit);
|
||||
*/
|
||||
#if PRINTPKT_SUPPORT
|
||||
static int ecp_printpkt (const u_char *pkt, int len,
|
||||
void (*printer) (void *, char *, ...),
|
||||
void *arg);
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
/*
|
||||
static void ecp_datainput (int unit, u_char *pkt, int len);
|
||||
*/
|
||||
|
||||
const struct protent ecp_protent = {
|
||||
PPP_ECP,
|
||||
ecp_init,
|
||||
NULL, /* ecp_input, */
|
||||
NULL, /* ecp_protrej, */
|
||||
NULL, /* ecp_lowerup, */
|
||||
NULL, /* ecp_lowerdown, */
|
||||
NULL, /* ecp_open, */
|
||||
NULL, /* ecp_close, */
|
||||
#if PRINTPKT_SUPPORT
|
||||
ecp_printpkt,
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
#if PPP_DATAINPUT
|
||||
NULL, /* ecp_datainput, */
|
||||
#endif /* PPP_DATAINPUT */
|
||||
#if PRINTPKT_SUPPORT
|
||||
"ECP",
|
||||
"Encrypted",
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
#if PPP_OPTIONS
|
||||
ecp_option_list,
|
||||
NULL,
|
||||
#endif /* PPP_OPTIONS */
|
||||
#if DEMAND_SUPPORT
|
||||
NULL,
|
||||
NULL
|
||||
#endif /* DEMAND_SUPPORT */
|
||||
};
|
||||
|
||||
fsm ecp_fsm[NUM_PPP];
|
||||
ecp_options ecp_wantoptions[NUM_PPP]; /* what to request the peer to use */
|
||||
ecp_options ecp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
|
||||
ecp_options ecp_allowoptions[NUM_PPP]; /* what we'll agree to do */
|
||||
ecp_options ecp_hisoptions[NUM_PPP]; /* what we agreed to do */
|
||||
|
||||
static const fsm_callbacks ecp_callbacks = {
|
||||
NULL, /* ecp_resetci, */
|
||||
NULL, /* ecp_cilen, */
|
||||
NULL, /* ecp_addci, */
|
||||
NULL, /* ecp_ackci, */
|
||||
NULL, /* ecp_nakci, */
|
||||
NULL, /* ecp_rejci, */
|
||||
NULL, /* ecp_reqci, */
|
||||
NULL, /* ecp_up, */
|
||||
NULL, /* ecp_down, */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* ecp_extcode, */
|
||||
"ECP"
|
||||
};
|
||||
|
||||
/*
|
||||
* ecp_init - initialize ECP.
|
||||
*/
|
||||
static void
|
||||
ecp_init(unit)
|
||||
int unit;
|
||||
{
|
||||
fsm *f = &ecp_fsm[unit];
|
||||
|
||||
f->unit = unit;
|
||||
f->protocol = PPP_ECP;
|
||||
f->callbacks = &ecp_callbacks;
|
||||
fsm_init(f);
|
||||
|
||||
#if 0 /* Not necessary, everything is cleared in ppp_new() */
|
||||
memset(&ecp_wantoptions[unit], 0, sizeof(ecp_options));
|
||||
memset(&ecp_gotoptions[unit], 0, sizeof(ecp_options));
|
||||
memset(&ecp_allowoptions[unit], 0, sizeof(ecp_options));
|
||||
memset(&ecp_hisoptions[unit], 0, sizeof(ecp_options));
|
||||
#endif /* 0 */
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if PRINTPKT_SUPPORT
|
||||
static int
|
||||
ecp_printpkt(p, plen, printer, arg)
|
||||
const u_char *p;
|
||||
int plen;
|
||||
void (*printer) (void *, char *, ...);
|
||||
void *arg;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
|
||||
#endif /* PPP_SUPPORT && ECP_SUPPORT */
|
||||
/*
|
||||
* ecp.c - PPP Encryption Control Protocol.
|
||||
*
|
||||
* Copyright (c) 2002 Google, Inc.
|
||||
* 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(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Derived from ccp.c, which is:
|
||||
*
|
||||
* Copyright (c) 1994-2002 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 3. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Paul Mackerras
|
||||
* <paulus@samba.org>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ecp.h"
|
||||
|
||||
#if PPP_OPTIONS
|
||||
static option_t ecp_option_list[] = {
|
||||
{ "noecp", o_bool, &ecp_protent.enabled_flag,
|
||||
"Disable ECP negotiation" },
|
||||
{ "-ecp", o_bool, &ecp_protent.enabled_flag,
|
||||
"Disable ECP negotiation", OPT_ALIAS },
|
||||
|
||||
{ NULL }
|
||||
};
|
||||
#endif /* PPP_OPTIONS */
|
||||
|
||||
/*
|
||||
* Protocol entry points from main code.
|
||||
*/
|
||||
static void ecp_init (int unit);
|
||||
/*
|
||||
static void ecp_open (int unit);
|
||||
static void ecp_close (int unit, char *);
|
||||
static void ecp_lowerup (int unit);
|
||||
static void ecp_lowerdown (int);
|
||||
static void ecp_input (int unit, u_char *pkt, int len);
|
||||
static void ecp_protrej (int unit);
|
||||
*/
|
||||
#if PRINTPKT_SUPPORT
|
||||
static int ecp_printpkt (const u_char *pkt, int len,
|
||||
void (*printer) (void *, char *, ...),
|
||||
void *arg);
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
/*
|
||||
static void ecp_datainput (int unit, u_char *pkt, int len);
|
||||
*/
|
||||
|
||||
const struct protent ecp_protent = {
|
||||
PPP_ECP,
|
||||
ecp_init,
|
||||
NULL, /* ecp_input, */
|
||||
NULL, /* ecp_protrej, */
|
||||
NULL, /* ecp_lowerup, */
|
||||
NULL, /* ecp_lowerdown, */
|
||||
NULL, /* ecp_open, */
|
||||
NULL, /* ecp_close, */
|
||||
#if PRINTPKT_SUPPORT
|
||||
ecp_printpkt,
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
#if PPP_DATAINPUT
|
||||
NULL, /* ecp_datainput, */
|
||||
#endif /* PPP_DATAINPUT */
|
||||
#if PRINTPKT_SUPPORT
|
||||
"ECP",
|
||||
"Encrypted",
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
#if PPP_OPTIONS
|
||||
ecp_option_list,
|
||||
NULL,
|
||||
#endif /* PPP_OPTIONS */
|
||||
#if DEMAND_SUPPORT
|
||||
NULL,
|
||||
NULL
|
||||
#endif /* DEMAND_SUPPORT */
|
||||
};
|
||||
|
||||
fsm ecp_fsm[NUM_PPP];
|
||||
ecp_options ecp_wantoptions[NUM_PPP]; /* what to request the peer to use */
|
||||
ecp_options ecp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
|
||||
ecp_options ecp_allowoptions[NUM_PPP]; /* what we'll agree to do */
|
||||
ecp_options ecp_hisoptions[NUM_PPP]; /* what we agreed to do */
|
||||
|
||||
static const fsm_callbacks ecp_callbacks = {
|
||||
NULL, /* ecp_resetci, */
|
||||
NULL, /* ecp_cilen, */
|
||||
NULL, /* ecp_addci, */
|
||||
NULL, /* ecp_ackci, */
|
||||
NULL, /* ecp_nakci, */
|
||||
NULL, /* ecp_rejci, */
|
||||
NULL, /* ecp_reqci, */
|
||||
NULL, /* ecp_up, */
|
||||
NULL, /* ecp_down, */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* ecp_extcode, */
|
||||
"ECP"
|
||||
};
|
||||
|
||||
/*
|
||||
* ecp_init - initialize ECP.
|
||||
*/
|
||||
static void
|
||||
ecp_init(unit)
|
||||
int unit;
|
||||
{
|
||||
fsm *f = &ecp_fsm[unit];
|
||||
|
||||
f->unit = unit;
|
||||
f->protocol = PPP_ECP;
|
||||
f->callbacks = &ecp_callbacks;
|
||||
fsm_init(f);
|
||||
|
||||
#if 0 /* Not necessary, everything is cleared in ppp_new() */
|
||||
memset(&ecp_wantoptions[unit], 0, sizeof(ecp_options));
|
||||
memset(&ecp_gotoptions[unit], 0, sizeof(ecp_options));
|
||||
memset(&ecp_allowoptions[unit], 0, sizeof(ecp_options));
|
||||
memset(&ecp_hisoptions[unit], 0, sizeof(ecp_options));
|
||||
#endif /* 0 */
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if PRINTPKT_SUPPORT
|
||||
static int
|
||||
ecp_printpkt(p, plen, printer, arg)
|
||||
const u_char *p;
|
||||
int plen;
|
||||
void (*printer) (void *, char *, ...);
|
||||
void *arg;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* PRINTPKT_SUPPORT */
|
||||
|
||||
#endif /* PPP_SUPPORT && ECP_SUPPORT */
|
||||
|
||||
112
ext/lwip/src/netif/ppp/eui64.c
Normal file → Executable file
112
ext/lwip/src/netif/ppp/eui64.c
Normal file → Executable file
@@ -1,56 +1,56 @@
|
||||
/*
|
||||
* eui64.c - EUI64 routines for IPv6CP.
|
||||
*
|
||||
* Copyright (c) 1999 Tommi Komulainen. 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(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 4. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Tommi Komulainen
|
||||
* <Tommi.Komulainen@iki.fi>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id: eui64.c,v 1.6 2002/12/04 23:03:32 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/eui64.h"
|
||||
|
||||
/*
|
||||
* eui64_ntoa - Make an ascii representation of an interface identifier
|
||||
*/
|
||||
char *eui64_ntoa(eui64_t e) {
|
||||
static char buf[20];
|
||||
|
||||
sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
||||
e.e8[0], e.e8[1], e.e8[2], e.e8[3],
|
||||
e.e8[4], e.e8[5], e.e8[6], e.e8[7]);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */
|
||||
/*
|
||||
* eui64.c - EUI64 routines for IPv6CP.
|
||||
*
|
||||
* Copyright (c) 1999 Tommi Komulainen. 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(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* 4. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Tommi Komulainen
|
||||
* <Tommi.Komulainen@iki.fi>".
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $Id: eui64.c,v 1.6 2002/12/04 23:03:32 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/eui64.h"
|
||||
|
||||
/*
|
||||
* eui64_ntoa - Make an ascii representation of an interface identifier
|
||||
*/
|
||||
char *eui64_ntoa(eui64_t e) {
|
||||
static char buf[20];
|
||||
|
||||
sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
||||
e.e8[0], e.e8[1], e.e8[2], e.e8[3],
|
||||
e.e8[4], e.e8[5], e.e8[6], e.e8[7]);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */
|
||||
|
||||
1598
ext/lwip/src/netif/ppp/fsm.c
Normal file → Executable file
1598
ext/lwip/src/netif/ppp/fsm.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
4826
ext/lwip/src/netif/ppp/ipcp.c
Normal file → Executable file
4826
ext/lwip/src/netif/ppp/ipcp.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
3066
ext/lwip/src/netif/ppp/ipv6cp.c
Normal file → Executable file
3066
ext/lwip/src/netif/ppp/ipv6cp.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
5576
ext/lwip/src/netif/ppp/lcp.c
Normal file → Executable file
5576
ext/lwip/src/netif/ppp/lcp.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
588
ext/lwip/src/netif/ppp/magic.c
Normal file → Executable file
588
ext/lwip/src/netif/ppp/magic.c
Normal file → Executable file
@@ -1,294 +1,294 @@
|
||||
/*
|
||||
* magic.c - PPP Magic Number routines.
|
||||
*
|
||||
* Copyright (c) 1984-2000 Carnegie Mellon University. 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 "Carnegie Mellon University" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For permission or any legal
|
||||
* details, please contact
|
||||
* Office of Technology Transfer
|
||||
* Carnegie Mellon University
|
||||
* 5000 Forbes Avenue
|
||||
* Pittsburgh, PA 15213-3890
|
||||
* (412) 268-4387, fax: (412) 268-7395
|
||||
* tech-transfer@andrew.cmu.edu
|
||||
*
|
||||
* 4. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Computing Services
|
||||
* at Carnegie Mellon University (http://www.cmu.edu/computing/)."
|
||||
*
|
||||
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
|
||||
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
* randm.c - Random number generator program file.
|
||||
*
|
||||
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
|
||||
* Copyright (c) 1998 by Global Election Systems Inc.
|
||||
*
|
||||
* The authors hereby grant permission to use, copy, modify, distribute,
|
||||
* and license this software and its documentation for any purpose, provided
|
||||
* that existing copyright notices are retained in all copies and that this
|
||||
* notice and the following disclaimer are included verbatim in any
|
||||
* distributions. No written agreement, license, or royalty fee is required
|
||||
* for any of the authorized uses.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *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 CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* REVISION HISTORY
|
||||
*
|
||||
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
||||
* Ported to lwIP.
|
||||
* 98-06-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
||||
* Extracted from avos.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
|
||||
#if PPP_MD5_RANDM /* Using MD5 for better randomness if enabled */
|
||||
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
#define MD5_HASH_SIZE 16
|
||||
static char magic_randpool[MD5_HASH_SIZE]; /* Pool of randomness. */
|
||||
static long magic_randcount; /* Pseudo-random incrementer */
|
||||
static u32_t magic_randomseed; /* Seed used for random number generation. */
|
||||
|
||||
/*
|
||||
* Churn the randomness pool on a random event. Call this early and often
|
||||
* on random and semi-random system events to build randomness in time for
|
||||
* usage. For randomly timed events, pass a null pointer and a zero length
|
||||
* and this will use the system timer and other sources to add randomness.
|
||||
* If new random data is available, pass a pointer to that and it will be
|
||||
* included.
|
||||
*
|
||||
* Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427
|
||||
*/
|
||||
static void magic_churnrand(char *rand_data, u32_t rand_len) {
|
||||
lwip_md5_context md5_ctx;
|
||||
|
||||
/* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: %u@%P\n", rand_len, rand_data)); */
|
||||
lwip_md5_init(&md5_ctx);
|
||||
lwip_md5_starts(&md5_ctx);
|
||||
lwip_md5_update(&md5_ctx, (u_char *)magic_randpool, sizeof(magic_randpool));
|
||||
if (rand_data) {
|
||||
lwip_md5_update(&md5_ctx, (u_char *)rand_data, rand_len);
|
||||
} else {
|
||||
struct {
|
||||
/* INCLUDE fields for any system sources of randomness */
|
||||
u32_t jiffies;
|
||||
#ifdef LWIP_RAND
|
||||
u32_t rand;
|
||||
#endif /* LWIP_RAND */
|
||||
} sys_data;
|
||||
magic_randomseed += sys_jiffies();
|
||||
sys_data.jiffies = magic_randomseed;
|
||||
#ifdef LWIP_RAND
|
||||
sys_data.rand = LWIP_RAND();
|
||||
#endif /* LWIP_RAND */
|
||||
/* Load sys_data fields here. */
|
||||
lwip_md5_update(&md5_ctx, (u_char *)&sys_data, sizeof(sys_data));
|
||||
}
|
||||
lwip_md5_finish(&md5_ctx, (u_char *)magic_randpool);
|
||||
lwip_md5_free(&md5_ctx);
|
||||
/* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: -> 0\n")); */
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the random number generator.
|
||||
*/
|
||||
void magic_init(void) {
|
||||
magic_churnrand(NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Randomize our random seed value.
|
||||
*/
|
||||
void magic_randomize(void) {
|
||||
magic_churnrand(NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* magic_random_bytes - Fill a buffer with random bytes.
|
||||
*
|
||||
* Use the random pool to generate random data. This degrades to pseudo
|
||||
* random when used faster than randomness is supplied using magic_churnrand().
|
||||
* Note: It's important that there be sufficient randomness in magic_randpool
|
||||
* before this is called for otherwise the range of the result may be
|
||||
* narrow enough to make a search feasible.
|
||||
*
|
||||
* Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427
|
||||
*
|
||||
* XXX Why does he not just call magic_churnrand() for each block? Probably
|
||||
* so that you don't ever publish the seed which could possibly help
|
||||
* predict future values.
|
||||
* XXX Why don't we preserve md5 between blocks and just update it with
|
||||
* magic_randcount each time? Probably there is a weakness but I wish that
|
||||
* it was documented.
|
||||
*/
|
||||
void magic_random_bytes(unsigned char *buf, u32_t buf_len) {
|
||||
lwip_md5_context md5_ctx;
|
||||
u_char tmp[MD5_HASH_SIZE];
|
||||
u32_t n;
|
||||
|
||||
while (buf_len > 0) {
|
||||
lwip_md5_init(&md5_ctx);
|
||||
lwip_md5_starts(&md5_ctx);
|
||||
lwip_md5_update(&md5_ctx, (u_char *)magic_randpool, sizeof(magic_randpool));
|
||||
lwip_md5_update(&md5_ctx, (u_char *)&magic_randcount, sizeof(magic_randcount));
|
||||
lwip_md5_finish(&md5_ctx, tmp);
|
||||
lwip_md5_free(&md5_ctx);
|
||||
magic_randcount++;
|
||||
n = LWIP_MIN(buf_len, MD5_HASH_SIZE);
|
||||
MEMCPY(buf, tmp, n);
|
||||
buf += n;
|
||||
buf_len -= n;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a new random number.
|
||||
*/
|
||||
u32_t magic(void) {
|
||||
u32_t new_rand;
|
||||
|
||||
magic_random_bytes((unsigned char *)&new_rand, sizeof(new_rand));
|
||||
|
||||
return new_rand;
|
||||
}
|
||||
|
||||
#else /* PPP_MD5_RANDM */
|
||||
|
||||
/*****************************/
|
||||
/*** LOCAL DATA STRUCTURES ***/
|
||||
/*****************************/
|
||||
#ifndef LWIP_RAND
|
||||
static int magic_randomized; /* Set when truely randomized. */
|
||||
#endif /* LWIP_RAND */
|
||||
static u32_t magic_randomseed; /* Seed used for random number generation. */
|
||||
|
||||
|
||||
/***********************************/
|
||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||
/***********************************/
|
||||
|
||||
/*
|
||||
* Initialize the random number generator.
|
||||
*
|
||||
* Here we attempt to compute a random number seed but even if
|
||||
* it isn't random, we'll randomize it later.
|
||||
*
|
||||
* The current method uses the fields from the real time clock,
|
||||
* the idle process counter, the millisecond counter, and the
|
||||
* hardware timer tick counter. When this is invoked
|
||||
* in startup(), then the idle counter and timer values may
|
||||
* repeat after each boot and the real time clock may not be
|
||||
* operational. Thus we call it again on the first random
|
||||
* event.
|
||||
*/
|
||||
void magic_init(void) {
|
||||
magic_randomseed += sys_jiffies();
|
||||
#ifndef LWIP_RAND
|
||||
/* Initialize the Borland random number generator. */
|
||||
srand((unsigned)magic_randomseed);
|
||||
#endif /* LWIP_RAND */
|
||||
}
|
||||
|
||||
/*
|
||||
* magic_init - Initialize the magic number generator.
|
||||
*
|
||||
* Randomize our random seed value. Here we use the fact that
|
||||
* this function is called at *truely random* times by the polling
|
||||
* and network functions. Here we only get 16 bits of new random
|
||||
* value but we use the previous value to randomize the other 16
|
||||
* bits.
|
||||
*/
|
||||
void magic_randomize(void) {
|
||||
#ifndef LWIP_RAND
|
||||
if (!magic_randomized) {
|
||||
magic_randomized = !0;
|
||||
magic_init();
|
||||
/* The initialization function also updates the seed. */
|
||||
} else {
|
||||
#endif /* LWIP_RAND */
|
||||
magic_randomseed += sys_jiffies();
|
||||
#ifndef LWIP_RAND
|
||||
}
|
||||
#endif /* LWIP_RAND */
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a new random number.
|
||||
*
|
||||
* Here we use the Borland rand() function to supply a pseudo random
|
||||
* number which we make truely random by combining it with our own
|
||||
* seed which is randomized by truely random events.
|
||||
* Thus the numbers will be truely random unless there have been no
|
||||
* operator or network events in which case it will be pseudo random
|
||||
* seeded by the real time clock.
|
||||
*/
|
||||
u32_t magic(void) {
|
||||
#ifdef LWIP_RAND
|
||||
return LWIP_RAND() + magic_randomseed;
|
||||
#else /* LWIP_RAND */
|
||||
return ((u32_t)rand() << 16) + (u32_t)rand() + magic_randomseed;
|
||||
#endif /* LWIP_RAND */
|
||||
}
|
||||
|
||||
/*
|
||||
* magic_random_bytes - Fill a buffer with random bytes.
|
||||
*/
|
||||
void magic_random_bytes(unsigned char *buf, u32_t buf_len) {
|
||||
u32_t new_rand, n;
|
||||
|
||||
while (buf_len > 0) {
|
||||
new_rand = magic();
|
||||
n = LWIP_MIN(buf_len, sizeof(new_rand));
|
||||
MEMCPY(buf, &new_rand, n);
|
||||
buf += n;
|
||||
buf_len -= n;
|
||||
}
|
||||
}
|
||||
#endif /* PPP_MD5_RANDM */
|
||||
|
||||
/*
|
||||
* Return a new random number between 0 and (2^pow)-1 included.
|
||||
*/
|
||||
u32_t magic_pow(u8_t pow) {
|
||||
return magic() & ~(~0UL<<pow);
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT */
|
||||
/*
|
||||
* magic.c - PPP Magic Number routines.
|
||||
*
|
||||
* Copyright (c) 1984-2000 Carnegie Mellon University. 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 "Carnegie Mellon University" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For permission or any legal
|
||||
* details, please contact
|
||||
* Office of Technology Transfer
|
||||
* Carnegie Mellon University
|
||||
* 5000 Forbes Avenue
|
||||
* Pittsburgh, PA 15213-3890
|
||||
* (412) 268-4387, fax: (412) 268-7395
|
||||
* tech-transfer@andrew.cmu.edu
|
||||
*
|
||||
* 4. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by Computing Services
|
||||
* at Carnegie Mellon University (http://www.cmu.edu/computing/)."
|
||||
*
|
||||
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
|
||||
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
/*****************************************************************************
|
||||
* randm.c - Random number generator program file.
|
||||
*
|
||||
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
|
||||
* Copyright (c) 1998 by Global Election Systems Inc.
|
||||
*
|
||||
* The authors hereby grant permission to use, copy, modify, distribute,
|
||||
* and license this software and its documentation for any purpose, provided
|
||||
* that existing copyright notices are retained in all copies and that this
|
||||
* notice and the following disclaimer are included verbatim in any
|
||||
* distributions. No written agreement, license, or royalty fee is required
|
||||
* for any of the authorized uses.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *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 CONTRIBUTORS 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* REVISION HISTORY
|
||||
*
|
||||
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
||||
* Ported to lwIP.
|
||||
* 98-06-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
||||
* Extracted from avos.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
|
||||
#if PPP_MD5_RANDM /* Using MD5 for better randomness if enabled */
|
||||
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
#define MD5_HASH_SIZE 16
|
||||
static char magic_randpool[MD5_HASH_SIZE]; /* Pool of randomness. */
|
||||
static long magic_randcount; /* Pseudo-random incrementer */
|
||||
static u32_t magic_randomseed; /* Seed used for random number generation. */
|
||||
|
||||
/*
|
||||
* Churn the randomness pool on a random event. Call this early and often
|
||||
* on random and semi-random system events to build randomness in time for
|
||||
* usage. For randomly timed events, pass a null pointer and a zero length
|
||||
* and this will use the system timer and other sources to add randomness.
|
||||
* If new random data is available, pass a pointer to that and it will be
|
||||
* included.
|
||||
*
|
||||
* Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427
|
||||
*/
|
||||
static void magic_churnrand(char *rand_data, u32_t rand_len) {
|
||||
lwip_md5_context md5_ctx;
|
||||
|
||||
/* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: %u@%P\n", rand_len, rand_data)); */
|
||||
lwip_md5_init(&md5_ctx);
|
||||
lwip_md5_starts(&md5_ctx);
|
||||
lwip_md5_update(&md5_ctx, (u_char *)magic_randpool, sizeof(magic_randpool));
|
||||
if (rand_data) {
|
||||
lwip_md5_update(&md5_ctx, (u_char *)rand_data, rand_len);
|
||||
} else {
|
||||
struct {
|
||||
/* INCLUDE fields for any system sources of randomness */
|
||||
u32_t jiffies;
|
||||
#ifdef LWIP_RAND
|
||||
u32_t rand;
|
||||
#endif /* LWIP_RAND */
|
||||
} sys_data;
|
||||
magic_randomseed += sys_jiffies();
|
||||
sys_data.jiffies = magic_randomseed;
|
||||
#ifdef LWIP_RAND
|
||||
sys_data.rand = LWIP_RAND();
|
||||
#endif /* LWIP_RAND */
|
||||
/* Load sys_data fields here. */
|
||||
lwip_md5_update(&md5_ctx, (u_char *)&sys_data, sizeof(sys_data));
|
||||
}
|
||||
lwip_md5_finish(&md5_ctx, (u_char *)magic_randpool);
|
||||
lwip_md5_free(&md5_ctx);
|
||||
/* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: -> 0\n")); */
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the random number generator.
|
||||
*/
|
||||
void magic_init(void) {
|
||||
magic_churnrand(NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Randomize our random seed value.
|
||||
*/
|
||||
void magic_randomize(void) {
|
||||
magic_churnrand(NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* magic_random_bytes - Fill a buffer with random bytes.
|
||||
*
|
||||
* Use the random pool to generate random data. This degrades to pseudo
|
||||
* random when used faster than randomness is supplied using magic_churnrand().
|
||||
* Note: It's important that there be sufficient randomness in magic_randpool
|
||||
* before this is called for otherwise the range of the result may be
|
||||
* narrow enough to make a search feasible.
|
||||
*
|
||||
* Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427
|
||||
*
|
||||
* XXX Why does he not just call magic_churnrand() for each block? Probably
|
||||
* so that you don't ever publish the seed which could possibly help
|
||||
* predict future values.
|
||||
* XXX Why don't we preserve md5 between blocks and just update it with
|
||||
* magic_randcount each time? Probably there is a weakness but I wish that
|
||||
* it was documented.
|
||||
*/
|
||||
void magic_random_bytes(unsigned char *buf, u32_t buf_len) {
|
||||
lwip_md5_context md5_ctx;
|
||||
u_char tmp[MD5_HASH_SIZE];
|
||||
u32_t n;
|
||||
|
||||
while (buf_len > 0) {
|
||||
lwip_md5_init(&md5_ctx);
|
||||
lwip_md5_starts(&md5_ctx);
|
||||
lwip_md5_update(&md5_ctx, (u_char *)magic_randpool, sizeof(magic_randpool));
|
||||
lwip_md5_update(&md5_ctx, (u_char *)&magic_randcount, sizeof(magic_randcount));
|
||||
lwip_md5_finish(&md5_ctx, tmp);
|
||||
lwip_md5_free(&md5_ctx);
|
||||
magic_randcount++;
|
||||
n = LWIP_MIN(buf_len, MD5_HASH_SIZE);
|
||||
MEMCPY(buf, tmp, n);
|
||||
buf += n;
|
||||
buf_len -= n;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a new random number.
|
||||
*/
|
||||
u32_t magic(void) {
|
||||
u32_t new_rand;
|
||||
|
||||
magic_random_bytes((unsigned char *)&new_rand, sizeof(new_rand));
|
||||
|
||||
return new_rand;
|
||||
}
|
||||
|
||||
#else /* PPP_MD5_RANDM */
|
||||
|
||||
/*****************************/
|
||||
/*** LOCAL DATA STRUCTURES ***/
|
||||
/*****************************/
|
||||
#ifndef LWIP_RAND
|
||||
static int magic_randomized; /* Set when truely randomized. */
|
||||
#endif /* LWIP_RAND */
|
||||
static u32_t magic_randomseed; /* Seed used for random number generation. */
|
||||
|
||||
|
||||
/***********************************/
|
||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||
/***********************************/
|
||||
|
||||
/*
|
||||
* Initialize the random number generator.
|
||||
*
|
||||
* Here we attempt to compute a random number seed but even if
|
||||
* it isn't random, we'll randomize it later.
|
||||
*
|
||||
* The current method uses the fields from the real time clock,
|
||||
* the idle process counter, the millisecond counter, and the
|
||||
* hardware timer tick counter. When this is invoked
|
||||
* in startup(), then the idle counter and timer values may
|
||||
* repeat after each boot and the real time clock may not be
|
||||
* operational. Thus we call it again on the first random
|
||||
* event.
|
||||
*/
|
||||
void magic_init(void) {
|
||||
magic_randomseed += sys_jiffies();
|
||||
#ifndef LWIP_RAND
|
||||
/* Initialize the Borland random number generator. */
|
||||
srand((unsigned)magic_randomseed);
|
||||
#endif /* LWIP_RAND */
|
||||
}
|
||||
|
||||
/*
|
||||
* magic_init - Initialize the magic number generator.
|
||||
*
|
||||
* Randomize our random seed value. Here we use the fact that
|
||||
* this function is called at *truely random* times by the polling
|
||||
* and network functions. Here we only get 16 bits of new random
|
||||
* value but we use the previous value to randomize the other 16
|
||||
* bits.
|
||||
*/
|
||||
void magic_randomize(void) {
|
||||
#ifndef LWIP_RAND
|
||||
if (!magic_randomized) {
|
||||
magic_randomized = !0;
|
||||
magic_init();
|
||||
/* The initialization function also updates the seed. */
|
||||
} else {
|
||||
#endif /* LWIP_RAND */
|
||||
magic_randomseed += sys_jiffies();
|
||||
#ifndef LWIP_RAND
|
||||
}
|
||||
#endif /* LWIP_RAND */
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a new random number.
|
||||
*
|
||||
* Here we use the Borland rand() function to supply a pseudo random
|
||||
* number which we make truely random by combining it with our own
|
||||
* seed which is randomized by truely random events.
|
||||
* Thus the numbers will be truely random unless there have been no
|
||||
* operator or network events in which case it will be pseudo random
|
||||
* seeded by the real time clock.
|
||||
*/
|
||||
u32_t magic(void) {
|
||||
#ifdef LWIP_RAND
|
||||
return LWIP_RAND() + magic_randomseed;
|
||||
#else /* LWIP_RAND */
|
||||
return ((u32_t)rand() << 16) + (u32_t)rand() + magic_randomseed;
|
||||
#endif /* LWIP_RAND */
|
||||
}
|
||||
|
||||
/*
|
||||
* magic_random_bytes - Fill a buffer with random bytes.
|
||||
*/
|
||||
void magic_random_bytes(unsigned char *buf, u32_t buf_len) {
|
||||
u32_t new_rand, n;
|
||||
|
||||
while (buf_len > 0) {
|
||||
new_rand = magic();
|
||||
n = LWIP_MIN(buf_len, sizeof(new_rand));
|
||||
MEMCPY(buf, &new_rand, n);
|
||||
buf += n;
|
||||
buf_len -= n;
|
||||
}
|
||||
}
|
||||
#endif /* PPP_MD5_RANDM */
|
||||
|
||||
/*
|
||||
* Return a new random number between 0 and (2^pow)-1 included.
|
||||
*/
|
||||
u32_t magic_pow(u8_t pow) {
|
||||
return magic() & ~(~0UL<<pow);
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT */
|
||||
|
||||
824
ext/lwip/src/netif/ppp/mppe.c
Normal file → Executable file
824
ext/lwip/src/netif/ppp/mppe.c
Normal file → Executable file
@@ -1,412 +1,412 @@
|
||||
/*
|
||||
* mppe.c - interface MPPE to the PPP code.
|
||||
*
|
||||
* By Frank Cusack <fcusack@fcusack.com>.
|
||||
* Copyright (c) 2002,2003,2004 Google, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* License:
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, provided that the above copyright
|
||||
* notice appears in all copies. This software is provided without any
|
||||
* warranty, express or implied.
|
||||
*
|
||||
* Changelog:
|
||||
* 08/12/05 - Matt Domsch <Matt_Domsch@dell.com>
|
||||
* Only need extra skb padding on transmit, not receive.
|
||||
* 06/18/04 - Matt Domsch <Matt_Domsch@dell.com>, Oleg Makarenko <mole@quadra.ru>
|
||||
* Use Linux kernel 2.6 arc4 and sha1 routines rather than
|
||||
* providing our own.
|
||||
* 2/15/04 - TS: added #include <version.h> and testing for Kernel
|
||||
* version before using
|
||||
* MOD_DEC_USAGE_COUNT/MOD_INC_USAGE_COUNT which are
|
||||
* deprecated in 2.6
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "lwip/err.h"
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/ccp.h"
|
||||
#include "netif/ppp/mppe.h"
|
||||
#include "netif/ppp/pppdebug.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
#define SHA1_SIGNATURE_SIZE 20
|
||||
|
||||
/* ppp_mppe_state.bits definitions */
|
||||
#define MPPE_BIT_A 0x80 /* Encryption table were (re)inititalized */
|
||||
#define MPPE_BIT_B 0x40 /* MPPC only (not implemented) */
|
||||
#define MPPE_BIT_C 0x20 /* MPPC only (not implemented) */
|
||||
#define MPPE_BIT_D 0x10 /* This is an encrypted frame */
|
||||
|
||||
#define MPPE_BIT_FLUSHED MPPE_BIT_A
|
||||
#define MPPE_BIT_ENCRYPTED MPPE_BIT_D
|
||||
|
||||
#define MPPE_BITS(p) ((p)[0] & 0xf0)
|
||||
#define MPPE_CCOUNT(p) ((((p)[0] & 0x0f) << 8) + (p)[1])
|
||||
#define MPPE_CCOUNT_SPACE 0x1000 /* The size of the ccount space */
|
||||
|
||||
#define MPPE_OVHD 2 /* MPPE overhead/packet */
|
||||
#define SANITY_MAX 1600 /* Max bogon factor we will tolerate */
|
||||
|
||||
/*
|
||||
* Perform the MPPE rekey algorithm, from RFC 3078, sec. 7.3.
|
||||
* Well, not what's written there, but rather what they meant.
|
||||
*/
|
||||
static void mppe_rekey(ppp_mppe_state * state, int initial_key)
|
||||
{
|
||||
lwip_sha1_context sha1_ctx;
|
||||
u8_t sha1_digest[SHA1_SIGNATURE_SIZE];
|
||||
|
||||
/*
|
||||
* Key Derivation, from RFC 3078, RFC 3079.
|
||||
* Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
|
||||
*/
|
||||
lwip_sha1_init(&sha1_ctx);
|
||||
lwip_sha1_starts(&sha1_ctx);
|
||||
lwip_sha1_update(&sha1_ctx, state->master_key, state->keylen);
|
||||
lwip_sha1_update(&sha1_ctx, mppe_sha1_pad1, SHA1_PAD_SIZE);
|
||||
lwip_sha1_update(&sha1_ctx, state->session_key, state->keylen);
|
||||
lwip_sha1_update(&sha1_ctx, mppe_sha1_pad2, SHA1_PAD_SIZE);
|
||||
lwip_sha1_finish(&sha1_ctx, sha1_digest);
|
||||
lwip_sha1_free(&sha1_ctx);
|
||||
MEMCPY(state->session_key, sha1_digest, state->keylen);
|
||||
|
||||
if (!initial_key) {
|
||||
lwip_arc4_init(&state->arc4);
|
||||
lwip_arc4_setup(&state->arc4, sha1_digest, state->keylen);
|
||||
lwip_arc4_crypt(&state->arc4, state->session_key, state->keylen);
|
||||
lwip_arc4_free(&state->arc4);
|
||||
}
|
||||
if (state->keylen == 8) {
|
||||
/* See RFC 3078 */
|
||||
state->session_key[0] = 0xd1;
|
||||
state->session_key[1] = 0x26;
|
||||
state->session_key[2] = 0x9e;
|
||||
}
|
||||
lwip_arc4_init(&state->arc4);
|
||||
lwip_arc4_setup(&state->arc4, state->session_key, state->keylen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set key, used by MSCHAP before mppe_init() is actually called by CCP so we
|
||||
* don't have to keep multiple copies of keys.
|
||||
*/
|
||||
void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key) {
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
MEMCPY(state->master_key, key, MPPE_MAX_KEY_LEN);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize (de)compressor state.
|
||||
*/
|
||||
void
|
||||
mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options)
|
||||
{
|
||||
#if PPP_DEBUG
|
||||
const u8_t *debugstr = (const u8_t*)"mppe_comp_init";
|
||||
if (&pcb->mppe_decomp == state) {
|
||||
debugstr = (const u8_t*)"mppe_decomp_init";
|
||||
}
|
||||
#endif /* PPP_DEBUG */
|
||||
|
||||
/* Save keys. */
|
||||
MEMCPY(state->session_key, state->master_key, sizeof(state->master_key));
|
||||
|
||||
if (options & MPPE_OPT_128)
|
||||
state->keylen = 16;
|
||||
else if (options & MPPE_OPT_40)
|
||||
state->keylen = 8;
|
||||
else {
|
||||
PPPDEBUG(LOG_DEBUG, ("%s[%d]: unknown key length\n", debugstr,
|
||||
pcb->netif->num));
|
||||
lcp_close(pcb, "MPPE required but peer negotiation failed");
|
||||
return;
|
||||
}
|
||||
if (options & MPPE_OPT_STATEFUL)
|
||||
state->stateful = 1;
|
||||
|
||||
/* Generate the initial session key. */
|
||||
mppe_rekey(state, 1);
|
||||
|
||||
#if PPP_DEBUG
|
||||
{
|
||||
int i;
|
||||
char mkey[sizeof(state->master_key) * 2 + 1];
|
||||
char skey[sizeof(state->session_key) * 2 + 1];
|
||||
|
||||
PPPDEBUG(LOG_DEBUG, ("%s[%d]: initialized with %d-bit %s mode\n",
|
||||
debugstr, pcb->netif->num, (state->keylen == 16) ? 128 : 40,
|
||||
(state->stateful) ? "stateful" : "stateless"));
|
||||
|
||||
for (i = 0; i < (int)sizeof(state->master_key); i++)
|
||||
sprintf(mkey + i * 2, "%02x", state->master_key[i]);
|
||||
for (i = 0; i < (int)sizeof(state->session_key); i++)
|
||||
sprintf(skey + i * 2, "%02x", state->session_key[i]);
|
||||
PPPDEBUG(LOG_DEBUG,
|
||||
("%s[%d]: keys: master: %s initial session: %s\n",
|
||||
debugstr, pcb->netif->num, mkey, skey));
|
||||
}
|
||||
#endif /* PPP_DEBUG */
|
||||
|
||||
/*
|
||||
* Initialize the coherency count. The initial value is not specified
|
||||
* in RFC 3078, but we can make a reasonable assumption that it will
|
||||
* start at 0. Setting it to the max here makes the comp/decomp code
|
||||
* do the right thing (determined through experiment).
|
||||
*/
|
||||
state->ccount = MPPE_CCOUNT_SPACE - 1;
|
||||
|
||||
/*
|
||||
* Note that even though we have initialized the key table, we don't
|
||||
* set the FLUSHED bit. This is contrary to RFC 3078, sec. 3.1.
|
||||
*/
|
||||
state->bits = MPPE_BIT_ENCRYPTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* We received a CCP Reset-Request (actually, we are sending a Reset-Ack),
|
||||
* tell the compressor to rekey. Note that we MUST NOT rekey for
|
||||
* every CCP Reset-Request; we only rekey on the next xmit packet.
|
||||
* We might get multiple CCP Reset-Requests if our CCP Reset-Ack is lost.
|
||||
* So, rekeying for every CCP Reset-Request is broken as the peer will not
|
||||
* know how many times we've rekeyed. (If we rekey and THEN get another
|
||||
* CCP Reset-Request, we must rekey again.)
|
||||
*/
|
||||
void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
|
||||
{
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
state->bits |= MPPE_BIT_FLUSHED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compress (encrypt) a packet.
|
||||
* It's strange to call this a compressor, since the output is always
|
||||
* MPPE_OVHD + 2 bytes larger than the input.
|
||||
*/
|
||||
err_t
|
||||
mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
|
||||
{
|
||||
struct pbuf *n, *np;
|
||||
u8_t *pl;
|
||||
err_t err;
|
||||
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
/* TCP stack requires that we don't change the packet payload, therefore we copy
|
||||
* the whole packet before encryption.
|
||||
*/
|
||||
np = pbuf_alloc(PBUF_RAW, MPPE_OVHD + sizeof(protocol) + (*pb)->tot_len, PBUF_POOL);
|
||||
if (!np) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
/* Hide MPPE header + protocol */
|
||||
pbuf_header(np, -(s16_t)(MPPE_OVHD + sizeof(protocol)));
|
||||
|
||||
if ((err = pbuf_copy(np, *pb)) != ERR_OK) {
|
||||
pbuf_free(np);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Reveal MPPE header + protocol */
|
||||
pbuf_header(np, (s16_t)(MPPE_OVHD + sizeof(protocol)));
|
||||
|
||||
*pb = np;
|
||||
pl = (u8_t*)np->payload;
|
||||
|
||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", pcb->netif->num, state->ccount));
|
||||
/* FIXME: use PUT* macros */
|
||||
pl[0] = state->ccount>>8;
|
||||
pl[1] = state->ccount;
|
||||
|
||||
if (!state->stateful || /* stateless mode */
|
||||
((state->ccount & 0xff) == 0xff) || /* "flag" packet */
|
||||
(state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */
|
||||
/* We must rekey */
|
||||
if (state->stateful) {
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: rekeying\n", pcb->netif->num));
|
||||
}
|
||||
mppe_rekey(state, 0);
|
||||
state->bits |= MPPE_BIT_FLUSHED;
|
||||
}
|
||||
pl[0] |= state->bits;
|
||||
state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */
|
||||
pl += MPPE_OVHD;
|
||||
|
||||
/* Add protocol */
|
||||
/* FIXME: add PFC support */
|
||||
pl[0] = protocol >> 8;
|
||||
pl[1] = protocol;
|
||||
|
||||
/* Hide MPPE header */
|
||||
pbuf_header(np, -(s16_t)MPPE_OVHD);
|
||||
|
||||
/* Encrypt packet */
|
||||
for (n = np; n != NULL; n = n->next) {
|
||||
lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
|
||||
if (n->tot_len == n->len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reveal MPPE header */
|
||||
pbuf_header(np, (s16_t)MPPE_OVHD);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* We received a CCP Reset-Ack. Just ignore it.
|
||||
*/
|
||||
void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
|
||||
{
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
LWIP_UNUSED_ARG(state);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decompress (decrypt) an MPPE packet.
|
||||
*/
|
||||
err_t
|
||||
mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb)
|
||||
{
|
||||
struct pbuf *n0 = *pb, *n;
|
||||
u8_t *pl;
|
||||
u16_t ccount;
|
||||
u8_t flushed;
|
||||
|
||||
/* MPPE Header */
|
||||
if (n0->len < MPPE_OVHD) {
|
||||
PPPDEBUG(LOG_DEBUG,
|
||||
("mppe_decompress[%d]: short pkt (%d)\n",
|
||||
pcb->netif->num, n0->len));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
|
||||
pl = (u8_t*)n0->payload;
|
||||
flushed = MPPE_BITS(pl) & MPPE_BIT_FLUSHED;
|
||||
ccount = MPPE_CCOUNT(pl);
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: ccount %d\n",
|
||||
pcb->netif->num, ccount));
|
||||
|
||||
/* sanity checks -- terminate with extreme prejudice */
|
||||
if (!(MPPE_BITS(pl) & MPPE_BIT_ENCRYPTED)) {
|
||||
PPPDEBUG(LOG_DEBUG,
|
||||
("mppe_decompress[%d]: ENCRYPTED bit not set!\n",
|
||||
pcb->netif->num));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
if (!state->stateful && !flushed) {
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set in "
|
||||
"stateless mode!\n", pcb->netif->num));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set on "
|
||||
"flag packet!\n", pcb->netif->num));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the coherency count.
|
||||
*/
|
||||
|
||||
if (!state->stateful) {
|
||||
/* Discard late packet */
|
||||
if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE > MPPE_CCOUNT_SPACE / 2) {
|
||||
state->sanity_errors++;
|
||||
goto sanity_error;
|
||||
}
|
||||
|
||||
/* RFC 3078, sec 8.1. Rekey for every packet. */
|
||||
while (state->ccount != ccount) {
|
||||
mppe_rekey(state, 0);
|
||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||
}
|
||||
} else {
|
||||
/* RFC 3078, sec 8.2. */
|
||||
if (!state->discard) {
|
||||
/* normal state */
|
||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||
if (ccount != state->ccount) {
|
||||
/*
|
||||
* (ccount > state->ccount)
|
||||
* Packet loss detected, enter the discard state.
|
||||
* Signal the peer to rekey (by sending a CCP Reset-Request).
|
||||
*/
|
||||
state->discard = 1;
|
||||
ccp_resetrequest(pcb);
|
||||
return ERR_BUF;
|
||||
}
|
||||
} else {
|
||||
/* discard state */
|
||||
if (!flushed) {
|
||||
/* ccp.c will be silent (no additional CCP Reset-Requests). */
|
||||
return ERR_BUF;
|
||||
} else {
|
||||
/* Rekey for every missed "flag" packet. */
|
||||
while ((ccount & ~0xff) !=
|
||||
(state->ccount & ~0xff)) {
|
||||
mppe_rekey(state, 0);
|
||||
state->ccount =
|
||||
(state->ccount +
|
||||
256) % MPPE_CCOUNT_SPACE;
|
||||
}
|
||||
|
||||
/* reset */
|
||||
state->discard = 0;
|
||||
state->ccount = ccount;
|
||||
/*
|
||||
* Another problem with RFC 3078 here. It implies that the
|
||||
* peer need not send a Reset-Ack packet. But RFC 1962
|
||||
* requires it. Hopefully, M$ does send a Reset-Ack; even
|
||||
* though it isn't required for MPPE synchronization, it is
|
||||
* required to reset CCP state.
|
||||
*/
|
||||
}
|
||||
}
|
||||
if (flushed)
|
||||
mppe_rekey(state, 0);
|
||||
}
|
||||
|
||||
/* Hide MPPE header */
|
||||
pbuf_header(n0, -(s16_t)(MPPE_OVHD));
|
||||
|
||||
/* Decrypt the packet. */
|
||||
for (n = n0; n != NULL; n = n->next) {
|
||||
lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
|
||||
if (n->tot_len == n->len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* good packet credit */
|
||||
state->sanity_errors >>= 1;
|
||||
|
||||
return ERR_OK;
|
||||
|
||||
sanity_error:
|
||||
if (state->sanity_errors >= SANITY_MAX) {
|
||||
/*
|
||||
* Take LCP down if the peer is sending too many bogons.
|
||||
* We don't want to do this for a single or just a few
|
||||
* instances since it could just be due to packet corruption.
|
||||
*/
|
||||
lcp_close(pcb, "Too many MPPE errors");
|
||||
}
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && MPPE_SUPPORT */
|
||||
/*
|
||||
* mppe.c - interface MPPE to the PPP code.
|
||||
*
|
||||
* By Frank Cusack <fcusack@fcusack.com>.
|
||||
* Copyright (c) 2002,2003,2004 Google, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* License:
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, provided that the above copyright
|
||||
* notice appears in all copies. This software is provided without any
|
||||
* warranty, express or implied.
|
||||
*
|
||||
* Changelog:
|
||||
* 08/12/05 - Matt Domsch <Matt_Domsch@dell.com>
|
||||
* Only need extra skb padding on transmit, not receive.
|
||||
* 06/18/04 - Matt Domsch <Matt_Domsch@dell.com>, Oleg Makarenko <mole@quadra.ru>
|
||||
* Use Linux kernel 2.6 arc4 and sha1 routines rather than
|
||||
* providing our own.
|
||||
* 2/15/04 - TS: added #include <version.h> and testing for Kernel
|
||||
* version before using
|
||||
* MOD_DEC_USAGE_COUNT/MOD_INC_USAGE_COUNT which are
|
||||
* deprecated in 2.6
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "lwip/err.h"
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/ccp.h"
|
||||
#include "netif/ppp/mppe.h"
|
||||
#include "netif/ppp/pppdebug.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
#define SHA1_SIGNATURE_SIZE 20
|
||||
|
||||
/* ppp_mppe_state.bits definitions */
|
||||
#define MPPE_BIT_A 0x80 /* Encryption table were (re)inititalized */
|
||||
#define MPPE_BIT_B 0x40 /* MPPC only (not implemented) */
|
||||
#define MPPE_BIT_C 0x20 /* MPPC only (not implemented) */
|
||||
#define MPPE_BIT_D 0x10 /* This is an encrypted frame */
|
||||
|
||||
#define MPPE_BIT_FLUSHED MPPE_BIT_A
|
||||
#define MPPE_BIT_ENCRYPTED MPPE_BIT_D
|
||||
|
||||
#define MPPE_BITS(p) ((p)[0] & 0xf0)
|
||||
#define MPPE_CCOUNT(p) ((((p)[0] & 0x0f) << 8) + (p)[1])
|
||||
#define MPPE_CCOUNT_SPACE 0x1000 /* The size of the ccount space */
|
||||
|
||||
#define MPPE_OVHD 2 /* MPPE overhead/packet */
|
||||
#define SANITY_MAX 1600 /* Max bogon factor we will tolerate */
|
||||
|
||||
/*
|
||||
* Perform the MPPE rekey algorithm, from RFC 3078, sec. 7.3.
|
||||
* Well, not what's written there, but rather what they meant.
|
||||
*/
|
||||
static void mppe_rekey(ppp_mppe_state * state, int initial_key)
|
||||
{
|
||||
lwip_sha1_context sha1_ctx;
|
||||
u8_t sha1_digest[SHA1_SIGNATURE_SIZE];
|
||||
|
||||
/*
|
||||
* Key Derivation, from RFC 3078, RFC 3079.
|
||||
* Equivalent to Get_Key() for MS-CHAP as described in RFC 3079.
|
||||
*/
|
||||
lwip_sha1_init(&sha1_ctx);
|
||||
lwip_sha1_starts(&sha1_ctx);
|
||||
lwip_sha1_update(&sha1_ctx, state->master_key, state->keylen);
|
||||
lwip_sha1_update(&sha1_ctx, mppe_sha1_pad1, SHA1_PAD_SIZE);
|
||||
lwip_sha1_update(&sha1_ctx, state->session_key, state->keylen);
|
||||
lwip_sha1_update(&sha1_ctx, mppe_sha1_pad2, SHA1_PAD_SIZE);
|
||||
lwip_sha1_finish(&sha1_ctx, sha1_digest);
|
||||
lwip_sha1_free(&sha1_ctx);
|
||||
MEMCPY(state->session_key, sha1_digest, state->keylen);
|
||||
|
||||
if (!initial_key) {
|
||||
lwip_arc4_init(&state->arc4);
|
||||
lwip_arc4_setup(&state->arc4, sha1_digest, state->keylen);
|
||||
lwip_arc4_crypt(&state->arc4, state->session_key, state->keylen);
|
||||
lwip_arc4_free(&state->arc4);
|
||||
}
|
||||
if (state->keylen == 8) {
|
||||
/* See RFC 3078 */
|
||||
state->session_key[0] = 0xd1;
|
||||
state->session_key[1] = 0x26;
|
||||
state->session_key[2] = 0x9e;
|
||||
}
|
||||
lwip_arc4_init(&state->arc4);
|
||||
lwip_arc4_setup(&state->arc4, state->session_key, state->keylen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set key, used by MSCHAP before mppe_init() is actually called by CCP so we
|
||||
* don't have to keep multiple copies of keys.
|
||||
*/
|
||||
void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key) {
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
MEMCPY(state->master_key, key, MPPE_MAX_KEY_LEN);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize (de)compressor state.
|
||||
*/
|
||||
void
|
||||
mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options)
|
||||
{
|
||||
#if PPP_DEBUG
|
||||
const u8_t *debugstr = (const u8_t*)"mppe_comp_init";
|
||||
if (&pcb->mppe_decomp == state) {
|
||||
debugstr = (const u8_t*)"mppe_decomp_init";
|
||||
}
|
||||
#endif /* PPP_DEBUG */
|
||||
|
||||
/* Save keys. */
|
||||
MEMCPY(state->session_key, state->master_key, sizeof(state->master_key));
|
||||
|
||||
if (options & MPPE_OPT_128)
|
||||
state->keylen = 16;
|
||||
else if (options & MPPE_OPT_40)
|
||||
state->keylen = 8;
|
||||
else {
|
||||
PPPDEBUG(LOG_DEBUG, ("%s[%d]: unknown key length\n", debugstr,
|
||||
pcb->netif->num));
|
||||
lcp_close(pcb, "MPPE required but peer negotiation failed");
|
||||
return;
|
||||
}
|
||||
if (options & MPPE_OPT_STATEFUL)
|
||||
state->stateful = 1;
|
||||
|
||||
/* Generate the initial session key. */
|
||||
mppe_rekey(state, 1);
|
||||
|
||||
#if PPP_DEBUG
|
||||
{
|
||||
int i;
|
||||
char mkey[sizeof(state->master_key) * 2 + 1];
|
||||
char skey[sizeof(state->session_key) * 2 + 1];
|
||||
|
||||
PPPDEBUG(LOG_DEBUG, ("%s[%d]: initialized with %d-bit %s mode\n",
|
||||
debugstr, pcb->netif->num, (state->keylen == 16) ? 128 : 40,
|
||||
(state->stateful) ? "stateful" : "stateless"));
|
||||
|
||||
for (i = 0; i < (int)sizeof(state->master_key); i++)
|
||||
sprintf(mkey + i * 2, "%02x", state->master_key[i]);
|
||||
for (i = 0; i < (int)sizeof(state->session_key); i++)
|
||||
sprintf(skey + i * 2, "%02x", state->session_key[i]);
|
||||
PPPDEBUG(LOG_DEBUG,
|
||||
("%s[%d]: keys: master: %s initial session: %s\n",
|
||||
debugstr, pcb->netif->num, mkey, skey));
|
||||
}
|
||||
#endif /* PPP_DEBUG */
|
||||
|
||||
/*
|
||||
* Initialize the coherency count. The initial value is not specified
|
||||
* in RFC 3078, but we can make a reasonable assumption that it will
|
||||
* start at 0. Setting it to the max here makes the comp/decomp code
|
||||
* do the right thing (determined through experiment).
|
||||
*/
|
||||
state->ccount = MPPE_CCOUNT_SPACE - 1;
|
||||
|
||||
/*
|
||||
* Note that even though we have initialized the key table, we don't
|
||||
* set the FLUSHED bit. This is contrary to RFC 3078, sec. 3.1.
|
||||
*/
|
||||
state->bits = MPPE_BIT_ENCRYPTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* We received a CCP Reset-Request (actually, we are sending a Reset-Ack),
|
||||
* tell the compressor to rekey. Note that we MUST NOT rekey for
|
||||
* every CCP Reset-Request; we only rekey on the next xmit packet.
|
||||
* We might get multiple CCP Reset-Requests if our CCP Reset-Ack is lost.
|
||||
* So, rekeying for every CCP Reset-Request is broken as the peer will not
|
||||
* know how many times we've rekeyed. (If we rekey and THEN get another
|
||||
* CCP Reset-Request, we must rekey again.)
|
||||
*/
|
||||
void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
|
||||
{
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
state->bits |= MPPE_BIT_FLUSHED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compress (encrypt) a packet.
|
||||
* It's strange to call this a compressor, since the output is always
|
||||
* MPPE_OVHD + 2 bytes larger than the input.
|
||||
*/
|
||||
err_t
|
||||
mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol)
|
||||
{
|
||||
struct pbuf *n, *np;
|
||||
u8_t *pl;
|
||||
err_t err;
|
||||
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
/* TCP stack requires that we don't change the packet payload, therefore we copy
|
||||
* the whole packet before encryption.
|
||||
*/
|
||||
np = pbuf_alloc(PBUF_RAW, MPPE_OVHD + sizeof(protocol) + (*pb)->tot_len, PBUF_POOL);
|
||||
if (!np) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
/* Hide MPPE header + protocol */
|
||||
pbuf_header(np, -(s16_t)(MPPE_OVHD + sizeof(protocol)));
|
||||
|
||||
if ((err = pbuf_copy(np, *pb)) != ERR_OK) {
|
||||
pbuf_free(np);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Reveal MPPE header + protocol */
|
||||
pbuf_header(np, (s16_t)(MPPE_OVHD + sizeof(protocol)));
|
||||
|
||||
*pb = np;
|
||||
pl = (u8_t*)np->payload;
|
||||
|
||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: ccount %d\n", pcb->netif->num, state->ccount));
|
||||
/* FIXME: use PUT* macros */
|
||||
pl[0] = state->ccount>>8;
|
||||
pl[1] = state->ccount;
|
||||
|
||||
if (!state->stateful || /* stateless mode */
|
||||
((state->ccount & 0xff) == 0xff) || /* "flag" packet */
|
||||
(state->bits & MPPE_BIT_FLUSHED)) { /* CCP Reset-Request */
|
||||
/* We must rekey */
|
||||
if (state->stateful) {
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_compress[%d]: rekeying\n", pcb->netif->num));
|
||||
}
|
||||
mppe_rekey(state, 0);
|
||||
state->bits |= MPPE_BIT_FLUSHED;
|
||||
}
|
||||
pl[0] |= state->bits;
|
||||
state->bits &= ~MPPE_BIT_FLUSHED; /* reset for next xmit */
|
||||
pl += MPPE_OVHD;
|
||||
|
||||
/* Add protocol */
|
||||
/* FIXME: add PFC support */
|
||||
pl[0] = protocol >> 8;
|
||||
pl[1] = protocol;
|
||||
|
||||
/* Hide MPPE header */
|
||||
pbuf_header(np, -(s16_t)MPPE_OVHD);
|
||||
|
||||
/* Encrypt packet */
|
||||
for (n = np; n != NULL; n = n->next) {
|
||||
lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
|
||||
if (n->tot_len == n->len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reveal MPPE header */
|
||||
pbuf_header(np, (s16_t)MPPE_OVHD);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* We received a CCP Reset-Ack. Just ignore it.
|
||||
*/
|
||||
void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state)
|
||||
{
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
LWIP_UNUSED_ARG(state);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decompress (decrypt) an MPPE packet.
|
||||
*/
|
||||
err_t
|
||||
mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb)
|
||||
{
|
||||
struct pbuf *n0 = *pb, *n;
|
||||
u8_t *pl;
|
||||
u16_t ccount;
|
||||
u8_t flushed;
|
||||
|
||||
/* MPPE Header */
|
||||
if (n0->len < MPPE_OVHD) {
|
||||
PPPDEBUG(LOG_DEBUG,
|
||||
("mppe_decompress[%d]: short pkt (%d)\n",
|
||||
pcb->netif->num, n0->len));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
|
||||
pl = (u8_t*)n0->payload;
|
||||
flushed = MPPE_BITS(pl) & MPPE_BIT_FLUSHED;
|
||||
ccount = MPPE_CCOUNT(pl);
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: ccount %d\n",
|
||||
pcb->netif->num, ccount));
|
||||
|
||||
/* sanity checks -- terminate with extreme prejudice */
|
||||
if (!(MPPE_BITS(pl) & MPPE_BIT_ENCRYPTED)) {
|
||||
PPPDEBUG(LOG_DEBUG,
|
||||
("mppe_decompress[%d]: ENCRYPTED bit not set!\n",
|
||||
pcb->netif->num));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
if (!state->stateful && !flushed) {
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set in "
|
||||
"stateless mode!\n", pcb->netif->num));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
|
||||
PPPDEBUG(LOG_DEBUG, ("mppe_decompress[%d]: FLUSHED bit not set on "
|
||||
"flag packet!\n", pcb->netif->num));
|
||||
state->sanity_errors += 100;
|
||||
goto sanity_error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the coherency count.
|
||||
*/
|
||||
|
||||
if (!state->stateful) {
|
||||
/* Discard late packet */
|
||||
if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE > MPPE_CCOUNT_SPACE / 2) {
|
||||
state->sanity_errors++;
|
||||
goto sanity_error;
|
||||
}
|
||||
|
||||
/* RFC 3078, sec 8.1. Rekey for every packet. */
|
||||
while (state->ccount != ccount) {
|
||||
mppe_rekey(state, 0);
|
||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||
}
|
||||
} else {
|
||||
/* RFC 3078, sec 8.2. */
|
||||
if (!state->discard) {
|
||||
/* normal state */
|
||||
state->ccount = (state->ccount + 1) % MPPE_CCOUNT_SPACE;
|
||||
if (ccount != state->ccount) {
|
||||
/*
|
||||
* (ccount > state->ccount)
|
||||
* Packet loss detected, enter the discard state.
|
||||
* Signal the peer to rekey (by sending a CCP Reset-Request).
|
||||
*/
|
||||
state->discard = 1;
|
||||
ccp_resetrequest(pcb);
|
||||
return ERR_BUF;
|
||||
}
|
||||
} else {
|
||||
/* discard state */
|
||||
if (!flushed) {
|
||||
/* ccp.c will be silent (no additional CCP Reset-Requests). */
|
||||
return ERR_BUF;
|
||||
} else {
|
||||
/* Rekey for every missed "flag" packet. */
|
||||
while ((ccount & ~0xff) !=
|
||||
(state->ccount & ~0xff)) {
|
||||
mppe_rekey(state, 0);
|
||||
state->ccount =
|
||||
(state->ccount +
|
||||
256) % MPPE_CCOUNT_SPACE;
|
||||
}
|
||||
|
||||
/* reset */
|
||||
state->discard = 0;
|
||||
state->ccount = ccount;
|
||||
/*
|
||||
* Another problem with RFC 3078 here. It implies that the
|
||||
* peer need not send a Reset-Ack packet. But RFC 1962
|
||||
* requires it. Hopefully, M$ does send a Reset-Ack; even
|
||||
* though it isn't required for MPPE synchronization, it is
|
||||
* required to reset CCP state.
|
||||
*/
|
||||
}
|
||||
}
|
||||
if (flushed)
|
||||
mppe_rekey(state, 0);
|
||||
}
|
||||
|
||||
/* Hide MPPE header */
|
||||
pbuf_header(n0, -(s16_t)(MPPE_OVHD));
|
||||
|
||||
/* Decrypt the packet. */
|
||||
for (n = n0; n != NULL; n = n->next) {
|
||||
lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len);
|
||||
if (n->tot_len == n->len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* good packet credit */
|
||||
state->sanity_errors >>= 1;
|
||||
|
||||
return ERR_OK;
|
||||
|
||||
sanity_error:
|
||||
if (state->sanity_errors >= SANITY_MAX) {
|
||||
/*
|
||||
* Take LCP down if the peer is sending too many bogons.
|
||||
* We don't want to do this for a single or just a few
|
||||
* instances since it could just be due to packet corruption.
|
||||
*/
|
||||
lcp_close(pcb, "Too many MPPE errors");
|
||||
}
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && MPPE_SUPPORT */
|
||||
|
||||
1218
ext/lwip/src/netif/ppp/multilink.c
Normal file → Executable file
1218
ext/lwip/src/netif/ppp/multilink.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
44
ext/lwip/src/netif/ppp/polarssl/README
Normal file → Executable file
44
ext/lwip/src/netif/ppp/polarssl/README
Normal file → Executable file
@@ -1,22 +1,22 @@
|
||||
About PolarSSL files into lwIP PPP support
|
||||
------------------------------------------
|
||||
|
||||
This folder contains some files fetched from the latest BSD release of
|
||||
the PolarSSL project (PolarSSL 0.10.1-bsd) for ciphers and encryption
|
||||
methods we need for lwIP PPP support.
|
||||
|
||||
The PolarSSL files were cleaned to contain only the necessary struct
|
||||
fields and functions needed for lwIP.
|
||||
|
||||
The PolarSSL API was not changed at all, so if you are already using
|
||||
PolarSSL you can choose to skip the compilation of the included PolarSSL
|
||||
library into lwIP.
|
||||
|
||||
If you are not using the embedded copy you must include external
|
||||
libraries into your arch/cc.h port file.
|
||||
|
||||
Beware of the stack requirements which can be a lot larger if you are not
|
||||
using our cleaned PolarSSL library.
|
||||
|
||||
|
||||
PolarSSL project website: http://polarssl.org/
|
||||
About PolarSSL files into lwIP PPP support
|
||||
------------------------------------------
|
||||
|
||||
This folder contains some files fetched from the latest BSD release of
|
||||
the PolarSSL project (PolarSSL 0.10.1-bsd) for ciphers and encryption
|
||||
methods we need for lwIP PPP support.
|
||||
|
||||
The PolarSSL files were cleaned to contain only the necessary struct
|
||||
fields and functions needed for lwIP.
|
||||
|
||||
The PolarSSL API was not changed at all, so if you are already using
|
||||
PolarSSL you can choose to skip the compilation of the included PolarSSL
|
||||
library into lwIP.
|
||||
|
||||
If you are not using the embedded copy you must include external
|
||||
libraries into your arch/cc.h port file.
|
||||
|
||||
Beware of the stack requirements which can be a lot larger if you are not
|
||||
using our cleaned PolarSSL library.
|
||||
|
||||
|
||||
PolarSSL project website: http://polarssl.org/
|
||||
|
||||
202
ext/lwip/src/netif/ppp/polarssl/arc4.c
Normal file → Executable file
202
ext/lwip/src/netif/ppp/polarssl/arc4.c
Normal file → Executable file
@@ -1,101 +1,101 @@
|
||||
/*
|
||||
* An implementation of the ARCFOUR algorithm
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The ARCFOUR algorithm was publicly disclosed on 94/09.
|
||||
*
|
||||
* http://groups.google.com/group/sci.crypt/msg/10a300c9d21afca0
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_ARC4
|
||||
|
||||
#include "netif/ppp/polarssl/arc4.h"
|
||||
/*
|
||||
* ARC4 key schedule
|
||||
*/
|
||||
void arc4_setup( arc4_context *ctx, unsigned char *key, int keylen )
|
||||
{
|
||||
int i, j, k, a;
|
||||
unsigned char *m;
|
||||
|
||||
ctx->x = 0;
|
||||
ctx->y = 0;
|
||||
m = ctx->m;
|
||||
|
||||
for( i = 0; i < 256; i++ )
|
||||
m[i] = (unsigned char) i;
|
||||
|
||||
j = k = 0;
|
||||
|
||||
for( i = 0; i < 256; i++, k++ )
|
||||
{
|
||||
if( k >= keylen ) k = 0;
|
||||
|
||||
a = m[i];
|
||||
j = ( j + a + key[k] ) & 0xFF;
|
||||
m[i] = m[j];
|
||||
m[j] = (unsigned char) a;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ARC4 cipher function
|
||||
*/
|
||||
void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen )
|
||||
{
|
||||
int i, x, y, a, b;
|
||||
unsigned char *m;
|
||||
|
||||
x = ctx->x;
|
||||
y = ctx->y;
|
||||
m = ctx->m;
|
||||
|
||||
for( i = 0; i < buflen; i++ )
|
||||
{
|
||||
x = ( x + 1 ) & 0xFF; a = m[x];
|
||||
y = ( y + a ) & 0xFF; b = m[y];
|
||||
|
||||
m[x] = (unsigned char) b;
|
||||
m[y] = (unsigned char) a;
|
||||
|
||||
buf[i] = (unsigned char)
|
||||
( buf[i] ^ m[(unsigned char)( a + b )] );
|
||||
}
|
||||
|
||||
ctx->x = x;
|
||||
ctx->y = y;
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES */
|
||||
/*
|
||||
* An implementation of the ARCFOUR algorithm
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The ARCFOUR algorithm was publicly disclosed on 94/09.
|
||||
*
|
||||
* http://groups.google.com/group/sci.crypt/msg/10a300c9d21afca0
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_ARC4
|
||||
|
||||
#include "netif/ppp/polarssl/arc4.h"
|
||||
/*
|
||||
* ARC4 key schedule
|
||||
*/
|
||||
void arc4_setup( arc4_context *ctx, unsigned char *key, int keylen )
|
||||
{
|
||||
int i, j, k, a;
|
||||
unsigned char *m;
|
||||
|
||||
ctx->x = 0;
|
||||
ctx->y = 0;
|
||||
m = ctx->m;
|
||||
|
||||
for( i = 0; i < 256; i++ )
|
||||
m[i] = (unsigned char) i;
|
||||
|
||||
j = k = 0;
|
||||
|
||||
for( i = 0; i < 256; i++, k++ )
|
||||
{
|
||||
if( k >= keylen ) k = 0;
|
||||
|
||||
a = m[i];
|
||||
j = ( j + a + key[k] ) & 0xFF;
|
||||
m[i] = m[j];
|
||||
m[j] = (unsigned char) a;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ARC4 cipher function
|
||||
*/
|
||||
void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen )
|
||||
{
|
||||
int i, x, y, a, b;
|
||||
unsigned char *m;
|
||||
|
||||
x = ctx->x;
|
||||
y = ctx->y;
|
||||
m = ctx->m;
|
||||
|
||||
for( i = 0; i < buflen; i++ )
|
||||
{
|
||||
x = ( x + 1 ) & 0xFF; a = m[x];
|
||||
y = ( y + a ) & 0xFF; b = m[y];
|
||||
|
||||
m[x] = (unsigned char) b;
|
||||
m[y] = (unsigned char) a;
|
||||
|
||||
buf[i] = (unsigned char)
|
||||
( buf[i] ^ m[(unsigned char)( a + b )] );
|
||||
}
|
||||
|
||||
ctx->x = x;
|
||||
ctx->y = y;
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES */
|
||||
|
||||
844
ext/lwip/src/netif/ppp/polarssl/des.c
Normal file → Executable file
844
ext/lwip/src/netif/ppp/polarssl/des.c
Normal file → Executable file
@@ -1,422 +1,422 @@
|
||||
/*
|
||||
* FIPS-46-3 compliant Triple-DES implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* DES, on which TDES is based, was originally designed by Horst Feistel
|
||||
* at IBM in 1974, and was adopted as a standard by NIST (formerly NBS).
|
||||
*
|
||||
* http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES
|
||||
|
||||
#include "netif/ppp/polarssl/des.h"
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_BE
|
||||
#define GET_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_BE
|
||||
#define PUT_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Expanded DES S-boxes
|
||||
*/
|
||||
static const unsigned long SB1[64] =
|
||||
{
|
||||
0x01010400, 0x00000000, 0x00010000, 0x01010404,
|
||||
0x01010004, 0x00010404, 0x00000004, 0x00010000,
|
||||
0x00000400, 0x01010400, 0x01010404, 0x00000400,
|
||||
0x01000404, 0x01010004, 0x01000000, 0x00000004,
|
||||
0x00000404, 0x01000400, 0x01000400, 0x00010400,
|
||||
0x00010400, 0x01010000, 0x01010000, 0x01000404,
|
||||
0x00010004, 0x01000004, 0x01000004, 0x00010004,
|
||||
0x00000000, 0x00000404, 0x00010404, 0x01000000,
|
||||
0x00010000, 0x01010404, 0x00000004, 0x01010000,
|
||||
0x01010400, 0x01000000, 0x01000000, 0x00000400,
|
||||
0x01010004, 0x00010000, 0x00010400, 0x01000004,
|
||||
0x00000400, 0x00000004, 0x01000404, 0x00010404,
|
||||
0x01010404, 0x00010004, 0x01010000, 0x01000404,
|
||||
0x01000004, 0x00000404, 0x00010404, 0x01010400,
|
||||
0x00000404, 0x01000400, 0x01000400, 0x00000000,
|
||||
0x00010004, 0x00010400, 0x00000000, 0x01010004
|
||||
};
|
||||
|
||||
static const unsigned long SB2[64] =
|
||||
{
|
||||
0x80108020, 0x80008000, 0x00008000, 0x00108020,
|
||||
0x00100000, 0x00000020, 0x80100020, 0x80008020,
|
||||
0x80000020, 0x80108020, 0x80108000, 0x80000000,
|
||||
0x80008000, 0x00100000, 0x00000020, 0x80100020,
|
||||
0x00108000, 0x00100020, 0x80008020, 0x00000000,
|
||||
0x80000000, 0x00008000, 0x00108020, 0x80100000,
|
||||
0x00100020, 0x80000020, 0x00000000, 0x00108000,
|
||||
0x00008020, 0x80108000, 0x80100000, 0x00008020,
|
||||
0x00000000, 0x00108020, 0x80100020, 0x00100000,
|
||||
0x80008020, 0x80100000, 0x80108000, 0x00008000,
|
||||
0x80100000, 0x80008000, 0x00000020, 0x80108020,
|
||||
0x00108020, 0x00000020, 0x00008000, 0x80000000,
|
||||
0x00008020, 0x80108000, 0x00100000, 0x80000020,
|
||||
0x00100020, 0x80008020, 0x80000020, 0x00100020,
|
||||
0x00108000, 0x00000000, 0x80008000, 0x00008020,
|
||||
0x80000000, 0x80100020, 0x80108020, 0x00108000
|
||||
};
|
||||
|
||||
static const unsigned long SB3[64] =
|
||||
{
|
||||
0x00000208, 0x08020200, 0x00000000, 0x08020008,
|
||||
0x08000200, 0x00000000, 0x00020208, 0x08000200,
|
||||
0x00020008, 0x08000008, 0x08000008, 0x00020000,
|
||||
0x08020208, 0x00020008, 0x08020000, 0x00000208,
|
||||
0x08000000, 0x00000008, 0x08020200, 0x00000200,
|
||||
0x00020200, 0x08020000, 0x08020008, 0x00020208,
|
||||
0x08000208, 0x00020200, 0x00020000, 0x08000208,
|
||||
0x00000008, 0x08020208, 0x00000200, 0x08000000,
|
||||
0x08020200, 0x08000000, 0x00020008, 0x00000208,
|
||||
0x00020000, 0x08020200, 0x08000200, 0x00000000,
|
||||
0x00000200, 0x00020008, 0x08020208, 0x08000200,
|
||||
0x08000008, 0x00000200, 0x00000000, 0x08020008,
|
||||
0x08000208, 0x00020000, 0x08000000, 0x08020208,
|
||||
0x00000008, 0x00020208, 0x00020200, 0x08000008,
|
||||
0x08020000, 0x08000208, 0x00000208, 0x08020000,
|
||||
0x00020208, 0x00000008, 0x08020008, 0x00020200
|
||||
};
|
||||
|
||||
static const unsigned long SB4[64] =
|
||||
{
|
||||
0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
||||
0x00802080, 0x00800081, 0x00800001, 0x00002001,
|
||||
0x00000000, 0x00802000, 0x00802000, 0x00802081,
|
||||
0x00000081, 0x00000000, 0x00800080, 0x00800001,
|
||||
0x00000001, 0x00002000, 0x00800000, 0x00802001,
|
||||
0x00000080, 0x00800000, 0x00002001, 0x00002080,
|
||||
0x00800081, 0x00000001, 0x00002080, 0x00800080,
|
||||
0x00002000, 0x00802080, 0x00802081, 0x00000081,
|
||||
0x00800080, 0x00800001, 0x00802000, 0x00802081,
|
||||
0x00000081, 0x00000000, 0x00000000, 0x00802000,
|
||||
0x00002080, 0x00800080, 0x00800081, 0x00000001,
|
||||
0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
||||
0x00802081, 0x00000081, 0x00000001, 0x00002000,
|
||||
0x00800001, 0x00002001, 0x00802080, 0x00800081,
|
||||
0x00002001, 0x00002080, 0x00800000, 0x00802001,
|
||||
0x00000080, 0x00800000, 0x00002000, 0x00802080
|
||||
};
|
||||
|
||||
static const unsigned long SB5[64] =
|
||||
{
|
||||
0x00000100, 0x02080100, 0x02080000, 0x42000100,
|
||||
0x00080000, 0x00000100, 0x40000000, 0x02080000,
|
||||
0x40080100, 0x00080000, 0x02000100, 0x40080100,
|
||||
0x42000100, 0x42080000, 0x00080100, 0x40000000,
|
||||
0x02000000, 0x40080000, 0x40080000, 0x00000000,
|
||||
0x40000100, 0x42080100, 0x42080100, 0x02000100,
|
||||
0x42080000, 0x40000100, 0x00000000, 0x42000000,
|
||||
0x02080100, 0x02000000, 0x42000000, 0x00080100,
|
||||
0x00080000, 0x42000100, 0x00000100, 0x02000000,
|
||||
0x40000000, 0x02080000, 0x42000100, 0x40080100,
|
||||
0x02000100, 0x40000000, 0x42080000, 0x02080100,
|
||||
0x40080100, 0x00000100, 0x02000000, 0x42080000,
|
||||
0x42080100, 0x00080100, 0x42000000, 0x42080100,
|
||||
0x02080000, 0x00000000, 0x40080000, 0x42000000,
|
||||
0x00080100, 0x02000100, 0x40000100, 0x00080000,
|
||||
0x00000000, 0x40080000, 0x02080100, 0x40000100
|
||||
};
|
||||
|
||||
static const unsigned long SB6[64] =
|
||||
{
|
||||
0x20000010, 0x20400000, 0x00004000, 0x20404010,
|
||||
0x20400000, 0x00000010, 0x20404010, 0x00400000,
|
||||
0x20004000, 0x00404010, 0x00400000, 0x20000010,
|
||||
0x00400010, 0x20004000, 0x20000000, 0x00004010,
|
||||
0x00000000, 0x00400010, 0x20004010, 0x00004000,
|
||||
0x00404000, 0x20004010, 0x00000010, 0x20400010,
|
||||
0x20400010, 0x00000000, 0x00404010, 0x20404000,
|
||||
0x00004010, 0x00404000, 0x20404000, 0x20000000,
|
||||
0x20004000, 0x00000010, 0x20400010, 0x00404000,
|
||||
0x20404010, 0x00400000, 0x00004010, 0x20000010,
|
||||
0x00400000, 0x20004000, 0x20000000, 0x00004010,
|
||||
0x20000010, 0x20404010, 0x00404000, 0x20400000,
|
||||
0x00404010, 0x20404000, 0x00000000, 0x20400010,
|
||||
0x00000010, 0x00004000, 0x20400000, 0x00404010,
|
||||
0x00004000, 0x00400010, 0x20004010, 0x00000000,
|
||||
0x20404000, 0x20000000, 0x00400010, 0x20004010
|
||||
};
|
||||
|
||||
static const unsigned long SB7[64] =
|
||||
{
|
||||
0x00200000, 0x04200002, 0x04000802, 0x00000000,
|
||||
0x00000800, 0x04000802, 0x00200802, 0x04200800,
|
||||
0x04200802, 0x00200000, 0x00000000, 0x04000002,
|
||||
0x00000002, 0x04000000, 0x04200002, 0x00000802,
|
||||
0x04000800, 0x00200802, 0x00200002, 0x04000800,
|
||||
0x04000002, 0x04200000, 0x04200800, 0x00200002,
|
||||
0x04200000, 0x00000800, 0x00000802, 0x04200802,
|
||||
0x00200800, 0x00000002, 0x04000000, 0x00200800,
|
||||
0x04000000, 0x00200800, 0x00200000, 0x04000802,
|
||||
0x04000802, 0x04200002, 0x04200002, 0x00000002,
|
||||
0x00200002, 0x04000000, 0x04000800, 0x00200000,
|
||||
0x04200800, 0x00000802, 0x00200802, 0x04200800,
|
||||
0x00000802, 0x04000002, 0x04200802, 0x04200000,
|
||||
0x00200800, 0x00000000, 0x00000002, 0x04200802,
|
||||
0x00000000, 0x00200802, 0x04200000, 0x00000800,
|
||||
0x04000002, 0x04000800, 0x00000800, 0x00200002
|
||||
};
|
||||
|
||||
static const unsigned long SB8[64] =
|
||||
{
|
||||
0x10001040, 0x00001000, 0x00040000, 0x10041040,
|
||||
0x10000000, 0x10001040, 0x00000040, 0x10000000,
|
||||
0x00040040, 0x10040000, 0x10041040, 0x00041000,
|
||||
0x10041000, 0x00041040, 0x00001000, 0x00000040,
|
||||
0x10040000, 0x10000040, 0x10001000, 0x00001040,
|
||||
0x00041000, 0x00040040, 0x10040040, 0x10041000,
|
||||
0x00001040, 0x00000000, 0x00000000, 0x10040040,
|
||||
0x10000040, 0x10001000, 0x00041040, 0x00040000,
|
||||
0x00041040, 0x00040000, 0x10041000, 0x00001000,
|
||||
0x00000040, 0x10040040, 0x00001000, 0x00041040,
|
||||
0x10001000, 0x00000040, 0x10000040, 0x10040000,
|
||||
0x10040040, 0x10000000, 0x00040000, 0x10001040,
|
||||
0x00000000, 0x10041040, 0x00040040, 0x10000040,
|
||||
0x10040000, 0x10001000, 0x10001040, 0x00000000,
|
||||
0x10041040, 0x00041000, 0x00041000, 0x00001040,
|
||||
0x00001040, 0x00040040, 0x10000000, 0x10041000
|
||||
};
|
||||
|
||||
/*
|
||||
* PC1: left and right halves bit-swap
|
||||
*/
|
||||
static const unsigned long LHs[16] =
|
||||
{
|
||||
0x00000000, 0x00000001, 0x00000100, 0x00000101,
|
||||
0x00010000, 0x00010001, 0x00010100, 0x00010101,
|
||||
0x01000000, 0x01000001, 0x01000100, 0x01000101,
|
||||
0x01010000, 0x01010001, 0x01010100, 0x01010101
|
||||
};
|
||||
|
||||
static const unsigned long RHs[16] =
|
||||
{
|
||||
0x00000000, 0x01000000, 0x00010000, 0x01010000,
|
||||
0x00000100, 0x01000100, 0x00010100, 0x01010100,
|
||||
0x00000001, 0x01000001, 0x00010001, 0x01010001,
|
||||
0x00000101, 0x01000101, 0x00010101, 0x01010101,
|
||||
};
|
||||
|
||||
/*
|
||||
* Initial Permutation macro
|
||||
*/
|
||||
#define DES_IP(X,Y) \
|
||||
{ \
|
||||
T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
|
||||
T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
|
||||
T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
|
||||
T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
|
||||
Y = ((Y << 1) | (Y >> 31)) & 0xFFFFFFFF; \
|
||||
T = (X ^ Y) & 0xAAAAAAAA; Y ^= T; X ^= T; \
|
||||
X = ((X << 1) | (X >> 31)) & 0xFFFFFFFF; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Final Permutation macro
|
||||
*/
|
||||
#define DES_FP(X,Y) \
|
||||
{ \
|
||||
X = ((X << 31) | (X >> 1)) & 0xFFFFFFFF; \
|
||||
T = (X ^ Y) & 0xAAAAAAAA; X ^= T; Y ^= T; \
|
||||
Y = ((Y << 31) | (Y >> 1)) & 0xFFFFFFFF; \
|
||||
T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
|
||||
T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
|
||||
T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
|
||||
T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
|
||||
}
|
||||
|
||||
/*
|
||||
* DES round macro
|
||||
*/
|
||||
#define DES_ROUND(X,Y) \
|
||||
{ \
|
||||
T = *SK++ ^ X; \
|
||||
Y ^= SB8[ (T ) & 0x3F ] ^ \
|
||||
SB6[ (T >> 8) & 0x3F ] ^ \
|
||||
SB4[ (T >> 16) & 0x3F ] ^ \
|
||||
SB2[ (T >> 24) & 0x3F ]; \
|
||||
\
|
||||
T = *SK++ ^ ((X << 28) | (X >> 4)); \
|
||||
Y ^= SB7[ (T ) & 0x3F ] ^ \
|
||||
SB5[ (T >> 8) & 0x3F ] ^ \
|
||||
SB3[ (T >> 16) & 0x3F ] ^ \
|
||||
SB1[ (T >> 24) & 0x3F ]; \
|
||||
}
|
||||
|
||||
#define SWAP(a,b) { unsigned long t = a; a = b; b = t; t = 0; }
|
||||
|
||||
static void des_setkey( unsigned long SK[32], unsigned char key[8] )
|
||||
{
|
||||
int i;
|
||||
unsigned long X, Y, T;
|
||||
|
||||
GET_ULONG_BE( X, key, 0 );
|
||||
GET_ULONG_BE( Y, key, 4 );
|
||||
|
||||
/*
|
||||
* Permuted Choice 1
|
||||
*/
|
||||
T = ((Y >> 4) ^ X) & 0x0F0F0F0F; X ^= T; Y ^= (T << 4);
|
||||
T = ((Y ) ^ X) & 0x10101010; X ^= T; Y ^= (T );
|
||||
|
||||
X = (LHs[ (X ) & 0xF] << 3) | (LHs[ (X >> 8) & 0xF ] << 2)
|
||||
| (LHs[ (X >> 16) & 0xF] << 1) | (LHs[ (X >> 24) & 0xF ] )
|
||||
| (LHs[ (X >> 5) & 0xF] << 7) | (LHs[ (X >> 13) & 0xF ] << 6)
|
||||
| (LHs[ (X >> 21) & 0xF] << 5) | (LHs[ (X >> 29) & 0xF ] << 4);
|
||||
|
||||
Y = (RHs[ (Y >> 1) & 0xF] << 3) | (RHs[ (Y >> 9) & 0xF ] << 2)
|
||||
| (RHs[ (Y >> 17) & 0xF] << 1) | (RHs[ (Y >> 25) & 0xF ] )
|
||||
| (RHs[ (Y >> 4) & 0xF] << 7) | (RHs[ (Y >> 12) & 0xF ] << 6)
|
||||
| (RHs[ (Y >> 20) & 0xF] << 5) | (RHs[ (Y >> 28) & 0xF ] << 4);
|
||||
|
||||
X &= 0x0FFFFFFF;
|
||||
Y &= 0x0FFFFFFF;
|
||||
|
||||
/*
|
||||
* calculate subkeys
|
||||
*/
|
||||
for( i = 0; i < 16; i++ )
|
||||
{
|
||||
if( i < 2 || i == 8 || i == 15 )
|
||||
{
|
||||
X = ((X << 1) | (X >> 27)) & 0x0FFFFFFF;
|
||||
Y = ((Y << 1) | (Y >> 27)) & 0x0FFFFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
X = ((X << 2) | (X >> 26)) & 0x0FFFFFFF;
|
||||
Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF;
|
||||
}
|
||||
|
||||
*SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000)
|
||||
| ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000)
|
||||
| ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000)
|
||||
| ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000)
|
||||
| ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000)
|
||||
| ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000)
|
||||
| ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400)
|
||||
| ((Y >> 14) & 0x00000200) | ((Y ) & 0x00000100)
|
||||
| ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010)
|
||||
| ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004)
|
||||
| ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001);
|
||||
|
||||
*SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000)
|
||||
| ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000)
|
||||
| ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000)
|
||||
| ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000)
|
||||
| ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000)
|
||||
| ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000)
|
||||
| ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000)
|
||||
| ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400)
|
||||
| ((Y ) & 0x00000200) | ((Y << 7) & 0x00000100)
|
||||
| ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011)
|
||||
| ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DES key schedule (56-bit, encryption)
|
||||
*/
|
||||
void des_setkey_enc( des_context *ctx, unsigned char key[8] )
|
||||
{
|
||||
des_setkey( ctx->sk, key );
|
||||
}
|
||||
|
||||
/*
|
||||
* DES key schedule (56-bit, decryption)
|
||||
*/
|
||||
void des_setkey_dec( des_context *ctx, unsigned char key[8] )
|
||||
{
|
||||
int i;
|
||||
|
||||
des_setkey( ctx->sk, key );
|
||||
|
||||
for( i = 0; i < 16; i += 2 )
|
||||
{
|
||||
SWAP( ctx->sk[i ], ctx->sk[30 - i] );
|
||||
SWAP( ctx->sk[i + 1], ctx->sk[31 - i] );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DES-ECB block encryption/decryption
|
||||
*/
|
||||
void des_crypt_ecb( des_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8] )
|
||||
{
|
||||
int i;
|
||||
unsigned long X, Y, T, *SK;
|
||||
|
||||
SK = ctx->sk;
|
||||
|
||||
GET_ULONG_BE( X, input, 0 );
|
||||
GET_ULONG_BE( Y, input, 4 );
|
||||
|
||||
DES_IP( X, Y );
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
DES_ROUND( Y, X );
|
||||
DES_ROUND( X, Y );
|
||||
}
|
||||
|
||||
DES_FP( Y, X );
|
||||
|
||||
PUT_ULONG_BE( Y, output, 0 );
|
||||
PUT_ULONG_BE( X, output, 4 );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES */
|
||||
/*
|
||||
* FIPS-46-3 compliant Triple-DES implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* DES, on which TDES is based, was originally designed by Horst Feistel
|
||||
* at IBM in 1974, and was adopted as a standard by NIST (formerly NBS).
|
||||
*
|
||||
* http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES
|
||||
|
||||
#include "netif/ppp/polarssl/des.h"
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_BE
|
||||
#define GET_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_BE
|
||||
#define PUT_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Expanded DES S-boxes
|
||||
*/
|
||||
static const unsigned long SB1[64] =
|
||||
{
|
||||
0x01010400, 0x00000000, 0x00010000, 0x01010404,
|
||||
0x01010004, 0x00010404, 0x00000004, 0x00010000,
|
||||
0x00000400, 0x01010400, 0x01010404, 0x00000400,
|
||||
0x01000404, 0x01010004, 0x01000000, 0x00000004,
|
||||
0x00000404, 0x01000400, 0x01000400, 0x00010400,
|
||||
0x00010400, 0x01010000, 0x01010000, 0x01000404,
|
||||
0x00010004, 0x01000004, 0x01000004, 0x00010004,
|
||||
0x00000000, 0x00000404, 0x00010404, 0x01000000,
|
||||
0x00010000, 0x01010404, 0x00000004, 0x01010000,
|
||||
0x01010400, 0x01000000, 0x01000000, 0x00000400,
|
||||
0x01010004, 0x00010000, 0x00010400, 0x01000004,
|
||||
0x00000400, 0x00000004, 0x01000404, 0x00010404,
|
||||
0x01010404, 0x00010004, 0x01010000, 0x01000404,
|
||||
0x01000004, 0x00000404, 0x00010404, 0x01010400,
|
||||
0x00000404, 0x01000400, 0x01000400, 0x00000000,
|
||||
0x00010004, 0x00010400, 0x00000000, 0x01010004
|
||||
};
|
||||
|
||||
static const unsigned long SB2[64] =
|
||||
{
|
||||
0x80108020, 0x80008000, 0x00008000, 0x00108020,
|
||||
0x00100000, 0x00000020, 0x80100020, 0x80008020,
|
||||
0x80000020, 0x80108020, 0x80108000, 0x80000000,
|
||||
0x80008000, 0x00100000, 0x00000020, 0x80100020,
|
||||
0x00108000, 0x00100020, 0x80008020, 0x00000000,
|
||||
0x80000000, 0x00008000, 0x00108020, 0x80100000,
|
||||
0x00100020, 0x80000020, 0x00000000, 0x00108000,
|
||||
0x00008020, 0x80108000, 0x80100000, 0x00008020,
|
||||
0x00000000, 0x00108020, 0x80100020, 0x00100000,
|
||||
0x80008020, 0x80100000, 0x80108000, 0x00008000,
|
||||
0x80100000, 0x80008000, 0x00000020, 0x80108020,
|
||||
0x00108020, 0x00000020, 0x00008000, 0x80000000,
|
||||
0x00008020, 0x80108000, 0x00100000, 0x80000020,
|
||||
0x00100020, 0x80008020, 0x80000020, 0x00100020,
|
||||
0x00108000, 0x00000000, 0x80008000, 0x00008020,
|
||||
0x80000000, 0x80100020, 0x80108020, 0x00108000
|
||||
};
|
||||
|
||||
static const unsigned long SB3[64] =
|
||||
{
|
||||
0x00000208, 0x08020200, 0x00000000, 0x08020008,
|
||||
0x08000200, 0x00000000, 0x00020208, 0x08000200,
|
||||
0x00020008, 0x08000008, 0x08000008, 0x00020000,
|
||||
0x08020208, 0x00020008, 0x08020000, 0x00000208,
|
||||
0x08000000, 0x00000008, 0x08020200, 0x00000200,
|
||||
0x00020200, 0x08020000, 0x08020008, 0x00020208,
|
||||
0x08000208, 0x00020200, 0x00020000, 0x08000208,
|
||||
0x00000008, 0x08020208, 0x00000200, 0x08000000,
|
||||
0x08020200, 0x08000000, 0x00020008, 0x00000208,
|
||||
0x00020000, 0x08020200, 0x08000200, 0x00000000,
|
||||
0x00000200, 0x00020008, 0x08020208, 0x08000200,
|
||||
0x08000008, 0x00000200, 0x00000000, 0x08020008,
|
||||
0x08000208, 0x00020000, 0x08000000, 0x08020208,
|
||||
0x00000008, 0x00020208, 0x00020200, 0x08000008,
|
||||
0x08020000, 0x08000208, 0x00000208, 0x08020000,
|
||||
0x00020208, 0x00000008, 0x08020008, 0x00020200
|
||||
};
|
||||
|
||||
static const unsigned long SB4[64] =
|
||||
{
|
||||
0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
||||
0x00802080, 0x00800081, 0x00800001, 0x00002001,
|
||||
0x00000000, 0x00802000, 0x00802000, 0x00802081,
|
||||
0x00000081, 0x00000000, 0x00800080, 0x00800001,
|
||||
0x00000001, 0x00002000, 0x00800000, 0x00802001,
|
||||
0x00000080, 0x00800000, 0x00002001, 0x00002080,
|
||||
0x00800081, 0x00000001, 0x00002080, 0x00800080,
|
||||
0x00002000, 0x00802080, 0x00802081, 0x00000081,
|
||||
0x00800080, 0x00800001, 0x00802000, 0x00802081,
|
||||
0x00000081, 0x00000000, 0x00000000, 0x00802000,
|
||||
0x00002080, 0x00800080, 0x00800081, 0x00000001,
|
||||
0x00802001, 0x00002081, 0x00002081, 0x00000080,
|
||||
0x00802081, 0x00000081, 0x00000001, 0x00002000,
|
||||
0x00800001, 0x00002001, 0x00802080, 0x00800081,
|
||||
0x00002001, 0x00002080, 0x00800000, 0x00802001,
|
||||
0x00000080, 0x00800000, 0x00002000, 0x00802080
|
||||
};
|
||||
|
||||
static const unsigned long SB5[64] =
|
||||
{
|
||||
0x00000100, 0x02080100, 0x02080000, 0x42000100,
|
||||
0x00080000, 0x00000100, 0x40000000, 0x02080000,
|
||||
0x40080100, 0x00080000, 0x02000100, 0x40080100,
|
||||
0x42000100, 0x42080000, 0x00080100, 0x40000000,
|
||||
0x02000000, 0x40080000, 0x40080000, 0x00000000,
|
||||
0x40000100, 0x42080100, 0x42080100, 0x02000100,
|
||||
0x42080000, 0x40000100, 0x00000000, 0x42000000,
|
||||
0x02080100, 0x02000000, 0x42000000, 0x00080100,
|
||||
0x00080000, 0x42000100, 0x00000100, 0x02000000,
|
||||
0x40000000, 0x02080000, 0x42000100, 0x40080100,
|
||||
0x02000100, 0x40000000, 0x42080000, 0x02080100,
|
||||
0x40080100, 0x00000100, 0x02000000, 0x42080000,
|
||||
0x42080100, 0x00080100, 0x42000000, 0x42080100,
|
||||
0x02080000, 0x00000000, 0x40080000, 0x42000000,
|
||||
0x00080100, 0x02000100, 0x40000100, 0x00080000,
|
||||
0x00000000, 0x40080000, 0x02080100, 0x40000100
|
||||
};
|
||||
|
||||
static const unsigned long SB6[64] =
|
||||
{
|
||||
0x20000010, 0x20400000, 0x00004000, 0x20404010,
|
||||
0x20400000, 0x00000010, 0x20404010, 0x00400000,
|
||||
0x20004000, 0x00404010, 0x00400000, 0x20000010,
|
||||
0x00400010, 0x20004000, 0x20000000, 0x00004010,
|
||||
0x00000000, 0x00400010, 0x20004010, 0x00004000,
|
||||
0x00404000, 0x20004010, 0x00000010, 0x20400010,
|
||||
0x20400010, 0x00000000, 0x00404010, 0x20404000,
|
||||
0x00004010, 0x00404000, 0x20404000, 0x20000000,
|
||||
0x20004000, 0x00000010, 0x20400010, 0x00404000,
|
||||
0x20404010, 0x00400000, 0x00004010, 0x20000010,
|
||||
0x00400000, 0x20004000, 0x20000000, 0x00004010,
|
||||
0x20000010, 0x20404010, 0x00404000, 0x20400000,
|
||||
0x00404010, 0x20404000, 0x00000000, 0x20400010,
|
||||
0x00000010, 0x00004000, 0x20400000, 0x00404010,
|
||||
0x00004000, 0x00400010, 0x20004010, 0x00000000,
|
||||
0x20404000, 0x20000000, 0x00400010, 0x20004010
|
||||
};
|
||||
|
||||
static const unsigned long SB7[64] =
|
||||
{
|
||||
0x00200000, 0x04200002, 0x04000802, 0x00000000,
|
||||
0x00000800, 0x04000802, 0x00200802, 0x04200800,
|
||||
0x04200802, 0x00200000, 0x00000000, 0x04000002,
|
||||
0x00000002, 0x04000000, 0x04200002, 0x00000802,
|
||||
0x04000800, 0x00200802, 0x00200002, 0x04000800,
|
||||
0x04000002, 0x04200000, 0x04200800, 0x00200002,
|
||||
0x04200000, 0x00000800, 0x00000802, 0x04200802,
|
||||
0x00200800, 0x00000002, 0x04000000, 0x00200800,
|
||||
0x04000000, 0x00200800, 0x00200000, 0x04000802,
|
||||
0x04000802, 0x04200002, 0x04200002, 0x00000002,
|
||||
0x00200002, 0x04000000, 0x04000800, 0x00200000,
|
||||
0x04200800, 0x00000802, 0x00200802, 0x04200800,
|
||||
0x00000802, 0x04000002, 0x04200802, 0x04200000,
|
||||
0x00200800, 0x00000000, 0x00000002, 0x04200802,
|
||||
0x00000000, 0x00200802, 0x04200000, 0x00000800,
|
||||
0x04000002, 0x04000800, 0x00000800, 0x00200002
|
||||
};
|
||||
|
||||
static const unsigned long SB8[64] =
|
||||
{
|
||||
0x10001040, 0x00001000, 0x00040000, 0x10041040,
|
||||
0x10000000, 0x10001040, 0x00000040, 0x10000000,
|
||||
0x00040040, 0x10040000, 0x10041040, 0x00041000,
|
||||
0x10041000, 0x00041040, 0x00001000, 0x00000040,
|
||||
0x10040000, 0x10000040, 0x10001000, 0x00001040,
|
||||
0x00041000, 0x00040040, 0x10040040, 0x10041000,
|
||||
0x00001040, 0x00000000, 0x00000000, 0x10040040,
|
||||
0x10000040, 0x10001000, 0x00041040, 0x00040000,
|
||||
0x00041040, 0x00040000, 0x10041000, 0x00001000,
|
||||
0x00000040, 0x10040040, 0x00001000, 0x00041040,
|
||||
0x10001000, 0x00000040, 0x10000040, 0x10040000,
|
||||
0x10040040, 0x10000000, 0x00040000, 0x10001040,
|
||||
0x00000000, 0x10041040, 0x00040040, 0x10000040,
|
||||
0x10040000, 0x10001000, 0x10001040, 0x00000000,
|
||||
0x10041040, 0x00041000, 0x00041000, 0x00001040,
|
||||
0x00001040, 0x00040040, 0x10000000, 0x10041000
|
||||
};
|
||||
|
||||
/*
|
||||
* PC1: left and right halves bit-swap
|
||||
*/
|
||||
static const unsigned long LHs[16] =
|
||||
{
|
||||
0x00000000, 0x00000001, 0x00000100, 0x00000101,
|
||||
0x00010000, 0x00010001, 0x00010100, 0x00010101,
|
||||
0x01000000, 0x01000001, 0x01000100, 0x01000101,
|
||||
0x01010000, 0x01010001, 0x01010100, 0x01010101
|
||||
};
|
||||
|
||||
static const unsigned long RHs[16] =
|
||||
{
|
||||
0x00000000, 0x01000000, 0x00010000, 0x01010000,
|
||||
0x00000100, 0x01000100, 0x00010100, 0x01010100,
|
||||
0x00000001, 0x01000001, 0x00010001, 0x01010001,
|
||||
0x00000101, 0x01000101, 0x00010101, 0x01010101,
|
||||
};
|
||||
|
||||
/*
|
||||
* Initial Permutation macro
|
||||
*/
|
||||
#define DES_IP(X,Y) \
|
||||
{ \
|
||||
T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
|
||||
T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
|
||||
T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
|
||||
T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
|
||||
Y = ((Y << 1) | (Y >> 31)) & 0xFFFFFFFF; \
|
||||
T = (X ^ Y) & 0xAAAAAAAA; Y ^= T; X ^= T; \
|
||||
X = ((X << 1) | (X >> 31)) & 0xFFFFFFFF; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Final Permutation macro
|
||||
*/
|
||||
#define DES_FP(X,Y) \
|
||||
{ \
|
||||
X = ((X << 31) | (X >> 1)) & 0xFFFFFFFF; \
|
||||
T = (X ^ Y) & 0xAAAAAAAA; X ^= T; Y ^= T; \
|
||||
Y = ((Y << 31) | (Y >> 1)) & 0xFFFFFFFF; \
|
||||
T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \
|
||||
T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \
|
||||
T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \
|
||||
T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \
|
||||
}
|
||||
|
||||
/*
|
||||
* DES round macro
|
||||
*/
|
||||
#define DES_ROUND(X,Y) \
|
||||
{ \
|
||||
T = *SK++ ^ X; \
|
||||
Y ^= SB8[ (T ) & 0x3F ] ^ \
|
||||
SB6[ (T >> 8) & 0x3F ] ^ \
|
||||
SB4[ (T >> 16) & 0x3F ] ^ \
|
||||
SB2[ (T >> 24) & 0x3F ]; \
|
||||
\
|
||||
T = *SK++ ^ ((X << 28) | (X >> 4)); \
|
||||
Y ^= SB7[ (T ) & 0x3F ] ^ \
|
||||
SB5[ (T >> 8) & 0x3F ] ^ \
|
||||
SB3[ (T >> 16) & 0x3F ] ^ \
|
||||
SB1[ (T >> 24) & 0x3F ]; \
|
||||
}
|
||||
|
||||
#define SWAP(a,b) { unsigned long t = a; a = b; b = t; t = 0; }
|
||||
|
||||
static void des_setkey( unsigned long SK[32], unsigned char key[8] )
|
||||
{
|
||||
int i;
|
||||
unsigned long X, Y, T;
|
||||
|
||||
GET_ULONG_BE( X, key, 0 );
|
||||
GET_ULONG_BE( Y, key, 4 );
|
||||
|
||||
/*
|
||||
* Permuted Choice 1
|
||||
*/
|
||||
T = ((Y >> 4) ^ X) & 0x0F0F0F0F; X ^= T; Y ^= (T << 4);
|
||||
T = ((Y ) ^ X) & 0x10101010; X ^= T; Y ^= (T );
|
||||
|
||||
X = (LHs[ (X ) & 0xF] << 3) | (LHs[ (X >> 8) & 0xF ] << 2)
|
||||
| (LHs[ (X >> 16) & 0xF] << 1) | (LHs[ (X >> 24) & 0xF ] )
|
||||
| (LHs[ (X >> 5) & 0xF] << 7) | (LHs[ (X >> 13) & 0xF ] << 6)
|
||||
| (LHs[ (X >> 21) & 0xF] << 5) | (LHs[ (X >> 29) & 0xF ] << 4);
|
||||
|
||||
Y = (RHs[ (Y >> 1) & 0xF] << 3) | (RHs[ (Y >> 9) & 0xF ] << 2)
|
||||
| (RHs[ (Y >> 17) & 0xF] << 1) | (RHs[ (Y >> 25) & 0xF ] )
|
||||
| (RHs[ (Y >> 4) & 0xF] << 7) | (RHs[ (Y >> 12) & 0xF ] << 6)
|
||||
| (RHs[ (Y >> 20) & 0xF] << 5) | (RHs[ (Y >> 28) & 0xF ] << 4);
|
||||
|
||||
X &= 0x0FFFFFFF;
|
||||
Y &= 0x0FFFFFFF;
|
||||
|
||||
/*
|
||||
* calculate subkeys
|
||||
*/
|
||||
for( i = 0; i < 16; i++ )
|
||||
{
|
||||
if( i < 2 || i == 8 || i == 15 )
|
||||
{
|
||||
X = ((X << 1) | (X >> 27)) & 0x0FFFFFFF;
|
||||
Y = ((Y << 1) | (Y >> 27)) & 0x0FFFFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
X = ((X << 2) | (X >> 26)) & 0x0FFFFFFF;
|
||||
Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF;
|
||||
}
|
||||
|
||||
*SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000)
|
||||
| ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000)
|
||||
| ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000)
|
||||
| ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000)
|
||||
| ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000)
|
||||
| ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000)
|
||||
| ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400)
|
||||
| ((Y >> 14) & 0x00000200) | ((Y ) & 0x00000100)
|
||||
| ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010)
|
||||
| ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004)
|
||||
| ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001);
|
||||
|
||||
*SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000)
|
||||
| ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000)
|
||||
| ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000)
|
||||
| ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000)
|
||||
| ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000)
|
||||
| ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000)
|
||||
| ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000)
|
||||
| ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400)
|
||||
| ((Y ) & 0x00000200) | ((Y << 7) & 0x00000100)
|
||||
| ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011)
|
||||
| ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DES key schedule (56-bit, encryption)
|
||||
*/
|
||||
void des_setkey_enc( des_context *ctx, unsigned char key[8] )
|
||||
{
|
||||
des_setkey( ctx->sk, key );
|
||||
}
|
||||
|
||||
/*
|
||||
* DES key schedule (56-bit, decryption)
|
||||
*/
|
||||
void des_setkey_dec( des_context *ctx, unsigned char key[8] )
|
||||
{
|
||||
int i;
|
||||
|
||||
des_setkey( ctx->sk, key );
|
||||
|
||||
for( i = 0; i < 16; i += 2 )
|
||||
{
|
||||
SWAP( ctx->sk[i ], ctx->sk[30 - i] );
|
||||
SWAP( ctx->sk[i + 1], ctx->sk[31 - i] );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DES-ECB block encryption/decryption
|
||||
*/
|
||||
void des_crypt_ecb( des_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8] )
|
||||
{
|
||||
int i;
|
||||
unsigned long X, Y, T, *SK;
|
||||
|
||||
SK = ctx->sk;
|
||||
|
||||
GET_ULONG_BE( X, input, 0 );
|
||||
GET_ULONG_BE( Y, input, 4 );
|
||||
|
||||
DES_IP( X, Y );
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
DES_ROUND( Y, X );
|
||||
DES_ROUND( X, Y );
|
||||
}
|
||||
|
||||
DES_FP( Y, X );
|
||||
|
||||
PUT_ULONG_BE( Y, output, 0 );
|
||||
PUT_ULONG_BE( X, output, 4 );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES */
|
||||
|
||||
562
ext/lwip/src/netif/ppp/polarssl/md4.c
Normal file → Executable file
562
ext/lwip/src/netif/ppp/polarssl/md4.c
Normal file → Executable file
@@ -1,281 +1,281 @@
|
||||
/*
|
||||
* RFC 1186/1320 compliant MD4 implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The MD4 algorithm was designed by Ron Rivest in 1990.
|
||||
*
|
||||
* http://www.ietf.org/rfc/rfc1186.txt
|
||||
* http://www.ietf.org/rfc/rfc1320.txt
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD4
|
||||
|
||||
#include "netif/ppp/polarssl/md4.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_LE
|
||||
#define GET_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] << 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_LE
|
||||
#define PUT_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MD4 context setup
|
||||
*/
|
||||
void md4_starts( md4_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
static void md4_process( md4_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
unsigned long X[16], A, B, C, D;
|
||||
|
||||
GET_ULONG_LE( X[ 0], data, 0 );
|
||||
GET_ULONG_LE( X[ 1], data, 4 );
|
||||
GET_ULONG_LE( X[ 2], data, 8 );
|
||||
GET_ULONG_LE( X[ 3], data, 12 );
|
||||
GET_ULONG_LE( X[ 4], data, 16 );
|
||||
GET_ULONG_LE( X[ 5], data, 20 );
|
||||
GET_ULONG_LE( X[ 6], data, 24 );
|
||||
GET_ULONG_LE( X[ 7], data, 28 );
|
||||
GET_ULONG_LE( X[ 8], data, 32 );
|
||||
GET_ULONG_LE( X[ 9], data, 36 );
|
||||
GET_ULONG_LE( X[10], data, 40 );
|
||||
GET_ULONG_LE( X[11], data, 44 );
|
||||
GET_ULONG_LE( X[12], data, 48 );
|
||||
GET_ULONG_LE( X[13], data, 52 );
|
||||
GET_ULONG_LE( X[14], data, 56 );
|
||||
GET_ULONG_LE( X[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
|
||||
#define F(x, y, z) ((x & y) | ((~x) & z))
|
||||
#define P(a,b,c,d,x,s) { a += F(b,c,d) + x; a = S(a,s); }
|
||||
|
||||
P( A, B, C, D, X[ 0], 3 );
|
||||
P( D, A, B, C, X[ 1], 7 );
|
||||
P( C, D, A, B, X[ 2], 11 );
|
||||
P( B, C, D, A, X[ 3], 19 );
|
||||
P( A, B, C, D, X[ 4], 3 );
|
||||
P( D, A, B, C, X[ 5], 7 );
|
||||
P( C, D, A, B, X[ 6], 11 );
|
||||
P( B, C, D, A, X[ 7], 19 );
|
||||
P( A, B, C, D, X[ 8], 3 );
|
||||
P( D, A, B, C, X[ 9], 7 );
|
||||
P( C, D, A, B, X[10], 11 );
|
||||
P( B, C, D, A, X[11], 19 );
|
||||
P( A, B, C, D, X[12], 3 );
|
||||
P( D, A, B, C, X[13], 7 );
|
||||
P( C, D, A, B, X[14], 11 );
|
||||
P( B, C, D, A, X[15], 19 );
|
||||
|
||||
#undef P
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) ((x & y) | (x & z) | (y & z))
|
||||
#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x5A827999; a = S(a,s); }
|
||||
|
||||
P( A, B, C, D, X[ 0], 3 );
|
||||
P( D, A, B, C, X[ 4], 5 );
|
||||
P( C, D, A, B, X[ 8], 9 );
|
||||
P( B, C, D, A, X[12], 13 );
|
||||
P( A, B, C, D, X[ 1], 3 );
|
||||
P( D, A, B, C, X[ 5], 5 );
|
||||
P( C, D, A, B, X[ 9], 9 );
|
||||
P( B, C, D, A, X[13], 13 );
|
||||
P( A, B, C, D, X[ 2], 3 );
|
||||
P( D, A, B, C, X[ 6], 5 );
|
||||
P( C, D, A, B, X[10], 9 );
|
||||
P( B, C, D, A, X[14], 13 );
|
||||
P( A, B, C, D, X[ 3], 3 );
|
||||
P( D, A, B, C, X[ 7], 5 );
|
||||
P( C, D, A, B, X[11], 9 );
|
||||
P( B, C, D, A, X[15], 13 );
|
||||
|
||||
#undef P
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x6ED9EBA1; a = S(a,s); }
|
||||
|
||||
P( A, B, C, D, X[ 0], 3 );
|
||||
P( D, A, B, C, X[ 8], 9 );
|
||||
P( C, D, A, B, X[ 4], 11 );
|
||||
P( B, C, D, A, X[12], 15 );
|
||||
P( A, B, C, D, X[ 2], 3 );
|
||||
P( D, A, B, C, X[10], 9 );
|
||||
P( C, D, A, B, X[ 6], 11 );
|
||||
P( B, C, D, A, X[14], 15 );
|
||||
P( A, B, C, D, X[ 1], 3 );
|
||||
P( D, A, B, C, X[ 9], 9 );
|
||||
P( C, D, A, B, X[ 5], 11 );
|
||||
P( B, C, D, A, X[13], 15 );
|
||||
P( A, B, C, D, X[ 3], 3 );
|
||||
P( D, A, B, C, X[11], 9 );
|
||||
P( C, D, A, B, X[ 7], 11 );
|
||||
P( B, C, D, A, X[15], 15 );
|
||||
|
||||
#undef F
|
||||
#undef P
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD4 process buffer
|
||||
*/
|
||||
void md4_update( md4_context *ctx, const unsigned char *input, int ilen )
|
||||
{
|
||||
int fill;
|
||||
unsigned long left;
|
||||
|
||||
if( ilen <= 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (unsigned long) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, fill );
|
||||
md4_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
md4_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char md4_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* MD4 final digest
|
||||
*/
|
||||
void md4_finish( md4_context *ctx, unsigned char output[16] )
|
||||
{
|
||||
unsigned long last, padn;
|
||||
unsigned long high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_ULONG_LE( low, msglen, 0 );
|
||||
PUT_ULONG_LE( high, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
md4_update( ctx, md4_padding, padn );
|
||||
md4_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_ULONG_LE( ctx->state[0], output, 0 );
|
||||
PUT_ULONG_LE( ctx->state[1], output, 4 );
|
||||
PUT_ULONG_LE( ctx->state[2], output, 8 );
|
||||
PUT_ULONG_LE( ctx->state[3], output, 12 );
|
||||
}
|
||||
|
||||
/*
|
||||
* output = MD4( input buffer )
|
||||
*/
|
||||
void md4( unsigned char *input, int ilen, unsigned char output[16] )
|
||||
{
|
||||
md4_context ctx;
|
||||
|
||||
md4_starts( &ctx );
|
||||
md4_update( &ctx, input, ilen );
|
||||
md4_finish( &ctx, output );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD4 */
|
||||
/*
|
||||
* RFC 1186/1320 compliant MD4 implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The MD4 algorithm was designed by Ron Rivest in 1990.
|
||||
*
|
||||
* http://www.ietf.org/rfc/rfc1186.txt
|
||||
* http://www.ietf.org/rfc/rfc1320.txt
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD4
|
||||
|
||||
#include "netif/ppp/polarssl/md4.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_LE
|
||||
#define GET_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] << 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_LE
|
||||
#define PUT_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MD4 context setup
|
||||
*/
|
||||
void md4_starts( md4_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
static void md4_process( md4_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
unsigned long X[16], A, B, C, D;
|
||||
|
||||
GET_ULONG_LE( X[ 0], data, 0 );
|
||||
GET_ULONG_LE( X[ 1], data, 4 );
|
||||
GET_ULONG_LE( X[ 2], data, 8 );
|
||||
GET_ULONG_LE( X[ 3], data, 12 );
|
||||
GET_ULONG_LE( X[ 4], data, 16 );
|
||||
GET_ULONG_LE( X[ 5], data, 20 );
|
||||
GET_ULONG_LE( X[ 6], data, 24 );
|
||||
GET_ULONG_LE( X[ 7], data, 28 );
|
||||
GET_ULONG_LE( X[ 8], data, 32 );
|
||||
GET_ULONG_LE( X[ 9], data, 36 );
|
||||
GET_ULONG_LE( X[10], data, 40 );
|
||||
GET_ULONG_LE( X[11], data, 44 );
|
||||
GET_ULONG_LE( X[12], data, 48 );
|
||||
GET_ULONG_LE( X[13], data, 52 );
|
||||
GET_ULONG_LE( X[14], data, 56 );
|
||||
GET_ULONG_LE( X[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
|
||||
#define F(x, y, z) ((x & y) | ((~x) & z))
|
||||
#define P(a,b,c,d,x,s) { a += F(b,c,d) + x; a = S(a,s); }
|
||||
|
||||
P( A, B, C, D, X[ 0], 3 );
|
||||
P( D, A, B, C, X[ 1], 7 );
|
||||
P( C, D, A, B, X[ 2], 11 );
|
||||
P( B, C, D, A, X[ 3], 19 );
|
||||
P( A, B, C, D, X[ 4], 3 );
|
||||
P( D, A, B, C, X[ 5], 7 );
|
||||
P( C, D, A, B, X[ 6], 11 );
|
||||
P( B, C, D, A, X[ 7], 19 );
|
||||
P( A, B, C, D, X[ 8], 3 );
|
||||
P( D, A, B, C, X[ 9], 7 );
|
||||
P( C, D, A, B, X[10], 11 );
|
||||
P( B, C, D, A, X[11], 19 );
|
||||
P( A, B, C, D, X[12], 3 );
|
||||
P( D, A, B, C, X[13], 7 );
|
||||
P( C, D, A, B, X[14], 11 );
|
||||
P( B, C, D, A, X[15], 19 );
|
||||
|
||||
#undef P
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) ((x & y) | (x & z) | (y & z))
|
||||
#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x5A827999; a = S(a,s); }
|
||||
|
||||
P( A, B, C, D, X[ 0], 3 );
|
||||
P( D, A, B, C, X[ 4], 5 );
|
||||
P( C, D, A, B, X[ 8], 9 );
|
||||
P( B, C, D, A, X[12], 13 );
|
||||
P( A, B, C, D, X[ 1], 3 );
|
||||
P( D, A, B, C, X[ 5], 5 );
|
||||
P( C, D, A, B, X[ 9], 9 );
|
||||
P( B, C, D, A, X[13], 13 );
|
||||
P( A, B, C, D, X[ 2], 3 );
|
||||
P( D, A, B, C, X[ 6], 5 );
|
||||
P( C, D, A, B, X[10], 9 );
|
||||
P( B, C, D, A, X[14], 13 );
|
||||
P( A, B, C, D, X[ 3], 3 );
|
||||
P( D, A, B, C, X[ 7], 5 );
|
||||
P( C, D, A, B, X[11], 9 );
|
||||
P( B, C, D, A, X[15], 13 );
|
||||
|
||||
#undef P
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x6ED9EBA1; a = S(a,s); }
|
||||
|
||||
P( A, B, C, D, X[ 0], 3 );
|
||||
P( D, A, B, C, X[ 8], 9 );
|
||||
P( C, D, A, B, X[ 4], 11 );
|
||||
P( B, C, D, A, X[12], 15 );
|
||||
P( A, B, C, D, X[ 2], 3 );
|
||||
P( D, A, B, C, X[10], 9 );
|
||||
P( C, D, A, B, X[ 6], 11 );
|
||||
P( B, C, D, A, X[14], 15 );
|
||||
P( A, B, C, D, X[ 1], 3 );
|
||||
P( D, A, B, C, X[ 9], 9 );
|
||||
P( C, D, A, B, X[ 5], 11 );
|
||||
P( B, C, D, A, X[13], 15 );
|
||||
P( A, B, C, D, X[ 3], 3 );
|
||||
P( D, A, B, C, X[11], 9 );
|
||||
P( C, D, A, B, X[ 7], 11 );
|
||||
P( B, C, D, A, X[15], 15 );
|
||||
|
||||
#undef F
|
||||
#undef P
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD4 process buffer
|
||||
*/
|
||||
void md4_update( md4_context *ctx, const unsigned char *input, int ilen )
|
||||
{
|
||||
int fill;
|
||||
unsigned long left;
|
||||
|
||||
if( ilen <= 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (unsigned long) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, fill );
|
||||
md4_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
md4_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char md4_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* MD4 final digest
|
||||
*/
|
||||
void md4_finish( md4_context *ctx, unsigned char output[16] )
|
||||
{
|
||||
unsigned long last, padn;
|
||||
unsigned long high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_ULONG_LE( low, msglen, 0 );
|
||||
PUT_ULONG_LE( high, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
md4_update( ctx, md4_padding, padn );
|
||||
md4_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_ULONG_LE( ctx->state[0], output, 0 );
|
||||
PUT_ULONG_LE( ctx->state[1], output, 4 );
|
||||
PUT_ULONG_LE( ctx->state[2], output, 8 );
|
||||
PUT_ULONG_LE( ctx->state[3], output, 12 );
|
||||
}
|
||||
|
||||
/*
|
||||
* output = MD4( input buffer )
|
||||
*/
|
||||
void md4( unsigned char *input, int ilen, unsigned char output[16] )
|
||||
{
|
||||
md4_context ctx;
|
||||
|
||||
md4_starts( &ctx );
|
||||
md4_update( &ctx, input, ilen );
|
||||
md4_finish( &ctx, output );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD4 */
|
||||
|
||||
600
ext/lwip/src/netif/ppp/polarssl/md5.c
Normal file → Executable file
600
ext/lwip/src/netif/ppp/polarssl/md5.c
Normal file → Executable file
@@ -1,300 +1,300 @@
|
||||
/*
|
||||
* RFC 1321 compliant MD5 implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The MD5 algorithm was designed by Ron Rivest in 1991.
|
||||
*
|
||||
* http://www.ietf.org/rfc/rfc1321.txt
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD5
|
||||
|
||||
#include "netif/ppp/polarssl/md5.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_LE
|
||||
#define GET_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] << 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_LE
|
||||
#define PUT_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MD5 context setup
|
||||
*/
|
||||
void md5_starts( md5_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
static void md5_process( md5_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
unsigned long X[16], A, B, C, D;
|
||||
|
||||
GET_ULONG_LE( X[ 0], data, 0 );
|
||||
GET_ULONG_LE( X[ 1], data, 4 );
|
||||
GET_ULONG_LE( X[ 2], data, 8 );
|
||||
GET_ULONG_LE( X[ 3], data, 12 );
|
||||
GET_ULONG_LE( X[ 4], data, 16 );
|
||||
GET_ULONG_LE( X[ 5], data, 20 );
|
||||
GET_ULONG_LE( X[ 6], data, 24 );
|
||||
GET_ULONG_LE( X[ 7], data, 28 );
|
||||
GET_ULONG_LE( X[ 8], data, 32 );
|
||||
GET_ULONG_LE( X[ 9], data, 36 );
|
||||
GET_ULONG_LE( X[10], data, 40 );
|
||||
GET_ULONG_LE( X[11], data, 44 );
|
||||
GET_ULONG_LE( X[12], data, 48 );
|
||||
GET_ULONG_LE( X[13], data, 52 );
|
||||
GET_ULONG_LE( X[14], data, 56 );
|
||||
GET_ULONG_LE( X[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define P(a,b,c,d,k,s,t) \
|
||||
{ \
|
||||
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
|
||||
P( A, B, C, D, 0, 7, 0xD76AA478 );
|
||||
P( D, A, B, C, 1, 12, 0xE8C7B756 );
|
||||
P( C, D, A, B, 2, 17, 0x242070DB );
|
||||
P( B, C, D, A, 3, 22, 0xC1BDCEEE );
|
||||
P( A, B, C, D, 4, 7, 0xF57C0FAF );
|
||||
P( D, A, B, C, 5, 12, 0x4787C62A );
|
||||
P( C, D, A, B, 6, 17, 0xA8304613 );
|
||||
P( B, C, D, A, 7, 22, 0xFD469501 );
|
||||
P( A, B, C, D, 8, 7, 0x698098D8 );
|
||||
P( D, A, B, C, 9, 12, 0x8B44F7AF );
|
||||
P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
|
||||
P( B, C, D, A, 11, 22, 0x895CD7BE );
|
||||
P( A, B, C, D, 12, 7, 0x6B901122 );
|
||||
P( D, A, B, C, 13, 12, 0xFD987193 );
|
||||
P( C, D, A, B, 14, 17, 0xA679438E );
|
||||
P( B, C, D, A, 15, 22, 0x49B40821 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (z & (x ^ y)))
|
||||
|
||||
P( A, B, C, D, 1, 5, 0xF61E2562 );
|
||||
P( D, A, B, C, 6, 9, 0xC040B340 );
|
||||
P( C, D, A, B, 11, 14, 0x265E5A51 );
|
||||
P( B, C, D, A, 0, 20, 0xE9B6C7AA );
|
||||
P( A, B, C, D, 5, 5, 0xD62F105D );
|
||||
P( D, A, B, C, 10, 9, 0x02441453 );
|
||||
P( C, D, A, B, 15, 14, 0xD8A1E681 );
|
||||
P( B, C, D, A, 4, 20, 0xE7D3FBC8 );
|
||||
P( A, B, C, D, 9, 5, 0x21E1CDE6 );
|
||||
P( D, A, B, C, 14, 9, 0xC33707D6 );
|
||||
P( C, D, A, B, 3, 14, 0xF4D50D87 );
|
||||
P( B, C, D, A, 8, 20, 0x455A14ED );
|
||||
P( A, B, C, D, 13, 5, 0xA9E3E905 );
|
||||
P( D, A, B, C, 2, 9, 0xFCEFA3F8 );
|
||||
P( C, D, A, B, 7, 14, 0x676F02D9 );
|
||||
P( B, C, D, A, 12, 20, 0x8D2A4C8A );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
|
||||
P( A, B, C, D, 5, 4, 0xFFFA3942 );
|
||||
P( D, A, B, C, 8, 11, 0x8771F681 );
|
||||
P( C, D, A, B, 11, 16, 0x6D9D6122 );
|
||||
P( B, C, D, A, 14, 23, 0xFDE5380C );
|
||||
P( A, B, C, D, 1, 4, 0xA4BEEA44 );
|
||||
P( D, A, B, C, 4, 11, 0x4BDECFA9 );
|
||||
P( C, D, A, B, 7, 16, 0xF6BB4B60 );
|
||||
P( B, C, D, A, 10, 23, 0xBEBFBC70 );
|
||||
P( A, B, C, D, 13, 4, 0x289B7EC6 );
|
||||
P( D, A, B, C, 0, 11, 0xEAA127FA );
|
||||
P( C, D, A, B, 3, 16, 0xD4EF3085 );
|
||||
P( B, C, D, A, 6, 23, 0x04881D05 );
|
||||
P( A, B, C, D, 9, 4, 0xD9D4D039 );
|
||||
P( D, A, B, C, 12, 11, 0xE6DB99E5 );
|
||||
P( C, D, A, B, 15, 16, 0x1FA27CF8 );
|
||||
P( B, C, D, A, 2, 23, 0xC4AC5665 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (x | ~z))
|
||||
|
||||
P( A, B, C, D, 0, 6, 0xF4292244 );
|
||||
P( D, A, B, C, 7, 10, 0x432AFF97 );
|
||||
P( C, D, A, B, 14, 15, 0xAB9423A7 );
|
||||
P( B, C, D, A, 5, 21, 0xFC93A039 );
|
||||
P( A, B, C, D, 12, 6, 0x655B59C3 );
|
||||
P( D, A, B, C, 3, 10, 0x8F0CCC92 );
|
||||
P( C, D, A, B, 10, 15, 0xFFEFF47D );
|
||||
P( B, C, D, A, 1, 21, 0x85845DD1 );
|
||||
P( A, B, C, D, 8, 6, 0x6FA87E4F );
|
||||
P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
|
||||
P( C, D, A, B, 6, 15, 0xA3014314 );
|
||||
P( B, C, D, A, 13, 21, 0x4E0811A1 );
|
||||
P( A, B, C, D, 4, 6, 0xF7537E82 );
|
||||
P( D, A, B, C, 11, 10, 0xBD3AF235 );
|
||||
P( C, D, A, B, 2, 15, 0x2AD7D2BB );
|
||||
P( B, C, D, A, 9, 21, 0xEB86D391 );
|
||||
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 process buffer
|
||||
*/
|
||||
void md5_update( md5_context *ctx, const unsigned char *input, int ilen )
|
||||
{
|
||||
int fill;
|
||||
unsigned long left;
|
||||
|
||||
if( ilen <= 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (unsigned long) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, fill );
|
||||
md5_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
md5_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char md5_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* MD5 final digest
|
||||
*/
|
||||
void md5_finish( md5_context *ctx, unsigned char output[16] )
|
||||
{
|
||||
unsigned long last, padn;
|
||||
unsigned long high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_ULONG_LE( low, msglen, 0 );
|
||||
PUT_ULONG_LE( high, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
md5_update( ctx, md5_padding, padn );
|
||||
md5_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_ULONG_LE( ctx->state[0], output, 0 );
|
||||
PUT_ULONG_LE( ctx->state[1], output, 4 );
|
||||
PUT_ULONG_LE( ctx->state[2], output, 8 );
|
||||
PUT_ULONG_LE( ctx->state[3], output, 12 );
|
||||
}
|
||||
|
||||
/*
|
||||
* output = MD5( input buffer )
|
||||
*/
|
||||
void md5( unsigned char *input, int ilen, unsigned char output[16] )
|
||||
{
|
||||
md5_context ctx;
|
||||
|
||||
md5_starts( &ctx );
|
||||
md5_update( &ctx, input, ilen );
|
||||
md5_finish( &ctx, output );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD5 */
|
||||
/*
|
||||
* RFC 1321 compliant MD5 implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The MD5 algorithm was designed by Ron Rivest in 1991.
|
||||
*
|
||||
* http://www.ietf.org/rfc/rfc1321.txt
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD5
|
||||
|
||||
#include "netif/ppp/polarssl/md5.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_LE
|
||||
#define GET_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] << 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_LE
|
||||
#define PUT_ULONG_LE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MD5 context setup
|
||||
*/
|
||||
void md5_starts( md5_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
static void md5_process( md5_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
unsigned long X[16], A, B, C, D;
|
||||
|
||||
GET_ULONG_LE( X[ 0], data, 0 );
|
||||
GET_ULONG_LE( X[ 1], data, 4 );
|
||||
GET_ULONG_LE( X[ 2], data, 8 );
|
||||
GET_ULONG_LE( X[ 3], data, 12 );
|
||||
GET_ULONG_LE( X[ 4], data, 16 );
|
||||
GET_ULONG_LE( X[ 5], data, 20 );
|
||||
GET_ULONG_LE( X[ 6], data, 24 );
|
||||
GET_ULONG_LE( X[ 7], data, 28 );
|
||||
GET_ULONG_LE( X[ 8], data, 32 );
|
||||
GET_ULONG_LE( X[ 9], data, 36 );
|
||||
GET_ULONG_LE( X[10], data, 40 );
|
||||
GET_ULONG_LE( X[11], data, 44 );
|
||||
GET_ULONG_LE( X[12], data, 48 );
|
||||
GET_ULONG_LE( X[13], data, 52 );
|
||||
GET_ULONG_LE( X[14], data, 56 );
|
||||
GET_ULONG_LE( X[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define P(a,b,c,d,k,s,t) \
|
||||
{ \
|
||||
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
|
||||
P( A, B, C, D, 0, 7, 0xD76AA478 );
|
||||
P( D, A, B, C, 1, 12, 0xE8C7B756 );
|
||||
P( C, D, A, B, 2, 17, 0x242070DB );
|
||||
P( B, C, D, A, 3, 22, 0xC1BDCEEE );
|
||||
P( A, B, C, D, 4, 7, 0xF57C0FAF );
|
||||
P( D, A, B, C, 5, 12, 0x4787C62A );
|
||||
P( C, D, A, B, 6, 17, 0xA8304613 );
|
||||
P( B, C, D, A, 7, 22, 0xFD469501 );
|
||||
P( A, B, C, D, 8, 7, 0x698098D8 );
|
||||
P( D, A, B, C, 9, 12, 0x8B44F7AF );
|
||||
P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
|
||||
P( B, C, D, A, 11, 22, 0x895CD7BE );
|
||||
P( A, B, C, D, 12, 7, 0x6B901122 );
|
||||
P( D, A, B, C, 13, 12, 0xFD987193 );
|
||||
P( C, D, A, B, 14, 17, 0xA679438E );
|
||||
P( B, C, D, A, 15, 22, 0x49B40821 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (z & (x ^ y)))
|
||||
|
||||
P( A, B, C, D, 1, 5, 0xF61E2562 );
|
||||
P( D, A, B, C, 6, 9, 0xC040B340 );
|
||||
P( C, D, A, B, 11, 14, 0x265E5A51 );
|
||||
P( B, C, D, A, 0, 20, 0xE9B6C7AA );
|
||||
P( A, B, C, D, 5, 5, 0xD62F105D );
|
||||
P( D, A, B, C, 10, 9, 0x02441453 );
|
||||
P( C, D, A, B, 15, 14, 0xD8A1E681 );
|
||||
P( B, C, D, A, 4, 20, 0xE7D3FBC8 );
|
||||
P( A, B, C, D, 9, 5, 0x21E1CDE6 );
|
||||
P( D, A, B, C, 14, 9, 0xC33707D6 );
|
||||
P( C, D, A, B, 3, 14, 0xF4D50D87 );
|
||||
P( B, C, D, A, 8, 20, 0x455A14ED );
|
||||
P( A, B, C, D, 13, 5, 0xA9E3E905 );
|
||||
P( D, A, B, C, 2, 9, 0xFCEFA3F8 );
|
||||
P( C, D, A, B, 7, 14, 0x676F02D9 );
|
||||
P( B, C, D, A, 12, 20, 0x8D2A4C8A );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
|
||||
P( A, B, C, D, 5, 4, 0xFFFA3942 );
|
||||
P( D, A, B, C, 8, 11, 0x8771F681 );
|
||||
P( C, D, A, B, 11, 16, 0x6D9D6122 );
|
||||
P( B, C, D, A, 14, 23, 0xFDE5380C );
|
||||
P( A, B, C, D, 1, 4, 0xA4BEEA44 );
|
||||
P( D, A, B, C, 4, 11, 0x4BDECFA9 );
|
||||
P( C, D, A, B, 7, 16, 0xF6BB4B60 );
|
||||
P( B, C, D, A, 10, 23, 0xBEBFBC70 );
|
||||
P( A, B, C, D, 13, 4, 0x289B7EC6 );
|
||||
P( D, A, B, C, 0, 11, 0xEAA127FA );
|
||||
P( C, D, A, B, 3, 16, 0xD4EF3085 );
|
||||
P( B, C, D, A, 6, 23, 0x04881D05 );
|
||||
P( A, B, C, D, 9, 4, 0xD9D4D039 );
|
||||
P( D, A, B, C, 12, 11, 0xE6DB99E5 );
|
||||
P( C, D, A, B, 15, 16, 0x1FA27CF8 );
|
||||
P( B, C, D, A, 2, 23, 0xC4AC5665 );
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (x | ~z))
|
||||
|
||||
P( A, B, C, D, 0, 6, 0xF4292244 );
|
||||
P( D, A, B, C, 7, 10, 0x432AFF97 );
|
||||
P( C, D, A, B, 14, 15, 0xAB9423A7 );
|
||||
P( B, C, D, A, 5, 21, 0xFC93A039 );
|
||||
P( A, B, C, D, 12, 6, 0x655B59C3 );
|
||||
P( D, A, B, C, 3, 10, 0x8F0CCC92 );
|
||||
P( C, D, A, B, 10, 15, 0xFFEFF47D );
|
||||
P( B, C, D, A, 1, 21, 0x85845DD1 );
|
||||
P( A, B, C, D, 8, 6, 0x6FA87E4F );
|
||||
P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
|
||||
P( C, D, A, B, 6, 15, 0xA3014314 );
|
||||
P( B, C, D, A, 13, 21, 0x4E0811A1 );
|
||||
P( A, B, C, D, 4, 6, 0xF7537E82 );
|
||||
P( D, A, B, C, 11, 10, 0xBD3AF235 );
|
||||
P( C, D, A, B, 2, 15, 0x2AD7D2BB );
|
||||
P( B, C, D, A, 9, 21, 0xEB86D391 );
|
||||
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 process buffer
|
||||
*/
|
||||
void md5_update( md5_context *ctx, const unsigned char *input, int ilen )
|
||||
{
|
||||
int fill;
|
||||
unsigned long left;
|
||||
|
||||
if( ilen <= 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (unsigned long) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, fill );
|
||||
md5_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
md5_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char md5_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* MD5 final digest
|
||||
*/
|
||||
void md5_finish( md5_context *ctx, unsigned char output[16] )
|
||||
{
|
||||
unsigned long last, padn;
|
||||
unsigned long high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_ULONG_LE( low, msglen, 0 );
|
||||
PUT_ULONG_LE( high, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
md5_update( ctx, md5_padding, padn );
|
||||
md5_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_ULONG_LE( ctx->state[0], output, 0 );
|
||||
PUT_ULONG_LE( ctx->state[1], output, 4 );
|
||||
PUT_ULONG_LE( ctx->state[2], output, 8 );
|
||||
PUT_ULONG_LE( ctx->state[3], output, 12 );
|
||||
}
|
||||
|
||||
/*
|
||||
* output = MD5( input buffer )
|
||||
*/
|
||||
void md5( unsigned char *input, int ilen, unsigned char output[16] )
|
||||
{
|
||||
md5_context ctx;
|
||||
|
||||
md5_starts( &ctx );
|
||||
md5_update( &ctx, input, ilen );
|
||||
md5_finish( &ctx, output );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD5 */
|
||||
|
||||
670
ext/lwip/src/netif/ppp/polarssl/sha1.c
Normal file → Executable file
670
ext/lwip/src/netif/ppp/polarssl/sha1.c
Normal file → Executable file
@@ -1,335 +1,335 @@
|
||||
/*
|
||||
* FIPS-180-1 compliant SHA-1 implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The SHA-1 standard was published by NIST in 1993.
|
||||
*
|
||||
* http://www.itl.nist.gov/fipspubs/fip180-1.htm
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_SHA1
|
||||
|
||||
#include "netif/ppp/polarssl/sha1.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_BE
|
||||
#define GET_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_BE
|
||||
#define PUT_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SHA-1 context setup
|
||||
*/
|
||||
void sha1_starts( sha1_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
ctx->state[4] = 0xC3D2E1F0;
|
||||
}
|
||||
|
||||
static void sha1_process( sha1_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
unsigned long temp, W[16], A, B, C, D, E;
|
||||
|
||||
GET_ULONG_BE( W[ 0], data, 0 );
|
||||
GET_ULONG_BE( W[ 1], data, 4 );
|
||||
GET_ULONG_BE( W[ 2], data, 8 );
|
||||
GET_ULONG_BE( W[ 3], data, 12 );
|
||||
GET_ULONG_BE( W[ 4], data, 16 );
|
||||
GET_ULONG_BE( W[ 5], data, 20 );
|
||||
GET_ULONG_BE( W[ 6], data, 24 );
|
||||
GET_ULONG_BE( W[ 7], data, 28 );
|
||||
GET_ULONG_BE( W[ 8], data, 32 );
|
||||
GET_ULONG_BE( W[ 9], data, 36 );
|
||||
GET_ULONG_BE( W[10], data, 40 );
|
||||
GET_ULONG_BE( W[11], data, 44 );
|
||||
GET_ULONG_BE( W[12], data, 48 );
|
||||
GET_ULONG_BE( W[13], data, 52 );
|
||||
GET_ULONG_BE( W[14], data, 56 );
|
||||
GET_ULONG_BE( W[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define R(t) \
|
||||
( \
|
||||
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
|
||||
W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \
|
||||
( W[t & 0x0F] = S(temp,1) ) \
|
||||
)
|
||||
|
||||
#define P(a,b,c,d,e,x) \
|
||||
{ \
|
||||
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
E = ctx->state[4];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
#define K 0x5A827999
|
||||
|
||||
P( A, B, C, D, E, W[0] );
|
||||
P( E, A, B, C, D, W[1] );
|
||||
P( D, E, A, B, C, W[2] );
|
||||
P( C, D, E, A, B, W[3] );
|
||||
P( B, C, D, E, A, W[4] );
|
||||
P( A, B, C, D, E, W[5] );
|
||||
P( E, A, B, C, D, W[6] );
|
||||
P( D, E, A, B, C, W[7] );
|
||||
P( C, D, E, A, B, W[8] );
|
||||
P( B, C, D, E, A, W[9] );
|
||||
P( A, B, C, D, E, W[10] );
|
||||
P( E, A, B, C, D, W[11] );
|
||||
P( D, E, A, B, C, W[12] );
|
||||
P( C, D, E, A, B, W[13] );
|
||||
P( B, C, D, E, A, W[14] );
|
||||
P( A, B, C, D, E, W[15] );
|
||||
P( E, A, B, C, D, R(16) );
|
||||
P( D, E, A, B, C, R(17) );
|
||||
P( C, D, E, A, B, R(18) );
|
||||
P( B, C, D, E, A, R(19) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0x6ED9EBA1
|
||||
|
||||
P( A, B, C, D, E, R(20) );
|
||||
P( E, A, B, C, D, R(21) );
|
||||
P( D, E, A, B, C, R(22) );
|
||||
P( C, D, E, A, B, R(23) );
|
||||
P( B, C, D, E, A, R(24) );
|
||||
P( A, B, C, D, E, R(25) );
|
||||
P( E, A, B, C, D, R(26) );
|
||||
P( D, E, A, B, C, R(27) );
|
||||
P( C, D, E, A, B, R(28) );
|
||||
P( B, C, D, E, A, R(29) );
|
||||
P( A, B, C, D, E, R(30) );
|
||||
P( E, A, B, C, D, R(31) );
|
||||
P( D, E, A, B, C, R(32) );
|
||||
P( C, D, E, A, B, R(33) );
|
||||
P( B, C, D, E, A, R(34) );
|
||||
P( A, B, C, D, E, R(35) );
|
||||
P( E, A, B, C, D, R(36) );
|
||||
P( D, E, A, B, C, R(37) );
|
||||
P( C, D, E, A, B, R(38) );
|
||||
P( B, C, D, E, A, R(39) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) ((x & y) | (z & (x | y)))
|
||||
#define K 0x8F1BBCDC
|
||||
|
||||
P( A, B, C, D, E, R(40) );
|
||||
P( E, A, B, C, D, R(41) );
|
||||
P( D, E, A, B, C, R(42) );
|
||||
P( C, D, E, A, B, R(43) );
|
||||
P( B, C, D, E, A, R(44) );
|
||||
P( A, B, C, D, E, R(45) );
|
||||
P( E, A, B, C, D, R(46) );
|
||||
P( D, E, A, B, C, R(47) );
|
||||
P( C, D, E, A, B, R(48) );
|
||||
P( B, C, D, E, A, R(49) );
|
||||
P( A, B, C, D, E, R(50) );
|
||||
P( E, A, B, C, D, R(51) );
|
||||
P( D, E, A, B, C, R(52) );
|
||||
P( C, D, E, A, B, R(53) );
|
||||
P( B, C, D, E, A, R(54) );
|
||||
P( A, B, C, D, E, R(55) );
|
||||
P( E, A, B, C, D, R(56) );
|
||||
P( D, E, A, B, C, R(57) );
|
||||
P( C, D, E, A, B, R(58) );
|
||||
P( B, C, D, E, A, R(59) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0xCA62C1D6
|
||||
|
||||
P( A, B, C, D, E, R(60) );
|
||||
P( E, A, B, C, D, R(61) );
|
||||
P( D, E, A, B, C, R(62) );
|
||||
P( C, D, E, A, B, R(63) );
|
||||
P( B, C, D, E, A, R(64) );
|
||||
P( A, B, C, D, E, R(65) );
|
||||
P( E, A, B, C, D, R(66) );
|
||||
P( D, E, A, B, C, R(67) );
|
||||
P( C, D, E, A, B, R(68) );
|
||||
P( B, C, D, E, A, R(69) );
|
||||
P( A, B, C, D, E, R(70) );
|
||||
P( E, A, B, C, D, R(71) );
|
||||
P( D, E, A, B, C, R(72) );
|
||||
P( C, D, E, A, B, R(73) );
|
||||
P( B, C, D, E, A, R(74) );
|
||||
P( A, B, C, D, E, R(75) );
|
||||
P( E, A, B, C, D, R(76) );
|
||||
P( D, E, A, B, C, R(77) );
|
||||
P( C, D, E, A, B, R(78) );
|
||||
P( B, C, D, E, A, R(79) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
ctx->state[4] += E;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-1 process buffer
|
||||
*/
|
||||
void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )
|
||||
{
|
||||
int fill;
|
||||
unsigned long left;
|
||||
|
||||
if( ilen <= 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (unsigned long) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, fill );
|
||||
sha1_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
sha1_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char sha1_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* SHA-1 final digest
|
||||
*/
|
||||
void sha1_finish( sha1_context *ctx, unsigned char output[20] )
|
||||
{
|
||||
unsigned long last, padn;
|
||||
unsigned long high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_ULONG_BE( high, msglen, 0 );
|
||||
PUT_ULONG_BE( low, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
sha1_update( ctx, sha1_padding, padn );
|
||||
sha1_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_ULONG_BE( ctx->state[0], output, 0 );
|
||||
PUT_ULONG_BE( ctx->state[1], output, 4 );
|
||||
PUT_ULONG_BE( ctx->state[2], output, 8 );
|
||||
PUT_ULONG_BE( ctx->state[3], output, 12 );
|
||||
PUT_ULONG_BE( ctx->state[4], output, 16 );
|
||||
}
|
||||
|
||||
/*
|
||||
* output = SHA-1( input buffer )
|
||||
*/
|
||||
void sha1( unsigned char *input, int ilen, unsigned char output[20] )
|
||||
{
|
||||
sha1_context ctx;
|
||||
|
||||
sha1_starts( &ctx );
|
||||
sha1_update( &ctx, input, ilen );
|
||||
sha1_finish( &ctx, output );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_SHA1 */
|
||||
/*
|
||||
* FIPS-180-1 compliant SHA-1 implementation
|
||||
*
|
||||
* Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
|
||||
*
|
||||
* Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * Neither the names of PolarSSL or XySSL nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
/*
|
||||
* The SHA-1 standard was published by NIST in 1993.
|
||||
*
|
||||
* http://www.itl.nist.gov/fipspubs/fip180-1.htm
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_SHA1
|
||||
|
||||
#include "netif/ppp/polarssl/sha1.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef GET_ULONG_BE
|
||||
#define GET_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (unsigned long) (b)[(i) ] << 24 ) \
|
||||
| ( (unsigned long) (b)[(i) + 1] << 16 ) \
|
||||
| ( (unsigned long) (b)[(i) + 2] << 8 ) \
|
||||
| ( (unsigned long) (b)[(i) + 3] ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_ULONG_BE
|
||||
#define PUT_ULONG_BE(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SHA-1 context setup
|
||||
*/
|
||||
void sha1_starts( sha1_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
ctx->state[4] = 0xC3D2E1F0;
|
||||
}
|
||||
|
||||
static void sha1_process( sha1_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
unsigned long temp, W[16], A, B, C, D, E;
|
||||
|
||||
GET_ULONG_BE( W[ 0], data, 0 );
|
||||
GET_ULONG_BE( W[ 1], data, 4 );
|
||||
GET_ULONG_BE( W[ 2], data, 8 );
|
||||
GET_ULONG_BE( W[ 3], data, 12 );
|
||||
GET_ULONG_BE( W[ 4], data, 16 );
|
||||
GET_ULONG_BE( W[ 5], data, 20 );
|
||||
GET_ULONG_BE( W[ 6], data, 24 );
|
||||
GET_ULONG_BE( W[ 7], data, 28 );
|
||||
GET_ULONG_BE( W[ 8], data, 32 );
|
||||
GET_ULONG_BE( W[ 9], data, 36 );
|
||||
GET_ULONG_BE( W[10], data, 40 );
|
||||
GET_ULONG_BE( W[11], data, 44 );
|
||||
GET_ULONG_BE( W[12], data, 48 );
|
||||
GET_ULONG_BE( W[13], data, 52 );
|
||||
GET_ULONG_BE( W[14], data, 56 );
|
||||
GET_ULONG_BE( W[15], data, 60 );
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define R(t) \
|
||||
( \
|
||||
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
|
||||
W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \
|
||||
( W[t & 0x0F] = S(temp,1) ) \
|
||||
)
|
||||
|
||||
#define P(a,b,c,d,e,x) \
|
||||
{ \
|
||||
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
E = ctx->state[4];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
#define K 0x5A827999
|
||||
|
||||
P( A, B, C, D, E, W[0] );
|
||||
P( E, A, B, C, D, W[1] );
|
||||
P( D, E, A, B, C, W[2] );
|
||||
P( C, D, E, A, B, W[3] );
|
||||
P( B, C, D, E, A, W[4] );
|
||||
P( A, B, C, D, E, W[5] );
|
||||
P( E, A, B, C, D, W[6] );
|
||||
P( D, E, A, B, C, W[7] );
|
||||
P( C, D, E, A, B, W[8] );
|
||||
P( B, C, D, E, A, W[9] );
|
||||
P( A, B, C, D, E, W[10] );
|
||||
P( E, A, B, C, D, W[11] );
|
||||
P( D, E, A, B, C, W[12] );
|
||||
P( C, D, E, A, B, W[13] );
|
||||
P( B, C, D, E, A, W[14] );
|
||||
P( A, B, C, D, E, W[15] );
|
||||
P( E, A, B, C, D, R(16) );
|
||||
P( D, E, A, B, C, R(17) );
|
||||
P( C, D, E, A, B, R(18) );
|
||||
P( B, C, D, E, A, R(19) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0x6ED9EBA1
|
||||
|
||||
P( A, B, C, D, E, R(20) );
|
||||
P( E, A, B, C, D, R(21) );
|
||||
P( D, E, A, B, C, R(22) );
|
||||
P( C, D, E, A, B, R(23) );
|
||||
P( B, C, D, E, A, R(24) );
|
||||
P( A, B, C, D, E, R(25) );
|
||||
P( E, A, B, C, D, R(26) );
|
||||
P( D, E, A, B, C, R(27) );
|
||||
P( C, D, E, A, B, R(28) );
|
||||
P( B, C, D, E, A, R(29) );
|
||||
P( A, B, C, D, E, R(30) );
|
||||
P( E, A, B, C, D, R(31) );
|
||||
P( D, E, A, B, C, R(32) );
|
||||
P( C, D, E, A, B, R(33) );
|
||||
P( B, C, D, E, A, R(34) );
|
||||
P( A, B, C, D, E, R(35) );
|
||||
P( E, A, B, C, D, R(36) );
|
||||
P( D, E, A, B, C, R(37) );
|
||||
P( C, D, E, A, B, R(38) );
|
||||
P( B, C, D, E, A, R(39) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) ((x & y) | (z & (x | y)))
|
||||
#define K 0x8F1BBCDC
|
||||
|
||||
P( A, B, C, D, E, R(40) );
|
||||
P( E, A, B, C, D, R(41) );
|
||||
P( D, E, A, B, C, R(42) );
|
||||
P( C, D, E, A, B, R(43) );
|
||||
P( B, C, D, E, A, R(44) );
|
||||
P( A, B, C, D, E, R(45) );
|
||||
P( E, A, B, C, D, R(46) );
|
||||
P( D, E, A, B, C, R(47) );
|
||||
P( C, D, E, A, B, R(48) );
|
||||
P( B, C, D, E, A, R(49) );
|
||||
P( A, B, C, D, E, R(50) );
|
||||
P( E, A, B, C, D, R(51) );
|
||||
P( D, E, A, B, C, R(52) );
|
||||
P( C, D, E, A, B, R(53) );
|
||||
P( B, C, D, E, A, R(54) );
|
||||
P( A, B, C, D, E, R(55) );
|
||||
P( E, A, B, C, D, R(56) );
|
||||
P( D, E, A, B, C, R(57) );
|
||||
P( C, D, E, A, B, R(58) );
|
||||
P( B, C, D, E, A, R(59) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define K 0xCA62C1D6
|
||||
|
||||
P( A, B, C, D, E, R(60) );
|
||||
P( E, A, B, C, D, R(61) );
|
||||
P( D, E, A, B, C, R(62) );
|
||||
P( C, D, E, A, B, R(63) );
|
||||
P( B, C, D, E, A, R(64) );
|
||||
P( A, B, C, D, E, R(65) );
|
||||
P( E, A, B, C, D, R(66) );
|
||||
P( D, E, A, B, C, R(67) );
|
||||
P( C, D, E, A, B, R(68) );
|
||||
P( B, C, D, E, A, R(69) );
|
||||
P( A, B, C, D, E, R(70) );
|
||||
P( E, A, B, C, D, R(71) );
|
||||
P( D, E, A, B, C, R(72) );
|
||||
P( C, D, E, A, B, R(73) );
|
||||
P( B, C, D, E, A, R(74) );
|
||||
P( A, B, C, D, E, R(75) );
|
||||
P( E, A, B, C, D, R(76) );
|
||||
P( D, E, A, B, C, R(77) );
|
||||
P( C, D, E, A, B, R(78) );
|
||||
P( B, C, D, E, A, R(79) );
|
||||
|
||||
#undef K
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
ctx->state[4] += E;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-1 process buffer
|
||||
*/
|
||||
void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )
|
||||
{
|
||||
int fill;
|
||||
unsigned long left;
|
||||
|
||||
if( ilen <= 0 )
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (unsigned long) ilen )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, fill );
|
||||
sha1_process( ctx, ctx->buffer );
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
sha1_process( ctx, input );
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
MEMCPY( (void *) (ctx->buffer + left),
|
||||
input, ilen );
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char sha1_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* SHA-1 final digest
|
||||
*/
|
||||
void sha1_finish( sha1_context *ctx, unsigned char output[20] )
|
||||
{
|
||||
unsigned long last, padn;
|
||||
unsigned long high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_ULONG_BE( high, msglen, 0 );
|
||||
PUT_ULONG_BE( low, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
sha1_update( ctx, sha1_padding, padn );
|
||||
sha1_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_ULONG_BE( ctx->state[0], output, 0 );
|
||||
PUT_ULONG_BE( ctx->state[1], output, 4 );
|
||||
PUT_ULONG_BE( ctx->state[2], output, 8 );
|
||||
PUT_ULONG_BE( ctx->state[3], output, 12 );
|
||||
PUT_ULONG_BE( ctx->state[4], output, 16 );
|
||||
}
|
||||
|
||||
/*
|
||||
* output = SHA-1( input buffer )
|
||||
*/
|
||||
void sha1( unsigned char *input, int ilen, unsigned char output[20] )
|
||||
{
|
||||
sha1_context ctx;
|
||||
|
||||
sha1_starts( &ctx );
|
||||
sha1_update( &ctx, input, ilen );
|
||||
sha1_finish( &ctx, output );
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_SHA1 */
|
||||
|
||||
3287
ext/lwip/src/netif/ppp/ppp.c
Normal file → Executable file
3287
ext/lwip/src/netif/ppp/ppp.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
849
ext/lwip/src/netif/ppp/pppapi.c
Normal file → Executable file
849
ext/lwip/src/netif/ppp/pppapi.c
Normal file → Executable file
@@ -1,422 +1,427 @@
|
||||
/**
|
||||
* @file
|
||||
* Point To Point Protocol Sequential API module
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
|
||||
#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "netif/ppp/pppapi.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#include "netif/ppp/pppol2tp.h"
|
||||
#include "netif/ppp/pppos.h"
|
||||
|
||||
#if LWIP_MPU_COMPATIBLE
|
||||
LWIP_MEMPOOL_DECLARE(PPPAPI_MSG, MEMP_NUM_PPP_API_MSG, sizeof(struct pppapi_msg), "PPPAPI_MSG")
|
||||
#endif
|
||||
|
||||
#define PPPAPI_VAR_REF(name) API_VAR_REF(name)
|
||||
#define PPPAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct pppapi_msg, name)
|
||||
#define PPPAPI_VAR_ALLOC(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, ERR_MEM)
|
||||
#define PPPAPI_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, NULL)
|
||||
#define PPPAPI_VAR_FREE(name) API_VAR_FREE_POOL(PPPAPI_MSG, name)
|
||||
|
||||
/**
|
||||
* Call ppp_set_default() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_set_default(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
ppp_set_default(msg->msg.ppp);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_set_default() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_set_default(ppp_pcb *pcb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_set_default, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
#if PPP_NOTIFY_PHASE
|
||||
/**
|
||||
* Call ppp_set_notify_phase_callback() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
#endif /* PPP_NOTIFY_PHASE */
|
||||
|
||||
|
||||
#if PPPOS_SUPPORT
|
||||
/**
|
||||
* Call pppos_create() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_pppos_create(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
msg->msg.ppp = pppos_create(msg->msg.msg.serialcreate.pppif, msg->msg.msg.serialcreate.output_cb,
|
||||
msg->msg.msg.serialcreate.link_status_cb, msg->msg.msg.serialcreate.ctx_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call pppos_create() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
ppp_pcb*
|
||||
pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
|
||||
ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
|
||||
{
|
||||
ppp_pcb* result;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = NULL;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.pppif = pppif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.output_cb = output_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.link_status_cb = link_status_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.ctx_cb = ctx_cb;
|
||||
tcpip_api_call(pppapi_do_pppos_create, &PPPAPI_VAR_REF(msg).call);
|
||||
result = PPPAPI_VAR_REF(msg).msg.ppp;
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return result;
|
||||
}
|
||||
#endif /* PPPOS_SUPPORT */
|
||||
|
||||
|
||||
#if PPPOE_SUPPORT
|
||||
/**
|
||||
* Call pppoe_create() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_pppoe_create(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif,
|
||||
msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name,
|
||||
msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call pppoe_create() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
ppp_pcb*
|
||||
pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name,
|
||||
const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
|
||||
void *ctx_cb)
|
||||
{
|
||||
ppp_pcb* result;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = NULL;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.pppif = pppif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ethif = ethif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.service_name = service_name;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.concentrator_name = concentrator_name;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.link_status_cb = link_status_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ctx_cb = ctx_cb;
|
||||
tcpip_api_call(pppapi_do_pppoe_create, &PPPAPI_VAR_REF(msg).call);
|
||||
result = PPPAPI_VAR_REF(msg).msg.ppp;
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return result;
|
||||
}
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
|
||||
#if PPPOL2TP_SUPPORT
|
||||
/**
|
||||
* Call pppol2tp_create() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_pppol2tp_create(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif,
|
||||
msg->msg.msg.l2tpcreate.netif, API_EXPR_REF(msg->msg.msg.l2tpcreate.ipaddr), msg->msg.msg.l2tpcreate.port,
|
||||
#if PPPOL2TP_AUTH_SUPPORT
|
||||
msg->msg.msg.l2tpcreate.secret,
|
||||
msg->msg.msg.l2tpcreate.secret_len,
|
||||
#else /* PPPOL2TP_AUTH_SUPPORT */
|
||||
NULL,
|
||||
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
||||
msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call pppol2tp_create() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
ppp_pcb*
|
||||
pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
|
||||
const u8_t *secret, u8_t secret_len,
|
||||
ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
|
||||
{
|
||||
ppp_pcb* result;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = NULL;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.pppif = pppif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.netif = netif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ipaddr = PPPAPI_VAR_REF(ipaddr);
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.port = port;
|
||||
#if PPPOL2TP_AUTH_SUPPORT
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret = secret;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret_len = secret_len;
|
||||
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.link_status_cb = link_status_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ctx_cb = ctx_cb;
|
||||
tcpip_api_call(pppapi_do_pppol2tp_create, &PPPAPI_VAR_REF(msg).call);
|
||||
result = PPPAPI_VAR_REF(msg).msg.ppp;
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return result;
|
||||
}
|
||||
#endif /* PPPOL2TP_SUPPORT */
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_connect() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_connect(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_connect(msg->msg.ppp, msg->msg.msg.connect.holdoff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_connect() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_connect(ppp_pcb *pcb, u16_t holdoff)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.connect.holdoff = holdoff;
|
||||
err = tcpip_api_call(pppapi_do_ppp_connect, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
#if PPP_SERVER
|
||||
/**
|
||||
* Call ppp_listen() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_listen(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_listen(msg->msg.ppp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_listen() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_listen(ppp_pcb *pcb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_listen, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
#endif /* PPP_SERVER */
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_close() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_close(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_close(msg->msg.ppp, msg->msg.msg.close.nocarrier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_close() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.close.nocarrier = nocarrier;
|
||||
err = tcpip_api_call(pppapi_do_ppp_close, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_free() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_free(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_free(msg->msg.ppp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_free() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_free(ppp_pcb *pcb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_free, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_ioctl() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_ioctl(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_ioctl(msg->msg.ppp, msg->msg.msg.ioctl.cmd, msg->msg.msg.ioctl.arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_ioctl() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ioctl.cmd = cmd;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ioctl.arg = arg;
|
||||
err = tcpip_api_call(pppapi_do_ppp_ioctl, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif /* LWIP_PPP_API */
|
||||
/**
|
||||
* @file
|
||||
* Point To Point Protocol Sequential API module
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
|
||||
#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "netif/ppp/pppapi.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#include "netif/ppp/pppol2tp.h"
|
||||
#include "netif/ppp/pppos.h"
|
||||
|
||||
#if LWIP_MPU_COMPATIBLE
|
||||
LWIP_MEMPOOL_DECLARE(PPPAPI_MSG, MEMP_NUM_PPP_API_MSG, sizeof(struct pppapi_msg), "PPPAPI_MSG")
|
||||
#endif
|
||||
|
||||
#define PPPAPI_VAR_REF(name) API_VAR_REF(name)
|
||||
#define PPPAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct pppapi_msg, name)
|
||||
#define PPPAPI_VAR_ALLOC(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, ERR_MEM)
|
||||
#define PPPAPI_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC_POOL(struct pppapi_msg, PPPAPI_MSG, name, NULL)
|
||||
#define PPPAPI_VAR_FREE(name) API_VAR_FREE_POOL(PPPAPI_MSG, name)
|
||||
|
||||
/**
|
||||
* Call ppp_set_default() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_set_default(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
ppp_set_default(msg->msg.ppp);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_set_default() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_set_default(ppp_pcb *pcb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_set_default, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
#if PPP_NOTIFY_PHASE
|
||||
/**
|
||||
* Call ppp_set_notify_phase_callback() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_set_notify_phase_callback(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
ppp_set_notify_phase_callback(msg->msg.ppp, msg->msg.msg.setnotifyphasecb.notify_phase_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_set_notify_phase_callback, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
#endif /* PPP_NOTIFY_PHASE */
|
||||
|
||||
|
||||
#if PPPOS_SUPPORT
|
||||
/**
|
||||
* Call pppos_create() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_pppos_create(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
msg->msg.ppp = pppos_create(msg->msg.msg.serialcreate.pppif, msg->msg.msg.serialcreate.output_cb,
|
||||
msg->msg.msg.serialcreate.link_status_cb, msg->msg.msg.serialcreate.ctx_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call pppos_create() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
ppp_pcb*
|
||||
pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
|
||||
ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
|
||||
{
|
||||
ppp_pcb* result;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = NULL;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.pppif = pppif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.output_cb = output_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.link_status_cb = link_status_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.serialcreate.ctx_cb = ctx_cb;
|
||||
tcpip_api_call(pppapi_do_pppos_create, &PPPAPI_VAR_REF(msg).call);
|
||||
result = PPPAPI_VAR_REF(msg).msg.ppp;
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return result;
|
||||
}
|
||||
#endif /* PPPOS_SUPPORT */
|
||||
|
||||
|
||||
#if PPPOE_SUPPORT
|
||||
/**
|
||||
* Call pppoe_create() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_pppoe_create(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
msg->msg.ppp = pppoe_create(msg->msg.msg.ethernetcreate.pppif, msg->msg.msg.ethernetcreate.ethif,
|
||||
msg->msg.msg.ethernetcreate.service_name, msg->msg.msg.ethernetcreate.concentrator_name,
|
||||
msg->msg.msg.ethernetcreate.link_status_cb, msg->msg.msg.ethernetcreate.ctx_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call pppoe_create() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
ppp_pcb*
|
||||
pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name,
|
||||
const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
|
||||
void *ctx_cb)
|
||||
{
|
||||
ppp_pcb* result;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = NULL;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.pppif = pppif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ethif = ethif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.service_name = service_name;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.concentrator_name = concentrator_name;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.link_status_cb = link_status_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ethernetcreate.ctx_cb = ctx_cb;
|
||||
tcpip_api_call(pppapi_do_pppoe_create, &PPPAPI_VAR_REF(msg).call);
|
||||
result = PPPAPI_VAR_REF(msg).msg.ppp;
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return result;
|
||||
}
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
|
||||
#if PPPOL2TP_SUPPORT
|
||||
/**
|
||||
* Call pppol2tp_create() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_pppol2tp_create(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
msg->msg.ppp = pppol2tp_create(msg->msg.msg.l2tpcreate.pppif,
|
||||
msg->msg.msg.l2tpcreate.netif, API_EXPR_REF(msg->msg.msg.l2tpcreate.ipaddr), msg->msg.msg.l2tpcreate.port,
|
||||
#if PPPOL2TP_AUTH_SUPPORT
|
||||
msg->msg.msg.l2tpcreate.secret,
|
||||
msg->msg.msg.l2tpcreate.secret_len,
|
||||
#else /* PPPOL2TP_AUTH_SUPPORT */
|
||||
NULL,
|
||||
0,
|
||||
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
||||
msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call pppol2tp_create() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
ppp_pcb*
|
||||
pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
|
||||
const u8_t *secret, u8_t secret_len,
|
||||
ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
|
||||
{
|
||||
ppp_pcb* result;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
|
||||
#if !PPPOL2TP_AUTH_SUPPORT
|
||||
LWIP_UNUSED_ARG(secret);
|
||||
LWIP_UNUSED_ARG(secret_len);
|
||||
#endif /* !PPPOL2TP_AUTH_SUPPORT */
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = NULL;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.pppif = pppif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.netif = netif;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ipaddr = PPPAPI_VAR_REF(ipaddr);
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.port = port;
|
||||
#if PPPOL2TP_AUTH_SUPPORT
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret = secret;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.secret_len = secret_len;
|
||||
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.link_status_cb = link_status_cb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.ctx_cb = ctx_cb;
|
||||
tcpip_api_call(pppapi_do_pppol2tp_create, &PPPAPI_VAR_REF(msg).call);
|
||||
result = PPPAPI_VAR_REF(msg).msg.ppp;
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return result;
|
||||
}
|
||||
#endif /* PPPOL2TP_SUPPORT */
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_connect() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_connect(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_connect(msg->msg.ppp, msg->msg.msg.connect.holdoff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_connect() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_connect(ppp_pcb *pcb, u16_t holdoff)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.connect.holdoff = holdoff;
|
||||
err = tcpip_api_call(pppapi_do_ppp_connect, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
#if PPP_SERVER
|
||||
/**
|
||||
* Call ppp_listen() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_listen(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_listen(msg->msg.ppp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_listen() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_listen(ppp_pcb *pcb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_listen, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
#endif /* PPP_SERVER */
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_close() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_close(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_close(msg->msg.ppp, msg->msg.msg.close.nocarrier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_close() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_close(ppp_pcb *pcb, u8_t nocarrier)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.close.nocarrier = nocarrier;
|
||||
err = tcpip_api_call(pppapi_do_ppp_close, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_free() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_free(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_free(msg->msg.ppp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_free() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_free(ppp_pcb *pcb)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
err = tcpip_api_call(pppapi_do_ppp_free, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call ppp_ioctl() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t
|
||||
pppapi_do_ppp_ioctl(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct pppapi_msg */
|
||||
struct pppapi_msg *msg = (struct pppapi_msg *)(void*)m;
|
||||
|
||||
return ppp_ioctl(msg->msg.ppp, msg->msg.msg.ioctl.cmd, msg->msg.msg.ioctl.arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call ppp_ioctl() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
err_t
|
||||
pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg)
|
||||
{
|
||||
err_t err;
|
||||
PPPAPI_VAR_DECLARE(msg);
|
||||
PPPAPI_VAR_ALLOC(msg);
|
||||
|
||||
PPPAPI_VAR_REF(msg).msg.ppp = pcb;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ioctl.cmd = cmd;
|
||||
PPPAPI_VAR_REF(msg).msg.msg.ioctl.arg = arg;
|
||||
err = tcpip_api_call(pppapi_do_ppp_ioctl, &PPPAPI_VAR_REF(msg).call);
|
||||
PPPAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif /* LWIP_PPP_API */
|
||||
|
||||
132
ext/lwip/src/netif/ppp/pppcrypt.c
Normal file → Executable file
132
ext/lwip/src/netif/ppp/pppcrypt.c
Normal file → Executable file
@@ -1,66 +1,66 @@
|
||||
/*
|
||||
* pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
|
||||
*
|
||||
* Extracted from chap_ms.c by James Carlson.
|
||||
*
|
||||
* Copyright (c) 1995 Eric Rosenquist. 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(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not necessary */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
|
||||
static u_char pppcrypt_get_7bits(u_char *input, int startBit) {
|
||||
unsigned int word;
|
||||
|
||||
word = (unsigned)input[startBit / 8] << 8;
|
||||
word |= (unsigned)input[startBit / 8 + 1];
|
||||
|
||||
word >>= 15 - (startBit % 8 + 7);
|
||||
|
||||
return word & 0xFE;
|
||||
}
|
||||
|
||||
/* IN 56 bit DES key missing parity bits
|
||||
* OUT 64 bit DES key with parity bits added
|
||||
*/
|
||||
void pppcrypt_56_to_64_bit_key(u_char *key, u_char * des_key) {
|
||||
des_key[0] = pppcrypt_get_7bits(key, 0);
|
||||
des_key[1] = pppcrypt_get_7bits(key, 7);
|
||||
des_key[2] = pppcrypt_get_7bits(key, 14);
|
||||
des_key[3] = pppcrypt_get_7bits(key, 21);
|
||||
des_key[4] = pppcrypt_get_7bits(key, 28);
|
||||
des_key[5] = pppcrypt_get_7bits(key, 35);
|
||||
des_key[6] = pppcrypt_get_7bits(key, 42);
|
||||
des_key[7] = pppcrypt_get_7bits(key, 49);
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && MSCHAP_SUPPORT */
|
||||
/*
|
||||
* pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
|
||||
*
|
||||
* Extracted from chap_ms.c by James Carlson.
|
||||
*
|
||||
* Copyright (c) 1995 Eric Rosenquist. 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(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not necessary */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
|
||||
|
||||
static u_char pppcrypt_get_7bits(u_char *input, int startBit) {
|
||||
unsigned int word;
|
||||
|
||||
word = (unsigned)input[startBit / 8] << 8;
|
||||
word |= (unsigned)input[startBit / 8 + 1];
|
||||
|
||||
word >>= 15 - (startBit % 8 + 7);
|
||||
|
||||
return word & 0xFE;
|
||||
}
|
||||
|
||||
/* IN 56 bit DES key missing parity bits
|
||||
* OUT 64 bit DES key with parity bits added
|
||||
*/
|
||||
void pppcrypt_56_to_64_bit_key(u_char *key, u_char * des_key) {
|
||||
des_key[0] = pppcrypt_get_7bits(key, 0);
|
||||
des_key[1] = pppcrypt_get_7bits(key, 7);
|
||||
des_key[2] = pppcrypt_get_7bits(key, 14);
|
||||
des_key[3] = pppcrypt_get_7bits(key, 21);
|
||||
des_key[4] = pppcrypt_get_7bits(key, 28);
|
||||
des_key[5] = pppcrypt_get_7bits(key, 35);
|
||||
des_key[6] = pppcrypt_get_7bits(key, 42);
|
||||
des_key[7] = pppcrypt_get_7bits(key, 49);
|
||||
}
|
||||
|
||||
#endif /* PPP_SUPPORT && MSCHAP_SUPPORT */
|
||||
|
||||
2450
ext/lwip/src/netif/ppp/pppoe.c
Normal file → Executable file
2450
ext/lwip/src/netif/ppp/pppoe.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
2281
ext/lwip/src/netif/ppp/pppol2tp.c
Normal file → Executable file
2281
ext/lwip/src/netif/ppp/pppol2tp.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
1752
ext/lwip/src/netif/ppp/pppos.c
Normal file → Executable file
1752
ext/lwip/src/netif/ppp/pppos.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
1354
ext/lwip/src/netif/ppp/upap.c
Normal file → Executable file
1354
ext/lwip/src/netif/ppp/upap.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
1920
ext/lwip/src/netif/ppp/utils.c
Normal file → Executable file
1920
ext/lwip/src/netif/ppp/utils.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
1390
ext/lwip/src/netif/ppp/vj.c
Normal file → Executable file
1390
ext/lwip/src/netif/ppp/vj.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
1110
ext/lwip/src/netif/slipif.c
Normal file → Executable file
1110
ext/lwip/src/netif/slipif.c
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user