diff --git a/features/netsocket/ppp/include/ccp.h b/features/netsocket/ppp/include/ccp.h index 12bff58cef..79a22c27f5 100644 --- a/features/netsocket/ppp/include/ccp.h +++ b/features/netsocket/ppp/include/ccp.h @@ -31,7 +31,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef CCP_H #define CCP_H diff --git a/features/netsocket/ppp/include/chap-md5.h b/features/netsocket/ppp/include/chap-md5.h index 645864ed41..06cd449afe 100644 --- a/features/netsocket/ppp/include/chap-md5.h +++ b/features/netsocket/ppp/include/chap-md5.h @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ extern const struct chap_digest_type md5_digest; diff --git a/features/netsocket/ppp/include/chap-new.h b/features/netsocket/ppp/include/chap-new.h index fc837dffc8..5ffbdb17c3 100644 --- a/features/netsocket/ppp/include/chap-new.h +++ b/features/netsocket/ppp/include/chap-new.h @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef CHAP_H #define CHAP_H diff --git a/features/netsocket/ppp/include/chap_ms.h b/features/netsocket/ppp/include/chap_ms.h index 4a754744a0..b3d0f184e7 100644 --- a/features/netsocket/ppp/include/chap_ms.h +++ b/features/netsocket/ppp/include/chap_ms.h @@ -31,7 +31,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef CHAPMS_INCLUDE #define CHAPMS_INCLUDE diff --git a/features/netsocket/ppp/include/eap.h b/features/netsocket/ppp/include/eap.h index 4adca9c9ce..42768014ba 100644 --- a/features/netsocket/ppp/include/eap.h +++ b/features/netsocket/ppp/include/eap.h @@ -21,7 +21,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef PPP_EAP_H #define PPP_EAP_H diff --git a/features/netsocket/ppp/include/ecp.h b/features/netsocket/ppp/include/ecp.h index 38a844b798..706b35f273 100644 --- a/features/netsocket/ppp/include/ecp.h +++ b/features/netsocket/ppp/include/ecp.h @@ -32,7 +32,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef ECP_H #define ECP_H diff --git a/features/netsocket/ppp/include/eui64.h b/features/netsocket/ppp/include/eui64.h index b7bb1dfddd..354df627b7 100644 --- a/features/netsocket/ppp/include/eui64.h +++ b/features/netsocket/ppp/include/eui64.h @@ -36,7 +36,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef EUI64_H #define EUI64_H @@ -88,7 +88,7 @@ typedef union #define eui64_set32(e, l) do { \ (e).e32[0] = 0; \ - (e).e32[1] = lwip_htonl(l); \ + (e).e32[1] = ppp_htonl(l); \ } while (0) #define eui64_setlo32(e, l) eui64_set32(e, l) diff --git a/features/netsocket/ppp/include/fsm.h b/features/netsocket/ppp/include/fsm.h index be2fa82cbc..00aa4dd733 100644 --- a/features/netsocket/ppp/include/fsm.h +++ b/features/netsocket/ppp/include/fsm.h @@ -43,7 +43,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef FSM_H #define FSM_H diff --git a/features/netsocket/ppp/include/ipcp.h b/features/netsocket/ppp/include/ipcp.h index 1aef48bbcb..51d533f324 100644 --- a/features/netsocket/ppp/include/ipcp.h +++ b/features/netsocket/ppp/include/ipcp.h @@ -43,7 +43,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPP_IPV4_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPP_IPV4_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef IPCP_H #define IPCP_H @@ -61,10 +61,10 @@ extern "C" { #endif /* VJ_SUPPORT */ #define CI_ADDR 3 -#if LWIP_DNS +#if PPP_DNS #define CI_MS_DNS1 129 /* Primary DNS value */ #define CI_MS_DNS2 131 /* Secondary DNS value */ -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ #define CI_MS_WINS1 130 /* Primary WINS value */ #define CI_MS_WINS2 132 /* Secondary WINS value */ @@ -101,15 +101,15 @@ typedef struct ipcp_options { #endif /* VJ_SUPPORT */ unsigned int accept_local :1; /* accept peer's value for ouraddr */ unsigned int accept_remote :1; /* accept peer's value for hisaddr */ -#if LWIP_DNS +#if PPP_DNS unsigned int req_dns1 :1; /* Ask peer to send primary DNS address? */ unsigned int req_dns2 :1; /* Ask peer to send secondary DNS address? */ -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ u32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */ -#if LWIP_DNS +#if PPP_DNS u32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */ -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ u32_t winsaddr[2]; /* Primary and secondary MS WINS entries */ #endif /* UNUSED - WINS */ @@ -120,9 +120,9 @@ typedef struct ipcp_options { #endif /* VJ_SUPPORT */ } ipcp_options; -#if 0 /* UNUSED, already defined by lwIP */ +#if 0 /* UNUSED, already defined */ char *ip_ntoa (u32_t); -#endif /* UNUSED, already defined by lwIP */ +#endif /* UNUSED, already defined */ extern const struct protent ipcp_protent; diff --git a/features/netsocket/ppp/include/ipv6cp.h b/features/netsocket/ppp/include/ipv6cp.h index 17d31d31cd..7b1671fa34 100644 --- a/features/netsocket/ppp/include/ipv6cp.h +++ b/features/netsocket/ppp/include/ipv6cp.h @@ -139,7 +139,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef IPV6CP_H #define IPV6CP_H diff --git a/features/netsocket/ppp/include/lcp.h b/features/netsocket/ppp/include/lcp.h index 2d36431269..51d4b4af76 100644 --- a/features/netsocket/ppp/include/lcp.h +++ b/features/netsocket/ppp/include/lcp.h @@ -43,7 +43,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef LCP_H #define LCP_H diff --git a/features/netsocket/ppp/include/magic.h b/features/netsocket/ppp/include/magic.h index a397fd27be..cfc803f787 100644 --- a/features/netsocket/ppp/include/magic.h +++ b/features/netsocket/ppp/include/magic.h @@ -42,6 +42,8 @@ * $Id: magic.h,v 1.5 2003/06/11 23:56:26 paulus Exp $ */ /***************************************************************************** +* /@code +* * randm.h - Random number generator header file. * * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. @@ -72,10 +74,12 @@ * Ported to lwIP. * 98-05-29 Guy Lancaster , Global Election Systems Inc. * Extracted from avos. +* +* /@endcode *****************************************************************************/ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef MAGIC_H #define MAGIC_H diff --git a/features/netsocket/ppp/include/mppe.h b/features/netsocket/ppp/include/mppe.h index dc2422cf83..569bf854b7 100644 --- a/features/netsocket/ppp/include/mppe.h +++ b/features/netsocket/ppp/include/mppe.h @@ -34,7 +34,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef MPPE_H #define MPPE_H @@ -63,7 +63,7 @@ extern "C" { * This is not nice ... the alternative is a bitfield struct though. * And unfortunately, we cannot share the same bits for the option * names above since C and H are the same bit. We could do a u_int32 - * but then we have to do a lwip_htonl() all the time and/or we still need + * but then we have to do a ppp_htonl() all the time and/or we still need * to know which octet is which. */ #define MPPE_C_BIT 0x01 /* MPPC */ @@ -152,7 +152,7 @@ static const u8_t mppe_sha1_pad2[SHA1_PAD_SIZE] = { * State for an MPPE (de)compressor. */ typedef struct ppp_mppe_state { - lwip_arc4_context arc4; + ppp_arc4_context arc4; u8_t master_key[MPPE_MAX_KEY_LEN]; u8_t session_key[MPPE_MAX_KEY_LEN]; u8_t keylen; /* key length in bytes */ diff --git a/features/netsocket/ppp/include/polarssl/arc4.h b/features/netsocket/ppp/include/polarssl/arc4.h index 417e239bd8..a1a5f63198 100644 --- a/features/netsocket/ppp/include/polarssl/arc4.h +++ b/features/netsocket/ppp/include/polarssl/arc4.h @@ -1,4 +1,6 @@ /** + * /@code + * * \file arc4.h * * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine @@ -31,13 +33,15 @@ * 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. + * + * /@endcode */ #include "ppp_opts.h" -#if LWIP_INCLUDED_POLARSSL_ARC4 +#if PPP_INCLUDED_POLARSSL_ARC4 -#ifndef LWIP_INCLUDED_POLARSSL_ARC4_H -#define LWIP_INCLUDED_POLARSSL_ARC4_H +#ifndef PPP_INCLUDED_POLARSSL_ARC4_H +#define PPP_INCLUDED_POLARSSL_ARC4_H /** * \brief ARC4 context structure @@ -76,6 +80,6 @@ void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen ); } #endif -#endif /* LWIP_INCLUDED_POLARSSL_ARC4_H */ +#endif /* PPP_INCLUDED_POLARSSL_ARC4_H */ -#endif /* LWIP_INCLUDED_POLARSSL_ARC4 */ +#endif /* PPP_INCLUDED_POLARSSL_ARC4 */ diff --git a/features/netsocket/ppp/include/polarssl/des.h b/features/netsocket/ppp/include/polarssl/des.h index aaf25c16a1..c5e7009aba 100644 --- a/features/netsocket/ppp/include/polarssl/des.h +++ b/features/netsocket/ppp/include/polarssl/des.h @@ -1,4 +1,6 @@ /** + * /@code + * * \file des.h * * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine @@ -31,13 +33,16 @@ * 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. + * + * /@endcode + * */ #include "ppp_opts.h" -#if LWIP_INCLUDED_POLARSSL_DES +#if PPP_INCLUDED_POLARSSL_DES -#ifndef LWIP_INCLUDED_POLARSSL_DES_H -#define LWIP_INCLUDED_POLARSSL_DES_H +#ifndef PPP_INCLUDED_POLARSSL_DES_H +#define PPP_INCLUDED_POLARSSL_DES_H #define DES_ENCRYPT 1 #define DES_DECRYPT 0 @@ -87,6 +92,6 @@ void des_crypt_ecb( des_context *ctx, } #endif -#endif /* LWIP_INCLUDED_POLARSSL_DES_H */ +#endif /* PPP_INCLUDED_POLARSSL_DES_H */ -#endif /* LWIP_INCLUDED_POLARSSL_DES */ +#endif /* PPP_INCLUDED_POLARSSL_DES */ diff --git a/features/netsocket/ppp/include/polarssl/md4.h b/features/netsocket/ppp/include/polarssl/md4.h index 1719e336a3..a8518f0afc 100644 --- a/features/netsocket/ppp/include/polarssl/md4.h +++ b/features/netsocket/ppp/include/polarssl/md4.h @@ -1,4 +1,6 @@ /** + * /@code + * * \file md4.h * * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine @@ -31,13 +33,15 @@ * 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. + * + * /@endcode */ #include "ppp_opts.h" -#if LWIP_INCLUDED_POLARSSL_MD4 +#if PPP_INCLUDED_POLARSSL_MD4 -#ifndef LWIP_INCLUDED_POLARSSL_MD4_H -#define LWIP_INCLUDED_POLARSSL_MD4_H +#ifndef PPP_INCLUDED_POLARSSL_MD4_H +#define PPP_INCLUDED_POLARSSL_MD4_H /** * \brief MD4 context structure @@ -92,6 +96,6 @@ void md4( unsigned char *input, int ilen, unsigned char output[16] ); } #endif -#endif /* LWIP_INCLUDED_POLARSSL_MD4_H */ +#endif /* PPP_INCLUDED_POLARSSL_MD4_H */ -#endif /* LWIP_INCLUDED_POLARSSL_MD4 */ +#endif /* PPP_INCLUDED_POLARSSL_MD4 */ diff --git a/features/netsocket/ppp/include/polarssl/md5.h b/features/netsocket/ppp/include/polarssl/md5.h index 2dd7a3540c..c43878b2e7 100644 --- a/features/netsocket/ppp/include/polarssl/md5.h +++ b/features/netsocket/ppp/include/polarssl/md5.h @@ -1,4 +1,6 @@ /** + * /@code + * * \file md5.h * * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine @@ -31,13 +33,12 @@ * 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. + * + * /@endcode */ -#include "ppp_opts.h" -#if LWIP_INCLUDED_POLARSSL_MD5 - -#ifndef LWIP_INCLUDED_POLARSSL_MD5_H -#define LWIP_INCLUDED_POLARSSL_MD5_H +#ifndef PPP_INCLUDED_POLARSSL_MD5_H +#define PPP_INCLUDED_POLARSSL_MD5_H /** * \brief MD5 context structure @@ -91,6 +92,5 @@ void md5( unsigned char *input, int ilen, unsigned char output[16] ); } #endif -#endif /* LWIP_INCLUDED_POLARSSL_MD5_H */ +#endif /* PPP_INCLUDED_POLARSSL_MD5_H */ -#endif /* LWIP_INCLUDED_POLARSSL_MD5 */ diff --git a/features/netsocket/ppp/include/polarssl/sha1.h b/features/netsocket/ppp/include/polarssl/sha1.h index 409776ffb3..3231dd26b0 100644 --- a/features/netsocket/ppp/include/polarssl/sha1.h +++ b/features/netsocket/ppp/include/polarssl/sha1.h @@ -1,4 +1,6 @@ /** + * /@code + * * \file sha1.h * * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine @@ -31,13 +33,15 @@ * 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. + * + * /@endcode */ #include "ppp_opts.h" -#if LWIP_INCLUDED_POLARSSL_SHA1 +#if PPP_INCLUDED_POLARSSL_SHA1 -#ifndef LWIP_INCLUDED_POLARSSL_SHA1_H -#define LWIP_INCLUDED_POLARSSL_SHA1_H +#ifndef PPP_INCLUDED_POLARSSL_SHA1_H +#define PPP_INCLUDED_POLARSSL_SHA1_H /** * \brief SHA-1 context structure @@ -91,6 +95,6 @@ void sha1( unsigned char *input, int ilen, unsigned char output[20] ); } #endif -#endif /* LWIP_INCLUDED_POLARSSL_SHA1_H */ +#endif /* PPP_INCLUDED_POLARSSL_SHA1_H */ -#endif /* LWIP_INCLUDED_POLARSSL_SHA1 */ +#endif /* PPP_INCLUDED_POLARSSL_SHA1 */ diff --git a/features/netsocket/ppp/include/ppp.h b/features/netsocket/ppp/include/ppp.h index c9be4ad3ea..e27ba093b5 100644 --- a/features/netsocket/ppp/include/ppp.h +++ b/features/netsocket/ppp/include/ppp.h @@ -1,4 +1,6 @@ /***************************************************************************** +* /@code +* * ppp.h - Network Point to Point Protocol header file. * * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. @@ -29,24 +31,16 @@ * Ported to lwIP. * 97-11-05 Guy Lancaster , Global Election Systems Inc. * Original derived from BSD codes. +* +* /@endcode *****************************************************************************/ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef PPP_H #define PPP_H -#include "lwip/def.h" -#include "lwip/stats.h" -#include "lwip/mem.h" -#include "lwip/netif.h" -#include "lwip/sys.h" -#include "lwip/timeouts.h" -#if PPP_IPV6_SUPPORT -#include "lwip/ip6_addr.h" -#endif /* PPP_IPV6_SUPPORT */ - #ifdef __cplusplus extern "C" { #endif @@ -220,9 +214,9 @@ typedef struct ppp_settings_s { #if EAP_SUPPORT unsigned int refuse_eap :1; /* Don't proceed auth. with EAP */ #endif /* EAP_SUPPORT */ -#if LWIP_DNS +#if PPP_DNS unsigned int usepeerdns :1; /* Ask peer for DNS adds */ -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ unsigned int persist :1; /* Persist mode, always try to open the connection */ #if PRINTPKT_SUPPORT unsigned int hide_password :1; /* Hide password in dumped packets */ @@ -300,9 +294,9 @@ typedef struct ppp_settings_s { struct ppp_addrs { #if PPP_IPV4_SUPPORT ip4_addr_t our_ipaddr, his_ipaddr, netmask; -#if LWIP_DNS +#if PPP_DNS ip4_addr_t dns1, dns2; -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #endif /* PPP_IPV4_SUPPORT */ #if PPP_IPV6_SUPPORT ip6_addr_t our6_ipaddr, his6_ipaddr; @@ -487,7 +481,7 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas #define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \ ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0) #define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr)) -#if LWIP_DNS +#if PPP_DNS /* * Set DNS server addresses that are sent if the peer asks for them. This is mostly necessary * for PPP server support. @@ -503,7 +497,7 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas * Default is false. */ #define ppp_set_usepeerdns(ppp, boolval) (ppp->settings.usepeerdns = boolval) -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #endif /* PPP_IPV4_SUPPORT */ #if MPPE_SUPPORT @@ -685,11 +679,11 @@ err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg); /* Get the PPP netif interface */ #define ppp_netif(ppp) (ppp->netif) -/* Set an lwIP-style status-callback for the selected PPP device */ +/* Set a status-callback for the selected PPP device */ #define ppp_set_netif_statuscallback(ppp, status_cb) \ netif_set_status_callback(ppp->netif, status_cb); -/* Set an lwIP-style link-callback for the selected PPP device */ +/* Set a link-callback for the selected PPP device */ #define ppp_set_netif_linkcallback(ppp, link_cb) \ netif_set_link_callback(ppp->netif, link_cb); diff --git a/features/netsocket/ppp/include/ppp_impl.h b/features/netsocket/ppp/include/ppp_impl.h index 9433bc0f95..fe2538ecb4 100644 --- a/features/netsocket/ppp/include/ppp_impl.h +++ b/features/netsocket/ppp/include/ppp_impl.h @@ -1,4 +1,6 @@ /***************************************************************************** +* /@code +* * ppp.h - Network Point to Point Protocol header file. * * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. @@ -29,13 +31,15 @@ * Ported to lwIP. * 97-11-05 Guy Lancaster , Global Election Systems Inc. * Original derived from BSD codes. +* +* /@endcode *****************************************************************************/ -#ifndef LWIP_HDR_PPP_IMPL_H -#define LWIP_HDR_PPP_IMPL_H +#ifndef PPP_IMPL_H +#define PPP_IMPL_H #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifdef PPP_INCLUDE_SETTINGS_HEADER #include "ppp_settings.h" @@ -46,10 +50,6 @@ #include #include /* strtol() */ -#include "lwip/netif.h" -#include "lwip/def.h" -#include "lwip/timeouts.h" - #include "ppp.h" #include "pppdebug.h" @@ -57,6 +57,53 @@ extern "C" { #endif +/* + * Endian conversion macros + */ +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif + +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif + +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif + +#if BYTE_ORDER == BIG_ENDIAN +#define ppp_htons(x) ((u16_t)(x)) +#define ppp_ntohs(x) ((u16_t)(x)) +#define ppp_htonl(x) ((u32_t)(x)) +#define ppp_ntohl(x) ((u32_t)(x)) +#define PP_HTONS(x) ((u16_t)(x)) +#define PP_NTOHS(x) ((u16_t)(x)) +#define PP_HTONL(x) ((u32_t)(x)) +#define PP_NTOHL(x) ((u32_t)(x)) +#else /* BYTE_ORDER != BIG_ENDIAN */ +#ifndef ppp_htons +u16_t ppp_htons(u16_t x); +#endif +#define ppp_ntohs(x) ppp_htons(x) + +#ifndef ppp_htonl +u32_t ppp_htonl(u32_t x); +#endif +#define ppp_ntohl(x) ppp_htonl(x) + +/* These macros should be calculated by the preprocessor and are used + with compile-time constants only (so that there is no little-endian + overhead at runtime). */ +#define PP_HTONS(x) ((u16_t)((((x) & (u16_t)0x00ffU) << 8) | (((x) & (u16_t)0xff00U) >> 8))) +#define PP_NTOHS(x) PP_HTONS(x) +#define PP_HTONL(x) ((((x) & (u32_t)0x000000ffUL) << 24) | \ + (((x) & (u32_t)0x0000ff00UL) << 8) | \ + (((x) & (u32_t)0x00ff0000UL) >> 8) | \ + (((x) & (u32_t)0xff000000UL) >> 24)) +#define PP_NTOHL(x) PP_HTONL(x) +#endif /* BYTE_ORDER == BIG_ENDIAN */ + /* * Memory used for control packets. * @@ -153,7 +200,7 @@ struct link_callbacks { err_t (*free) (ppp_pcb *pcb, void *ctx); /* Write a pbuf to a ppp link, only used from PPP functions to send PPP packets. */ err_t (*write)(ppp_pcb *pcb, void *ctx, struct pbuf *p); - /* Send a packet from lwIP core (IPv4 or IPv6) */ + /* Send a packet from stack core (IPv4 or IPv6) */ err_t (*netif_output)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u_short protocol); /* configure the transmit-side characteristics of the PPP interface */ void (*send_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp); @@ -384,7 +431,7 @@ struct pppd_stats { /* - * Functions called from lwIP core. + * Functions called from stack core. */ /* initialize the PPP subsystem */ @@ -433,10 +480,10 @@ int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr); int sifproxyarp(ppp_pcb *pcb, u32_t his_adr); int cifproxyarp(ppp_pcb *pcb, u32_t his_adr); #endif /* UNUSED - PROXY ARP */ -#if LWIP_DNS +#if PPP_DNS int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2); int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2); -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if VJ_SUPPORT int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid); #endif /* VJ_SUPPORT */ @@ -529,13 +576,6 @@ void update_link_stats(int u); /* Get stats at link termination */ #define INCPTR(n, cp) ((cp) += (n)) #define DECPTR(n, cp) ((cp) -= (n)) -/* - * System dependent definitions for user-level 4.3BSD UNIX implementation. - */ -#define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0) -#define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0) -#define UNTIMEOUT(f, a) sys_untimeout((f), (a)) - #define BZERO(s, n) memset(s, 0, n) #define BCMP(s1, s2, l) memcmp(s1, s2, l) @@ -703,12 +743,12 @@ void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len); * * IPv4 or IPv6 must be enabled, therefore we don't need to take care the authentication * and the CCP + ECP case, thus reducing overall complexity. - * 1 + LWIP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT) + * 1 + PPP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT) * * We don't support PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS features * and adding those defines to ppp_opts.h just for having the value always * defined to 0 isn't worth it. - * 1 + LWIP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + CCP_SUPPORT) + * 1 + PPP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + CCP_SUPPORT) * * Thus, the following is enough for now. * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT @@ -719,4 +759,4 @@ void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len); #endif #endif /* PPP_SUPPORT */ -#endif /* LWIP_HDR_PPP_IMPL_H */ +#endif /* PPP_IMPL_H */ diff --git a/features/netsocket/ppp/include/ppp_opts.h b/features/netsocket/ppp/include/ppp_opts.h index 6702bec618..8a2a35e375 100644 --- a/features/netsocket/ppp/include/ppp_opts.h +++ b/features/netsocket/ppp/include/ppp_opts.h @@ -25,10 +25,57 @@ * */ -#ifndef LWIP_PPP_OPTS_H -#define LWIP_PPP_OPTS_H +#ifndef PPP_OPTS_H +#define PPP_OPTS_H -#include "lwip/opt.h" +#include "nsapi_types.h" + +// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration +#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED + +#define PPP_SUPPORT 1 + +// For LWIP stack enable PPP Ipv4/Ipv6 support from LWIP IP version flags +#define LWIP 0x11991199 + +#if MBED_CONF_PPP_IPV4_ENABLED || ((MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && MBED_CONF_LWIP_IPV4_ENABLED) +#define PPP_IPV4_SUPPORT 1 +#endif + +#if MBED_CONF_PPP_IPV6_ENABLED || ((MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && MBED_CONF_LWIP_IPV6_ENABLED) +#define PPP_IPV6_SUPPORT 1 +#endif +#undef LWIP + +#if MBED_CONF_PPP_ENABLE_TRACE +// Traces every packet +#define PPP_TRACE_ENABLE 1 +#define PPP_TRACE_BUFFER_SIZE 0 //50000 +#endif + +#endif + +#if PPP_SUPPORT + +#define CHAP_SUPPORT 1 +#define PPP_INPROC_IRQ_SAFE 1 +#define NO_SYS 1 +// Save RAM +#define PAP_SUPPORT 0 +#define VJ_SUPPORT 0 +#define PRINTPKT_SUPPORT 0 + +#define MAXNAMELEN 64 /* max length of hostname or name for auth */ +#define MAXSECRETLEN 64 + +#define PPP_DNS 1 + +// Used as maximum size for output buffer, to restrict the memory manager get_pool_alloc_unit() +#define PBUF_POOL_BUFSIZE 536 + 40 + +#endif // PPP_SUPPORT + +#include "ppp_service_if.h" /** * PPP_SUPPORT==1: Enable PPP. @@ -66,10 +113,10 @@ #endif /** - * LWIP_PPP_API==1: Enable PPP API (in pppapi.c) + * PPP_API==1: Enable PPP API (in pppapi.c) */ -#ifndef LWIP_PPP_API -#define LWIP_PPP_API (PPP_SUPPORT && (NO_SYS == 0)) +#ifndef PPP_API +#define PPP_API 0 //(PPP_SUPPORT && (NO_SYS == 0)) #endif #if PPP_SUPPORT @@ -125,12 +172,6 @@ #define MEMP_NUM_PPP_API_MSG 5 #endif -/** - * PPP_DEBUG: Enable debugging for PPP. - */ -#ifndef PPP_DEBUG -#define PPP_DEBUG LWIP_DBG_OFF -#endif /** * PPP_INPROC_IRQ_SAFE==1 call pppos_input() using tcpip_callback(). @@ -138,7 +179,7 @@ * Please read the "PPPoS input path" chapter in the PPP documentation about this option. */ #ifndef PPP_INPROC_IRQ_SAFE -#define PPP_INPROC_IRQ_SAFE 0 +#define PPP_INPROC_IRQ_SAFE 1 #endif /** @@ -150,20 +191,6 @@ #define PRINTPKT_SUPPORT 0 #endif -/** - * PPP_IPV4_SUPPORT==1: Enable PPP IPv4 support - */ -#ifndef PPP_IPV4_SUPPORT -#define PPP_IPV4_SUPPORT (LWIP_IPV4) -#endif - -/** - * PPP_IPV6_SUPPORT==1: Enable PPP IPv6 support - */ -#ifndef PPP_IPV6_SUPPORT -#define PPP_IPV6_SUPPORT (LWIP_IPV6) -#endif - /** * PPP_NOTIFY_PHASE==1: Support PPP notify phase support * @@ -298,7 +325,7 @@ * PPP_OUR_NAME: Our name for authentication purposes */ #ifndef PPP_OUR_NAME -#define PPP_OUR_NAME "lwIP" +#define PPP_OUR_NAME "ppp" #endif #endif /* PPP_SERVER */ @@ -326,16 +353,16 @@ * PolarSSL embedded library * * - * lwIP contains some files fetched from the latest BSD release of + * PPP 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. + * methods we need for PPP support. * * The PolarSSL files were cleaned to contain only the necessary struct - * fields and functions needed for lwIP. + * fields and functions needed for PPP. * * 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. + * library into PPP. * * If you are not using the embedded copy you must include external * libraries into your arch/cc.h port file. @@ -345,17 +372,17 @@ */ /** - * LWIP_USE_EXTERNAL_POLARSSL: Use external PolarSSL library + * PPP_USE_EXTERNAL_POLARSSL: Use external PolarSSL library */ -#ifndef LWIP_USE_EXTERNAL_POLARSSL -#define LWIP_USE_EXTERNAL_POLARSSL 0 +#ifndef PPP_USE_EXTERNAL_POLARSSL +#define PPP_USE_EXTERNAL_POLARSSL 0 #endif /** - * LWIP_USE_EXTERNAL_MBEDTLS: Use external mbed TLS library + * PPP_USE_EXTERNAL_MBEDTLS: Use external mbed TLS library */ -#ifndef LWIP_USE_EXTERNAL_MBEDTLS -#define LWIP_USE_EXTERNAL_MBEDTLS 0 +#ifndef PPP_USE_EXTERNAL_MBEDTLS +#define PPP_USE_EXTERNAL_MBEDTLS 0 #endif /* @@ -391,7 +418,7 @@ #endif /** - * UPAP_DEFTIMEOUT: Timeout (seconds) for retransmitting req + * UPAP_DEFTIMEOUT: Timeout (seconds) for re-transmitting req */ #ifndef UPAP_DEFTIMEOUT #define UPAP_DEFTIMEOUT 6 @@ -414,7 +441,7 @@ #endif /* PPP_SERVER */ /** - * CHAP_DEFTIMEOUT: Timeout (seconds) for retransmitting req + * CHAP_DEFTIMEOUT: Timeout (seconds) for re-transmitting req */ #ifndef CHAP_DEFTIMEOUT #define CHAP_DEFTIMEOUT 6 @@ -429,7 +456,7 @@ #if PPP_SERVER /** - * CHAP_DEFRECHALLENGETIME: If this option is > 0, rechallenge the peer every n seconds + * CHAP_DEFRECHALLENGETIME: If this option is > 0, re-challenge the peer every n seconds */ #ifndef CHAP_DEFRECHALLENGETIME #define CHAP_DEFRECHALLENGETIME 0 @@ -557,48 +584,45 @@ /* * Build triggers for embedded PolarSSL */ -#if !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS /* CHAP, EAP, L2TP AUTH and MD5 Random require MD5 support */ #if CHAP_SUPPORT || EAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT || PPP_MD5_RANDM -#define LWIP_INCLUDED_POLARSSL_MD5 1 +#define PPP_INCLUDED_POLARSSL_MD5 1 #endif /* CHAP_SUPPORT || EAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT || PPP_MD5_RANDM */ #if MSCHAP_SUPPORT /* MSCHAP require MD4 support */ -#define LWIP_INCLUDED_POLARSSL_MD4 1 +#define PPP_INCLUDED_POLARSSL_MD4 1 /* MSCHAP require SHA1 support */ -#define LWIP_INCLUDED_POLARSSL_SHA1 1 +#define PPP_INCLUDED_POLARSSL_SHA1 1 /* MSCHAP require DES support */ -#define LWIP_INCLUDED_POLARSSL_DES 1 +#define PPP_INCLUDED_POLARSSL_DES 1 /* MS-CHAP support is required for MPPE */ #if MPPE_SUPPORT /* MPPE require ARC4 support */ -#define LWIP_INCLUDED_POLARSSL_ARC4 1 +#define PPP_INCLUDED_POLARSSL_ARC4 1 #endif /* MPPE_SUPPORT */ #endif /* MSCHAP_SUPPORT */ -#endif /* !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS */ - /* Default value if unset */ -#ifndef LWIP_INCLUDED_POLARSSL_MD4 -#define LWIP_INCLUDED_POLARSSL_MD4 0 -#endif /* LWIP_INCLUDED_POLARSSL_MD4 */ -#ifndef LWIP_INCLUDED_POLARSSL_MD5 -#define LWIP_INCLUDED_POLARSSL_MD5 0 -#endif /* LWIP_INCLUDED_POLARSSL_MD5 */ -#ifndef LWIP_INCLUDED_POLARSSL_SHA1 -#define LWIP_INCLUDED_POLARSSL_SHA1 0 -#endif /* LWIP_INCLUDED_POLARSSL_SHA1 */ -#ifndef LWIP_INCLUDED_POLARSSL_DES -#define LWIP_INCLUDED_POLARSSL_DES 0 -#endif /* LWIP_INCLUDED_POLARSSL_DES */ -#ifndef LWIP_INCLUDED_POLARSSL_ARC4 -#define LWIP_INCLUDED_POLARSSL_ARC4 0 -#endif /* LWIP_INCLUDED_POLARSSL_ARC4 */ +#ifndef PPP_INCLUDED_POLARSSL_MD4 +#define PPP_INCLUDED_POLARSSL_MD4 0 +#endif /* PPP_INCLUDED_POLARSSL_MD4 */ +#ifndef PPP_INCLUDED_POLARSSL_MD5 +#define PPP_INCLUDED_POLARSSL_MD5 0 +#endif /* PPP_INCLUDED_POLARSSL_MD5 */ +#ifndef PPP_INCLUDED_POLARSSL_SHA1 +#define PPP_INCLUDED_POLARSSL_SHA1 0 +#endif /* PPP_INCLUDED_POLARSSL_SHA1 */ +#ifndef PPP_INCLUDED_POLARSSL_DES +#define PPP_INCLUDED_POLARSSL_DES 0 +#endif /* PPP_INCLUDED_POLARSSL_DES */ +#ifndef PPP_INCLUDED_POLARSSL_ARC4 +#define PPP_INCLUDED_POLARSSL_ARC4 0 +#endif /* PPP_INCLUDED_POLARSSL_ARC4 */ #endif /* PPP_SUPPORT */ @@ -607,4 +631,4 @@ #define PPP_NUM_TIMEOUTS 0 #endif /* PPP_NUM_TIMEOUTS */ -#endif /* LWIP_PPP_OPTS_H */ +#endif /* PPP_OPTS_H */ diff --git a/features/netsocket/ppp/include/pppapi.h b/features/netsocket/ppp/include/pppapi.h index f9c0b22550..e4de17c2d4 100644 --- a/features/netsocket/ppp/include/pppapi.h +++ b/features/netsocket/ppp/include/pppapi.h @@ -25,16 +25,15 @@ * */ -#ifndef LWIP_PPPAPI_H -#define LWIP_PPPAPI_H +#ifndef PPPAPI_H +#define PPPAPI_H #include "ppp_opts.h" -#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */ +#if PPP_API + +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ -#include "lwip/sys.h" -#include "lwip/netif.h" -#include "lwip/priv/tcpip_priv.h" #include "ppp.h" #if PPPOS_SUPPORT #include "pppos.h" @@ -132,6 +131,8 @@ err_t pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg); } #endif -#endif /* LWIP_PPP_API */ +#endif /* PPP_SUPPORT */ -#endif /* LWIP_PPPAPI_H */ +#endif /* PPP_API */ + +#endif /* PPPAPI_H */ diff --git a/features/netsocket/ppp/include/pppcrypt.h b/features/netsocket/ppp/include/pppcrypt.h index a7444489c9..846f168d9b 100644 --- a/features/netsocket/ppp/include/pppcrypt.h +++ b/features/netsocket/ppp/include/pppcrypt.h @@ -31,19 +31,13 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ /* This header file is included in all PPP modules needing hashes and/or ciphers */ #ifndef PPPCRYPT_H #define PPPCRYPT_H -/* - * If included PolarSSL copy is not used, user is expected to include - * external libraries in arch/cc.h (which is included by lwip/arch.h). - */ -#include "lwip/arch.h" - #ifdef __cplusplus extern "C" { #endif @@ -51,87 +45,89 @@ extern "C" { /* * Map hashes and ciphers functions to PolarSSL */ -#if !LWIP_USE_EXTERNAL_MBEDTLS +#if !PPP_USE_EXTERNAL_MBEDTLS #include "polarssl/md4.h" -#define lwip_md4_context md4_context -#define lwip_md4_init(context) -#define lwip_md4_starts md4_starts -#define lwip_md4_update md4_update -#define lwip_md4_finish md4_finish -#define lwip_md4_free(context) +#define MD4_context md4_context +#define MD4_init(context) +#define MD4_starts md4_starts +#define MD4_update md4_update +#define MD4_finish md4_finish +#define MD4_free(context) #include "polarssl/md5.h" -#define lwip_md5_context md5_context -#define lwip_md5_init(context) -#define lwip_md5_starts md5_starts -#define lwip_md5_update md5_update -#define lwip_md5_finish md5_finish -#define lwip_md5_free(context) +#define MD5_context md5_context +#define MD5_init(context) +#define MD5_starts md5_starts +#define MD5_update md5_update +#define MD5_finish md5_finish +#define MD5_free(context) #include "polarssl/sha1.h" -#define lwip_sha1_context sha1_context -#define lwip_sha1_init(context) -#define lwip_sha1_starts sha1_starts -#define lwip_sha1_update sha1_update -#define lwip_sha1_finish sha1_finish -#define lwip_sha1_free(context) +#define SHA1_context sha1_context +#define SHA1_init(context) +#define SHA1_starts sha1_starts +#define SHA1_update sha1_update +#define SHA1_finish sha1_finish +#define SHA1_free(context) #include "polarssl/des.h" -#define lwip_des_context des_context -#define lwip_des_init(context) -#define lwip_des_setkey_enc des_setkey_enc -#define lwip_des_crypt_ecb des_crypt_ecb -#define lwip_des_free(context) +#define Des_context des_context +#define Des_init(context) +#define Des_setkey_enc des_setkey_enc +#define Des_crypt_ecb des_crypt_ecb +#define Des_free(context) #include "polarssl/arc4.h" -#define lwip_arc4_context arc4_context -#define lwip_arc4_init(context) -#define lwip_arc4_setup arc4_setup -#define lwip_arc4_crypt arc4_crypt -#define lwip_arc4_free(context) +#define ARC4_context arc4_context +#define ARC4_init(context) +#define ARC4_setup arc4_setup +#define ARC4_crypt arc4_crypt +#define ARC4_free(context) -#endif /* !LWIP_USE_EXTERNAL_MBEDTLS */ +#endif /* !PPP_USE_EXTERNAL_MBEDTLS */ /* * Map hashes and ciphers functions to mbed TLS */ -#if LWIP_USE_EXTERNAL_MBEDTLS +#if PPP_USE_EXTERNAL_MBEDTLS -#define lwip_md4_context mbedtls_md4_context -#define lwip_md4_init mbedtls_md4_init -#define lwip_md4_starts mbedtls_md4_starts -#define lwip_md4_update mbedtls_md4_update -#define lwip_md4_finish mbedtls_md4_finish -#define lwip_md4_free mbedtls_md4_free +#include "mbedtls/md5.h" -#define lwip_md5_context mbedtls_md5_context -#define lwip_md5_init mbedtls_md5_init -#define lwip_md5_starts mbedtls_md5_starts -#define lwip_md5_update mbedtls_md5_update -#define lwip_md5_finish mbedtls_md5_finish -#define lwip_md5_free mbedtls_md5_free +#define MD4_context mbedtls_md4_context +#define MD4_init mbedtls_md4_init +#define MD4_starts mbedtls_md4_starts +#define MD4_update mbedtls_md4_update +#define MD4_finish mbedtls_md4_finish +#define MD4_free mbedtls_md4_free -#define lwip_sha1_context mbedtls_sha1_context -#define lwip_sha1_init mbedtls_sha1_init -#define lwip_sha1_starts mbedtls_sha1_starts -#define lwip_sha1_update mbedtls_sha1_update -#define lwip_sha1_finish mbedtls_sha1_finish -#define lwip_sha1_free mbedtls_sha1_free +#define MD5_context mbedtls_md5_context +#define MD5_init mbedtls_md5_init +#define MD5_starts mbedtls_md5_starts +#define MD5_update mbedtls_md5_update +#define MD5_finish mbedtls_md5_finish +#define MD5_free mbedtls_md5_free -#define lwip_des_context mbedtls_des_context -#define lwip_des_init mbedtls_des_init -#define lwip_des_setkey_enc mbedtls_des_setkey_enc -#define lwip_des_crypt_ecb mbedtls_des_crypt_ecb -#define lwip_des_free mbedtls_des_free +#define SHA1_context mbedtls_sha1_context +#define SHA1_init mbedtls_sha1_init +#define SHA1_starts mbedtls_sha1_starts +#define SHA1_update mbedtls_sha1_update +#define SHA1_finish mbedtls_sha1_finish +#define SHA1_free mbedtls_sha1_free -#define lwip_arc4_context mbedtls_arc4_context -#define lwip_arc4_init mbedtls_arc4_init -#define lwip_arc4_setup mbedtls_arc4_setup -#define lwip_arc4_crypt(context, buffer, length) mbedtls_arc4_crypt(context, length, buffer, buffer) -#define lwip_arc4_free mbedtls_arc4_free +#define Des_context mbedtls_des_context +#define Des_init mbedtls_des_init +#define Des_setkey_enc mbedtls_des_setkey_enc +#define Des_crypt_ecb mbedtls_des_crypt_ecb +#define Des_free mbedtls_des_free -#endif /* LWIP_USE_EXTERNAL_MBEDTLS */ +#define ARC4_context mbedtls_arc4_context +#define ARC4_init mbedtls_arc4_init +#define ARC4_setup mbedtls_arc4_setup +#define ARC4_crypt(context, buffer, length) mbedtls_arc4_crypt(context, length, buffer, buffer) +#define ARC4_free mbedtls_arc4_free + +#endif /* PPP_USE_EXTERNAL_MBEDTLS */ void pppcrypt_56_to_64_bit_key(u_char *key, u_char *des_key); diff --git a/features/netsocket/ppp/include/pppdebug.h b/features/netsocket/ppp/include/pppdebug.h index 9f82b68637..9bdbbf548d 100644 --- a/features/netsocket/ppp/include/pppdebug.h +++ b/features/netsocket/ppp/include/pppdebug.h @@ -1,4 +1,6 @@ /***************************************************************************** +* /@code +* * pppdebug.h - System debugging utilities. * * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. @@ -31,11 +33,12 @@ * 98-07-29 Guy Lancaster , Global Election Systems Inc. * Original. * +* /@endcode ***************************************************************************** */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef PPPDEBUG_H #define PPPDEBUG_H @@ -44,26 +47,43 @@ extern "C" { #endif +#if PPP_DEBUG +#if MBED_CONF_MBED_TRACE_ENABLE +#include "mbed_trace.h" +#define TRACE_GROUP "ppp" +#define PPP_DEBUGF(level, message) tr_info message +#else +#define PPP_DEBUGF(level, message) printf message +#endif +#else +#define PPP_DEBUGF(level, message) +#endif + +#define PPP_DBG_LEVEL_ALL 0x00 +#define PPP_DBG_LEVEL_WARNING 0x01 +#define PPP_DBG_LEVEL_SERIOUS 0x02 +#define PPP_DBG_LEVEL_SEVERE 0x03 + /* Trace levels. */ -#define LOG_CRITICAL (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE) -#define LOG_ERR (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE) -#define LOG_NOTICE (PPP_DEBUG | LWIP_DBG_LEVEL_WARNING) -#define LOG_WARNING (PPP_DEBUG | LWIP_DBG_LEVEL_WARNING) +#define LOG_CRITICAL (PPP_DEBUG | PPP_DBG_LEVEL_SEVERE) +#define LOG_ERR (PPP_DEBUG | PPP_DBG_LEVEL_SEVERE) +#define LOG_NOTICE (PPP_DEBUG | PPP_DBG_LEVEL_WARNING) +#define LOG_WARNING (PPP_DEBUG | PPP_DBG_LEVEL_WARNING) #define LOG_INFO (PPP_DEBUG) #define LOG_DETAIL (PPP_DEBUG) #define LOG_DEBUG (PPP_DEBUG) #if PPP_DEBUG -#define MAINDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define SYSDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define FSMDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define LCPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define IPCPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define IPV6CPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define UPAPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define CHAPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) -#define PPPDEBUG(a, b) LWIP_DEBUGF(a, b) +#define MAINDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define SYSDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define FSMDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define LCPDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define IPCPDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define IPV6CPDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define UPAPDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define CHAPDEBUG(a) PPP_DEBUGF(PPP_DBG_LEVEL_WARNING, a) +#define PPPDEBUG(a, b) PPP_DEBUGF(a, b) #else /* PPP_DEBUG */ diff --git a/features/netsocket/ppp/include/pppoe.h b/features/netsocket/ppp/include/pppoe.h index c7603094e3..5b8cdd58cf 100644 --- a/features/netsocket/ppp/include/pppoe.h +++ b/features/netsocket/ppp/include/pppoe.h @@ -1,4 +1,6 @@ /***************************************************************************** +* /@code +* * pppoe.h - PPP Over Ethernet implementation for lwIP. * * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc. @@ -26,6 +28,8 @@ * * 06-01-01 Marc Boucher * Ported to lwIP. +* +* /@endcode *****************************************************************************/ @@ -68,13 +72,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPPOE_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef PPP_OE_H #define PPP_OE_H #include "ppp.h" -#include "lwip/etharp.h" #ifdef __cplusplus extern "C" { @@ -172,8 +175,8 @@ ppp_pcb *pppoe_create(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); /* - * Functions called from lwIP - * DO NOT CALL FROM lwIP USER APPLICATION. + * Functions called from stack + * DO NOT CALL FROM stack USER APPLICATION. */ void pppoe_disc_input(struct netif *netif, struct pbuf *p); void pppoe_data_input(struct netif *netif, struct pbuf *p); diff --git a/features/netsocket/ppp/include/pppol2tp.h b/features/netsocket/ppp/include/pppol2tp.h index 6460cc30e1..9f11a51675 100644 --- a/features/netsocket/ppp/include/pppol2tp.h +++ b/features/netsocket/ppp/include/pppol2tp.h @@ -32,7 +32,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef PPPOL2TP_H #define PPPOL2TP_H @@ -115,11 +115,11 @@ extern "C" { /* -- AVP - Host name */ #define PPPOL2TP_AVPTYPE_HOSTNAME 7 /* Host name */ -#define PPPOL2TP_HOSTNAME "lwIP" /* FIXME: make it configurable */ +#define PPPOL2TP_HOSTNAME "ppp" /* FIXME: make it configurable */ /* -- AVP - Vendor name */ #define PPPOL2TP_AVPTYPE_VENDORNAME 8 /* Vendor name */ -#define PPPOL2TP_VENDORNAME "lwIP" /* FIXME: make it configurable */ +#define PPPOL2TP_VENDORNAME "ppp" /* FIXME: make it configurable */ /* -- AVP - Assign tunnel ID */ #define PPPOL2TP_AVPTYPE_TUNNELID 9 /* Assign Tunnel ID */ diff --git a/features/netsocket/ppp/include/pppos.h b/features/netsocket/ppp/include/pppos.h index eb4aa4f69b..b33aa6bdce 100644 --- a/features/netsocket/ppp/include/pppos.h +++ b/features/netsocket/ppp/include/pppos.h @@ -32,13 +32,11 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef PPPOS_H #define PPPOS_H -#include "lwip/sys.h" - #include "ppp.h" #include "vj.h" @@ -102,7 +100,7 @@ ppp_pcb *pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); #if !NO_SYS && !PPP_INPROC_IRQ_SAFE -/* Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. */ +/* Pass received raw characters to PPPoS to be decoded through stacks TCPIP thread. */ err_t pppos_input_tcpip(ppp_pcb *ppp, u8_t *s, int l); #endif /* !NO_SYS && !PPP_INPROC_IRQ_SAFE */ @@ -111,8 +109,8 @@ void pppos_input(ppp_pcb *ppp, u8_t* data, int len); /* - * Functions called from lwIP - * DO NOT CALL FROM lwIP USER APPLICATION. + * Functions called from stack + * DO NOT CALL FROM stacks USER APPLICATION. */ #if !NO_SYS && !PPP_INPROC_IRQ_SAFE err_t pppos_input_sys(struct pbuf *p, struct netif *inp); diff --git a/features/netsocket/ppp/include/upap.h b/features/netsocket/ppp/include/upap.h index 19e8606581..d874fcbd7a 100644 --- a/features/netsocket/ppp/include/upap.h +++ b/features/netsocket/ppp/include/upap.h @@ -43,7 +43,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef UPAP_H #define UPAP_H diff --git a/features/netsocket/ppp/include/vj.h b/features/netsocket/ppp/include/vj.h index b802b32dd1..9a761d0bb3 100644 --- a/features/netsocket/ppp/include/vj.h +++ b/features/netsocket/ppp/include/vj.h @@ -23,14 +23,11 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && VJ_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && VJ_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #ifndef VJ_H #define VJ_H -#include "lwip/ip.h" -#include "lwip/priv/tcp_priv.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/features/netsocket/ppp/mbed_lib.json b/features/netsocket/ppp/mbed_lib.json index 6d1033ad65..7206c58b6b 100644 --- a/features/netsocket/ppp/mbed_lib.json +++ b/features/netsocket/ppp/mbed_lib.json @@ -1,24 +1,35 @@ { "name": "ppp", + "macros": ["NSAPI_PPP_AVAILABLE=(MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED)"], "config": { - "ppp-enabled": { + "enabled": { "help": "Enable support for PPP interfaces", - "value": false, - "macro_name": "NSAPI_PPP_AVAILABLE" + "value": false }, - "ppp-ipv4-enabled": { + "ipv4-enabled": { "help": "Enable support for ipv4 PPP interface", - "value": false, - "macro_name": "PPP_IPV4_SUPPORT" + "value": true }, - "ppp-ipv6-enabled": { + "ipv6-enabled": { "help": "Enable support for ipv6 PPP interface", - "value": true, - "macro_name": "PPP_IPV6_SUPPORT" + "value": false }, - "ppp-thread-stacksize": { + "debug": { + "help": "Enable debug traces for PPP", + "value": false, + "macro_name": "PPP_DEBUG" + }, + "enable-trace": { + "help": "Enable PPP packet traces (traces every outbound and inbound packet)", + "value": false + }, + "thread-stacksize": { "help": "Thread stack size for PPP", "value": 768 + }, + "mbed-event-queue": { + "help": "Use mbed event queue instead of PPP thread", + "value": false } }, "target_overrides": { diff --git a/features/netsocket/ppp/polarssl/lwip_arc4.c b/features/netsocket/ppp/polarssl/ppp_arc4.c similarity index 96% rename from features/netsocket/ppp/polarssl/lwip_arc4.c rename to features/netsocket/ppp/polarssl/ppp_arc4.c index 22edc4c21f..44958e183b 100644 --- a/features/netsocket/ppp/polarssl/lwip_arc4.c +++ b/features/netsocket/ppp/polarssl/ppp_arc4.c @@ -39,7 +39,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_ARC4 +#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_ARC4 #include "polarssl/arc4.h" /* @@ -98,4 +98,4 @@ void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen ) ctx->y = y; } -#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES */ +#endif /* PPP_SUPPORT && PPP_INCLUDED_POLARSSL_DES */ diff --git a/features/netsocket/ppp/polarssl/lwip_des.c b/features/netsocket/ppp/polarssl/ppp_des.c similarity index 99% rename from features/netsocket/ppp/polarssl/lwip_des.c rename to features/netsocket/ppp/polarssl/ppp_des.c index 1ad7f4ca75..091dc314ff 100644 --- a/features/netsocket/ppp/polarssl/lwip_des.c +++ b/features/netsocket/ppp/polarssl/ppp_des.c @@ -40,7 +40,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES +#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_DES #include "polarssl/des.h" @@ -419,4 +419,4 @@ void des_crypt_ecb( des_context *ctx, PUT_ULONG_BE( X, output, 4 ); } -#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES */ +#endif /* PPP_SUPPORT && PPP_INCLUDED_POLARSSL_DES */ diff --git a/features/netsocket/ppp/polarssl/lwip_md4.c b/features/netsocket/ppp/polarssl/ppp_md4.c similarity index 98% rename from features/netsocket/ppp/polarssl/lwip_md4.c rename to features/netsocket/ppp/polarssl/ppp_md4.c index c1f2676430..f662b41213 100644 --- a/features/netsocket/ppp/polarssl/lwip_md4.c +++ b/features/netsocket/ppp/polarssl/ppp_md4.c @@ -40,7 +40,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD4 +#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_MD4 #include "polarssl/md4.h" @@ -278,4 +278,4 @@ void md4( unsigned char *input, int ilen, unsigned char output[16] ) md4_finish( &ctx, output ); } -#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD4 */ +#endif /* PPP_SUPPORT && PPP_INCLUDED_POLARSSL_MD4 */ diff --git a/features/netsocket/ppp/polarssl/lwip_md5.c b/features/netsocket/ppp/polarssl/ppp_md5.c similarity index 97% rename from features/netsocket/ppp/polarssl/lwip_md5.c rename to features/netsocket/ppp/polarssl/ppp_md5.c index d956c7b19b..319b139cfe 100644 --- a/features/netsocket/ppp/polarssl/lwip_md5.c +++ b/features/netsocket/ppp/polarssl/ppp_md5.c @@ -38,12 +38,16 @@ * http://www.ietf.org/rfc/rfc1321.txt */ -#include "ppp_opts.h" -#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD5 - +#include #include "polarssl/md5.h" -#include +/** + * MEMCPY: override this if you have a faster implementation at hand than the + * one included in your C library + */ +#if !defined MEMCPY +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* * 32-bit integer manipulation macros (little endian) @@ -297,4 +301,4 @@ void md5( unsigned char *input, int ilen, unsigned char output[16] ) md5_finish( &ctx, output ); } -#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD5 */ +//#endif /* PPP_SUPPORT && PPP_INCLUDED_POLARSSL_MD5 */ diff --git a/features/netsocket/ppp/polarssl/lwip_sha1.c b/features/netsocket/ppp/polarssl/ppp_sha1.c similarity index 98% rename from features/netsocket/ppp/polarssl/lwip_sha1.c rename to features/netsocket/ppp/polarssl/ppp_sha1.c index dbd708d0d7..fe8553133f 100644 --- a/features/netsocket/ppp/polarssl/lwip_sha1.c +++ b/features/netsocket/ppp/polarssl/ppp_sha1.c @@ -39,7 +39,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_SHA1 +#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_SHA1 #include "polarssl/sha1.h" @@ -332,4 +332,4 @@ void sha1( unsigned char *input, int ilen, unsigned char output[20] ) sha1_finish( &ctx, output ); } -#endif /* PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_SHA1 */ +#endif /* PPP_SUPPORT && PPP_INCLUDED_POLARSSL_SHA1 */ diff --git a/features/netsocket/ppp/ppp_lwip.cpp b/features/netsocket/ppp/ppp_lwip.cpp deleted file mode 100644 index ba74248b6e..0000000000 --- a/features/netsocket/ppp/ppp_lwip.cpp +++ /dev/null @@ -1,466 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mbed.h" -#include -#include "platform/FileHandle.h" -#include "platform/mbed_poll.h" -#include "events/EventQueue.h" -#include "mbed_trace.h" -#define TRACE_GROUP "LPPP" -#include "rtos/Thread.h" -#include "lwip/tcpip.h" -#include "lwip/tcp.h" -#include "lwip/ip.h" -#include "lwip/dns.h" -#include "lwip/pbuf.h" -extern "C" { // "pppos.h" is missing extern C -#include "pppapi.h" -} - -#include "nsapi_ppp.h" -#include "ppp_lwip.h" -#include "LWIPStack.h" - -namespace mbed { - -using rtos::Thread; -using events::EventQueue; - -#if PPP_SUPPORT - -static EventQueue *event_queue; -static Thread *event_thread; -static volatile bool event_queued; -static nsapi_error_t connect_error_code; - -// Just one interface for now -static FileHandle *my_stream; -static OnboardNetworkStack::Interface *my_interface; -static Semaphore ppp_close_sem; -static ppp_pcb *my_ppp_pcb; -static bool ppp_active = false; -static bool blocking_connect = true; -static const char *login; -static const char *pwd; -static Callback connection_status_cb; - -static EventQueue *prepare_event_queue() -{ - if (event_queue) { - return event_queue; - } - - // Should be trying to get a global shared event queue here! - // Shouldn't have to be making a private thread! - - // Only need to queue 2 events. new blows on failure. - event_queue = new EventQueue(2 * EVENTS_EVENT_SIZE, NULL); - event_thread = new Thread(osPriorityNormal, 2*PPP_THREAD_STACK_SIZE, NULL, "ppp"); - - if (event_thread->start(callback(event_queue, &EventQueue::dispatch_forever)) != osOK) { - delete event_thread; - delete event_queue; - return NULL; - } - - return event_queue; -} - -static u32_t ppp_output(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx) -{ - FileHandle *stream = my_stream; - if (!stream) { - return 0; - } - - pollfh fhs; - fhs.fh = stream; - fhs.events = POLLOUT; - - // LWIP expects us to block on write - // File handle will be in non-blocking mode, because of read events. - // Therefore must use poll to achieve the necessary block for writing. - - uint32_t written = 0; - while (len != 0) { - // Block forever until we're selected - don't care about reason we wake; - // return from write should tell us what's up. - poll(&fhs, 1, -1); - // This write will be non-blocking, but blocking would be fine. - ssize_t ret = stream->write(data, len); - if (ret == -EAGAIN) { - continue; - } else if (ret < 0) { - break; - } - written += ret; - data += ret; - len -= ret; - } - -// /tr_debug("> %ld bytes of data written\n", (long) written); - - return written; -} - -static void ppp_link_status(ppp_pcb *pcb, int err_code, void *ctx) -{ - nsapi_error_t mapped_err_code = NSAPI_ERROR_NO_CONNECTION; - - switch (err_code) { - case PPPERR_NONE: - mapped_err_code = NSAPI_ERROR_OK; - tr_info("status_cb: Connected"); -#if PPP_IPV4_SUPPORT - tr_debug(" our_ipaddr = %s", ipaddr_ntoa(&ppp_netif(pcb)->ip_addr)); - tr_debug(" his_ipaddr = %s", ipaddr_ntoa(&ppp_netif(pcb)->gw)); - tr_debug(" netmask = %s", ipaddr_ntoa(&ppp_netif(pcb)->netmask)); -#if LWIP_DNS - const ip_addr_t *ns; - ns = dns_getserver(0, NULL); - if (ns) { - tr_debug(" dns1 = %s", ipaddr_ntoa(ns)); - } - ns = dns_getserver(1, NULL); - if (ns) { - tr_debug(" dns2 = %s", ipaddr_ntoa(ns)); - } -#endif /* LWIP_DNS */ -#endif /* PPP_IPV4_SUPPORT */ -#if PPP_IPV6_SUPPORT - tr_debug(" our6_ipaddr = %s", ip6addr_ntoa(netif_ip6_addr(ppp_netif(pcb), 0))); -#endif /* PPP_IPV6_SUPPORT */ - break; - - case PPPERR_PARAM: - tr_info("status_cb: Invalid parameter"); - break; - - case PPPERR_OPEN: - tr_info("status_cb: Unable to open PPP session"); - break; - - case PPPERR_DEVICE: - tr_info("status_cb: Invalid I/O device for PPP"); - break; - - case PPPERR_ALLOC: - tr_info("status_cb: Unable to allocate resources"); - break; - - case PPPERR_USER: - tr_info("status_cb: User interrupt"); - break; - - case PPPERR_CONNECT: - tr_info("status_cb: Connection lost"); - mapped_err_code = NSAPI_ERROR_CONNECTION_LOST; - break; - - case PPPERR_AUTHFAIL: - tr_info("status_cb: Failed authentication challenge"); - mapped_err_code = NSAPI_ERROR_AUTH_FAILURE; - break; - - case PPPERR_PROTOCOL: - tr_info("status_cb: Failed to meet protocol"); - break; - - case PPPERR_PEERDEAD: - tr_info("status_cb: Connection timeout"); - mapped_err_code = NSAPI_ERROR_CONNECTION_TIMEOUT; - break; - - case PPPERR_IDLETIMEOUT: - tr_info("status_cb: Idle Timeout"); - break; - - case PPPERR_CONNECTTIME: - tr_info("status_cb: Max connect time reached"); - break; - - case PPPERR_LOOPBACK: - tr_info("status_cb: Loopback detected"); - break; - - default: - tr_info("status_cb: Unknown error code %d", err_code); - break; - - } - - if (err_code == PPPERR_NONE) { - /* status changes have to be reported */ - if (connection_status_cb) { - connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_GLOBAL_UP); - } - return; - } - - /* If some error happened, we need to properly shutdown the PPP interface */ - if (ppp_active) { - ppp_active = false; - connect_error_code = mapped_err_code; - ppp_close_sem.release(); - } - - /* Alright, PPP interface is down, we need to notify upper layer */ - if (connection_status_cb) { - connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED); - } -} - -static void handle_modem_hangup() -{ - if (my_ppp_pcb->phase != PPP_PHASE_DEAD) { - ppp_close(my_ppp_pcb, 1); - } -} - -#if !PPP_INPROC_IRQ_SAFE -#error "PPP_INPROC_IRQ_SAFE must be enabled" -#endif -static void ppp_input() -{ - // Allow new events from now, avoiding potential races around the read - event_queued = false; - - if (!my_stream) { - return; - } - - // Non-blocking error check handler - pollfh fhs; - fhs.fh = my_stream; - fhs.events = POLLIN; - poll(&fhs, 1, 0); - if (fhs.revents & (POLLHUP | POLLERR | POLLNVAL)) { - handle_modem_hangup(); - return; - } - - // Infinite loop, but we assume that we can read faster than the - // serial, so we will fairly rapidly hit -EAGAIN. - for (;;) { - u8_t buffer[16]; - ssize_t len = my_stream->read(buffer, sizeof buffer); - if (len == -EAGAIN) { - break; - } else if (len <= 0) { - handle_modem_hangup(); - return; - } - pppos_input(my_ppp_pcb, buffer, len); - } - return; -} - -static void stream_cb() -{ - if (my_stream && !event_queued) { - event_queued = true; - if (event_queue->call(callback(ppp_input)) == 0) { - event_queued = false; - } - } -} - -extern "C" err_t ppp_if_connect(void *pcb) -{ -#if PPP_AUTH_SUPPORT - ppp_set_auth(my_ppp_pcb, PPPAUTHTYPE_ANY, login, pwd); -#endif //PPP_AUTH_SUPPORT - ppp_active = true; - err_t ret = ppp_connect(my_ppp_pcb, 0); - // lwIP's ppp.txt says input must not be called until after connect - if (ret == ERR_OK) { - my_stream->sigio(callback(stream_cb)); - } else { - ppp_active = false; - } - return ret; -} - -extern "C" err_t ppp_if_disconnect(void *pcb) -{ - err_t ret = ERR_OK; - if (ppp_active) { - ret = ppp_close(my_ppp_pcb, 0); - if (ret == ERR_OK) { - /* close call made, now let's catch the response in the status callback */ - ppp_close_sem.wait(); - } - ppp_active = false; - } - return ret; -} - -extern "C" nsapi_error_t ppp_stack_if_init(void *pcb, struct netif *netif, const nsapi_ip_stack_t stack) -{ - if (!prepare_event_queue()) { - return NSAPI_ERROR_NO_MEMORY; - } - - if (!my_ppp_pcb) { - my_ppp_pcb = pppos_create(netif, - ppp_output, ppp_link_status, NULL); - if (!my_ppp_pcb) { - return NSAPI_ERROR_DEVICE_ERROR; - } - - } - -#if LWIP_IPV4 - if (stack != IPV6_STACK) { - ppp_set_usepeerdns(my_ppp_pcb, true); - } -#endif - -#if LWIP_IPV4 && LWIP_IPV6 - if (stack == IPV4_STACK) { - my_ppp_pcb->ipv6cp_disabled = true; - } else if (stack == IPV6_STACK) { - my_ppp_pcb->ipcp_disabled = true; - } -#endif - - return NSAPI_ERROR_OK; -} - -nsapi_error_t nsapi_ppp_error_code() -{ - return connect_error_code; -} - -nsapi_error_t nsapi_ppp_set_blocking(bool blocking) -{ - blocking_connect = blocking; - return NSAPI_ERROR_OK; -} - -nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback cb, const char *uname, const char *password, const nsapi_ip_stack_t stack) -{ - if (my_stream) { - return NSAPI_ERROR_PARAMETER; - } - my_stream = stream; - stream->set_blocking(false); - connection_status_cb = cb; - login = uname; - pwd = password; - - nsapi_error_t retcode; - - if (!my_interface) { - OnboardNetworkStack &_stack = OnboardNetworkStack::get_default_instance(); - retcode = _stack.add_ppp_interface(stream, true, stack, &my_interface); - if (retcode != NSAPI_ERROR_OK) { - my_interface = NULL; - my_stream->set_blocking(true); - my_stream = NULL; - connection_status_cb = NULL; - return retcode; - } - } - - // mustn't start calling input until after connect - - // attach deferred until ppp_connect, called from mbed_lwip_bringup - retcode = my_interface->bringup(false, NULL, NULL, NULL, stack, blocking_connect); - - if (retcode != NSAPI_ERROR_OK) { - connection_status_cb = NULL; - my_stream->sigio(NULL); - my_stream->set_blocking(true); - my_stream = NULL; - } - - if (retcode != NSAPI_ERROR_OK && connect_error_code != NSAPI_ERROR_OK) { - return connect_error_code; - } else { - return retcode; - } -} - -nsapi_error_t nsapi_ppp_disconnect(FileHandle *stream) -{ - if (my_stream != stream) { - return NSAPI_ERROR_NO_CONNECTION; - } - - nsapi_error_t retcode = my_interface->bringdown(); - - connection_status_cb = NULL; - /* Detach callbacks, and put handle back to default blocking mode */ - my_stream->sigio(NULL); - my_stream->set_blocking(true); - my_stream = NULL; - - return retcode; -} - -NetworkStack *nsapi_ppp_get_stack() -{ - return &OnboardNetworkStack::get_default_instance(); -} - -const char *nsapi_ppp_get_ip_addr(FileHandle *stream) -{ - static char ip_addr[IPADDR_STRLEN_MAX]; - - if (stream == my_stream) { - - if (my_interface->get_ip_address(ip_addr, IPADDR_STRLEN_MAX)) { - return ip_addr; - } - } - - return NULL; -} -const char *nsapi_ppp_get_netmask(FileHandle *stream) -{ -#if !LWIP_IPV4 - return NULL; -#endif - - static char netmask[IPADDR_STRLEN_MAX]; - if (stream == my_stream) { - if (my_interface->get_netmask(netmask, IPADDR_STRLEN_MAX)) { - return netmask; - } - } - - return NULL; -} -const char *nsapi_ppp_get_gw_addr(FileHandle *stream) -{ -#if !LWIP_IPV4 - return NULL; -#endif - - static char gwaddr[IPADDR_STRLEN_MAX]; - if (stream == my_stream) { - if (my_interface->get_gateway(gwaddr, IPADDR_STRLEN_MAX)) { - return gwaddr; - } - } - - return NULL; -} - -#endif /* PPP_SUPPORT */ - -} // namespace mbed diff --git a/features/netsocket/ppp/ppp_lwip.h b/features/netsocket/ppp/ppp_lwip.h deleted file mode 100644 index 81f00bb08d..0000000000 --- a/features/netsocket/ppp/ppp_lwip.h +++ /dev/null @@ -1,64 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef PPP_LWIP_H_ -#define PPP_LWIP_H_ -#include "pppapi.h" -#ifdef __cplusplus -extern "C" { -#endif -#if LWIP_PPP_API - -/** Initializes LWIP PPP interface - * - * Starts a private thread for LWIP PPP and turns the PPP interface - * up. - * - * @param netif LWIP netif struct - * - * @return 0 for success and negative error codes for failure - */ -nsapi_error_t ppp_stack_if_init(void *pcb, struct netif *netif, nsapi_ip_stack_t stack); - -/** Connects to a PPP pipe - * - * Called during LWIP interface bringup - * - * @return 0 for success and negative error codes for failure - */ -err_t ppp_if_connect(void *pcb); - -/** Disconnects from a PPP pipe - * - * Can be called from multiple places. If LWIP bringup fails after initializing - * PPP interface, this API kicks in. Formal disconnection occurs when LWIP - * interface is brought down. - * - * @return 0 for success and negative error codes for failure - */ -err_t ppp_if_disconnect(void *pcb); -#else -/** - * Stubs in case LWIP PPP is not enabled - */ -#define ppp_if_init(pcb, netif, stack) NSAPI_ERROR_UNSUPPORTED -#define ppp_if_connect(pcb) ERR_IF -#define ppp_if_disconnect(pcb) ERR_IF -#endif //LWIP_PPP_API -#ifdef __cplusplus -} -#endif - -#endif /* PPP_LWIP_H_ */ diff --git a/features/netsocket/ppp/ppp_nsapi.cpp b/features/netsocket/ppp/ppp_nsapi.cpp new file mode 100644 index 0000000000..e02617da55 --- /dev/null +++ b/features/netsocket/ppp/ppp_nsapi.cpp @@ -0,0 +1,176 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "platform/FileHandle.h" +#include "mbed_trace.h" +#define TRACE_GROUP "PPPNS" +#include "nsapi_ppp.h" +#include "OnboardNetworkStack.h" +#include "netsocket/PPPInterface.h" + +#define IPADDR_STRLEN_MAX 46 + +#if NSAPI_PPP_AVAILABLE + +namespace mbed { + +void nsapi_ppp_close(); + +// Just one interface for now +static FileHandle *my_stream; +static OnboardNetworkStack::Interface *my_interface; +static bool blocking_connect = true; +static const char *login; +static const char *pwd; +static PPP *ppp_service = NULL; +static OnboardNetworkStack *stack; + +nsapi_error_t nsapi_ppp_set_blocking(bool blocking) +{ + blocking_connect = blocking; + return NSAPI_ERROR_OK; +} + +nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback cb, const char *uname, const char *password, const nsapi_ip_stack_t ip_stack) +{ + if (my_stream) { + return NSAPI_ERROR_PARAMETER; + } + + my_stream = stream; + stream->set_blocking(false); + login = uname; + pwd = password; + + nsapi_error_t retcode; + + if (!my_interface) { + ppp_service = &PPP::get_default_instance(); + stack = &OnboardNetworkStack::get_default_instance(); + + ppp_service->set_stream(stream); + ppp_service->set_ip_stack(ip_stack); + ppp_service->set_credentials(uname, password); + + retcode = stack->add_ppp_interface(*ppp_service, true, &my_interface); + + if (retcode != NSAPI_ERROR_OK) { + my_interface = NULL; + nsapi_ppp_close(); + return retcode; + } + + if (cb) { + my_interface->attach(cb); + } + } + + retcode = my_interface->bringup(false, NULL, NULL, NULL, ip_stack, blocking_connect); + + if (retcode != NSAPI_ERROR_OK) { + nsapi_ppp_close(); + } + + return retcode; +} + +nsapi_error_t nsapi_ppp_disconnect(FileHandle *stream) +{ + if (my_stream != stream) { + return NSAPI_ERROR_NO_CONNECTION; + } + + nsapi_error_t retcode = my_interface->bringdown(); + + nsapi_ppp_close(); + + return retcode; +} + +void nsapi_ppp_close() +{ + if (my_interface) { + stack->remove_ppp_interface(&my_interface); + my_interface = NULL; + } + + stack = NULL; + + if (ppp_service) { + ppp_service->set_stream(NULL); + ppp_service->set_ip_stack(DEFAULT_STACK); + ppp_service->set_credentials(NULL, NULL); + ppp_service = NULL; + } + + /* Detach callbacks, and put handle back to default blocking mode */ + my_stream->sigio(NULL); + my_stream->set_blocking(true); + my_stream = NULL; +} + +NetworkStack *nsapi_ppp_get_stack() +{ + return &OnboardNetworkStack::get_default_instance(); +} + +const char *nsapi_ppp_get_ip_addr(FileHandle *stream) +{ + static char ip_addr[IPADDR_STRLEN_MAX]; + + if (stream == my_stream) { + if (my_interface->get_ip_address(ip_addr, IPADDR_STRLEN_MAX)) { + return ip_addr; + } + } + + return NULL; +} +const char *nsapi_ppp_get_netmask(FileHandle *stream) +{ +#if !PPP_IPV4_SUPPORT + return NULL; +#endif + + static char netmask[IPADDR_STRLEN_MAX]; + if (stream == my_stream) { + if (my_interface->get_netmask(netmask, IPADDR_STRLEN_MAX)) { + return netmask; + } + } + + return NULL; +} +const char *nsapi_ppp_get_gw_addr(FileHandle *stream) +{ +#if !PPP_IPV4_SUPPORT + return NULL; +#endif + + static char gwaddr[IPADDR_STRLEN_MAX]; + if (stream == my_stream) { + if (my_interface->get_gateway(gwaddr, IPADDR_STRLEN_MAX)) { + return gwaddr; + } + } + + return NULL; +} + +} // namespace mbed + +#endif diff --git a/features/netsocket/ppp/ppp_service.cpp b/features/netsocket/ppp/ppp_service.cpp new file mode 100644 index 0000000000..3f30c190a4 --- /dev/null +++ b/features/netsocket/ppp/ppp_service.cpp @@ -0,0 +1,679 @@ +/* + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "mbed_interface.h" +#include "mbed_trace.h" +#include "netsocket/nsapi_types.h" + +#if PPP_MBED_EVENT_QUEUE +#include "mbed_shared_queues.h" +#else +#include "Thread.h" +#include "EventQueue.h" +#endif + +#include "mbed_poll.h" +#include "ip4string.h" +#include "ip6string.h" +#include "ppp_service.h" + +#include "ppp_opts.h" +#include "ppp_service_if.h" + +extern "C" { // "pppos.h" is missing extern C +#include "pppos.h" +#include "ppp_impl.h" +} + +#define TRACE_GROUP "ppp_serv" + +#define PPP_SERVICE_IF_NAME "pp" + +#if PPP_SUPPORT + +#if PPP_DEBUG || PPP_TRACE_ENABLE +// PPP internal traces enabled +#define PPP_THREAD_STACKSIZE MBED_CONF_PPP_THREAD_STACKSIZE * 3 +#elif MBED_DEBUG +// Compiled with debug enabled +#define PPP_THREAD_STACKSIZE MBED_CONF_PPP_THREAD_STACKSIZE * 2 +#else +#define PPP_THREAD_STACKSIZE MBED_CONF_PPP_THREAD_STACKSIZE +#endif + +/* Timeout to wait for PPP connection to be terminated + * (LCP Terminate-Request is answered with Terminate-Ack) + */ +#define PPP_TERMINATION_TIMEOUT 30000 + +// If both IPCP and IPCP6 are made, how long to wait for both to complete +#define PPP_IPCP_IPCP6_DELAY 5000 + +bool ppp_service::prepare_event_queue() +{ +#if PPP_MBED_EVENT_QUEUE + ppp_service_event_queue = mbed::mbed_event_queue(); + if (!ppp_service_event_queue) { + return false; + } + + return true; +#else + static events::EventQueue *event_queue = NULL; + static rtos::Thread *event_thread = NULL; + // Already prepared + if (event_queue && event_thread) { + return true; + } + + // Used for incoming data, timers, link status callback, power up callback + event_queue = new events::EventQueue(10 * EVENTS_EVENT_SIZE, NULL); + event_thread = new rtos::Thread(osPriorityNormal, PPP_THREAD_STACKSIZE, NULL, "ppp"); + + if (event_thread->start(callback(event_queue, &events::EventQueue::dispatch_forever)) != osOK) { + delete event_thread; + delete event_queue; + return false; + } + + ppp_service_event_queue = event_queue; + + return true; +#endif +} + +uint32_t ppp_output(struct ppp_pcb_s *pcb, uint8_t *data, uint32_t len, void *ctx) +{ +#if PPP_TRACE_ENABLE + ppp_trace_to_ascii_hex_dump(OUTPUT_BUFFER, len, reinterpret_cast(data)); + ppp_trace_to_ascii_hex_dump_print(OUTPUT_BUFFER); +#endif + + mbed::FileHandle *stream = (mbed::FileHandle *) pcb->netif->stream; + if (!stream) { + return 0; + } + + mbed::pollfh fhs; + fhs.fh = stream; + fhs.events = POLLOUT; + + // stack expects us to block on write + // File handle will be in non-blocking mode, because of read events. + // Therefore must use poll to achieve the necessary block for writing. + + uint32_t written = 0; + + while (len != 0) { + // Block forever until we're selected - don't care about reason we wake; + // return from write should tell us what's up. + poll(&fhs, 1, -1); + // This write will be non-blocking, but blocking would be fine. + ssize_t ret = stream->write(data, len); + if (ret == -EAGAIN) { + continue; + } else if (ret < 0) { + break; + } + written += ret; + data += ret; + len -= ret; + } + + return written; +} + +#if !PPP_INPROC_IRQ_SAFE +#error "PPP_INPROC_IRQ_SAFE must be enabled" +#endif +void ppp_service::ppp_input() +{ + // Allow new events from now, avoiding potential races around the read + ppp_service_event_queued = false; + + if (!ppp_service_stream) { + return; + } + + // Non-blocking error check handler + mbed::pollfh fhs; + fhs.fh = ppp_service_stream; + fhs.events = POLLIN; + poll(&fhs, 1, 0); + if (fhs.revents & (POLLHUP | POLLERR | POLLNVAL)) { + ppp_handle_modem_hangup(); + return; + } + + // Infinite loop, but we assume that we can read faster than the + // serial, so we will fairly rapidly hit -EAGAIN. + for (;;) { + u8_t buffer[16]; + + ssize_t len = ppp_service_stream->read(buffer, sizeof buffer); + + if (len == -EAGAIN) { + break; + } else if (len <= 0) { + ppp_handle_modem_hangup(); + return; + } + +#if PPP_TRACE_ENABLE + ppp_trace_to_ascii_hex_dump(INPUT_BUFFER, len, reinterpret_cast(buffer)); +#endif + + pppos_input(static_cast(ppp_service_pcb), buffer, len); + } +} + +void ppp_service::ppp_stream_sigio_callback() +{ + if (ppp_service_stream && !ppp_service_event_queued) { + ppp_service_event_queued = true; + if (ppp_service_event_queue->call(mbed::callback(this, &ppp_service::ppp_input)) == 0) { + ppp_service_event_queued = false; + } + } +} + +void ppp_service::ppp_handle_modem_hangup() +{ + ppp_pcb *pcb = static_cast(ppp_service_pcb); + + if (pcb->phase != PPP_PHASE_DEAD) { + ppp_close(pcb, 1); + } +} + +void ppp_service::ppp_link_status(struct ppp_pcb_s *pcb, int err_code, void *ctx) +{ + ppp_service *ppp_service_ptr = static_cast(pcb->netif->service_ptr); + + switch (err_code) { + case PPPERR_NONE: +#if PPP_DEBUG + PPPDEBUG(LOG_DEBUG, ("status_cb: Connected")); + char address[40]; +#if PPP_IPV4_SUPPORT + ip4tos(pcb->netif->ipv4_addr.bytes, address); + PPPDEBUG(LOG_DEBUG, (" our_ipaddr = %s", address)); + ip4tos(pcb->netif->ipv4_gateway.bytes, address); + PPPDEBUG(LOG_DEBUG, (" his_ipaddr = %s", address)); + ip4tos(pcb->netif->ipv4_netmask.bytes, address); + PPPDEBUG(LOG_DEBUG, (" netmask = %s", address)); + if (pcb->netif->ipv4_dns_server[0].version == NSAPI_IPv4) { + ip4tos(pcb->netif->ipv4_dns_server[0].bytes, address); + PPPDEBUG(LOG_DEBUG, (" dns1 = %s", address)); + } + if (pcb->netif->ipv4_dns_server[1].version == NSAPI_IPv4) { + ip4tos(pcb->netif->ipv4_dns_server[1].bytes, address); + PPPDEBUG(LOG_DEBUG, (" dns2 = %s", address)); + } +#endif /* PPP_IPV4_SUPPORT */ +#if PPP_IPV6_SUPPORT + ip6tos(pcb->netif->ipv6_addr.bytes, address); + PPPDEBUG(LOG_DEBUG, (" our6_ipaddr = %s", address)); +#endif /* PPP_IPV6_SUPPORT */ +#endif + break; + + case PPPERR_PARAM: + PPPDEBUG(LOG_DEBUG, ("status_cb: Invalid parameter")); + break; + + case PPPERR_OPEN: + PPPDEBUG(LOG_DEBUG, ("status_cb: Unable to open PPP session")); + break; + + case PPPERR_DEVICE: + PPPDEBUG(LOG_DEBUG, ("status_cb: Invalid I/O device for PPP")); + break; + + case PPPERR_ALLOC: + PPPDEBUG(LOG_DEBUG, ("status_cb: Unable to allocate resources")); + break; + + case PPPERR_USER: + PPPDEBUG(LOG_DEBUG, ("status_cb: User interrupt")); + break; + + case PPPERR_CONNECT: + PPPDEBUG(LOG_DEBUG, ("status_cb: Connection lost")); + break; + + case PPPERR_AUTHFAIL: + PPPDEBUG(LOG_DEBUG, ("status_cb: Failed authentication challenge")); + break; + + case PPPERR_PROTOCOL: + PPPDEBUG(LOG_DEBUG, ("status_cb: Failed to meet protocol")); + break; + + case PPPERR_PEERDEAD: + PPPDEBUG(LOG_DEBUG, ("status_cb: Connection timeout")); + break; + + case PPPERR_IDLETIMEOUT: + PPPDEBUG(LOG_DEBUG, ("status_cb: Idle Timeout")); + break; + + case PPPERR_CONNECTTIME: + PPPDEBUG(LOG_DEBUG, ("status_cb: Max connect time reached")); + break; + + case PPPERR_LOOPBACK: + PPPDEBUG(LOG_DEBUG, ("status_cb: Loopback detected")); + break; + + default: + PPPDEBUG(LOG_DEBUG, ("status_cb: Unknown error code %d", err_code)); + break; + } + + if (err_code == PPPERR_NONE) { + return; + } + + /* If some error happened, we need to properly shutdown the PPP interface */ + if (ppp_service_ptr->ppp_service_active) { + ppp_service_ptr->ppp_service_active = false; + ppp_service_ptr->ppp_service_close_sem.release(); + } +} + +nsapi_error_t ppp_service::ppp_stack_if_init() +{ + ppp_init(); + + if (!ppp_service_pcb) { + ppp_service_pcb = pppos_create(static_cast(ppp_service_netif), + ppp_output, ppp_link_status, NULL); + if (!ppp_service_pcb) { + return NSAPI_ERROR_DEVICE_ERROR; + } + } + +#if PPP_IPV4_SUPPORT + ppp_pcb *pcb = static_cast(ppp_service_pcb); + +#if PPP_IPV6_SUPPORT + if (ppp_service_stack != IPV6_STACK) { + ppp_set_usepeerdns(pcb, true); + } +#else + ppp_set_usepeerdns(pcb, true); +#endif +#endif + +#if PPP_IPV4_SUPPORT && PPP_IPV6_SUPPORT + if (ppp_service_stack == IPV4_STACK) { + pcb->ipv6cp_disabled = true; + } else if (ppp_service_stack == IPV6_STACK) { + pcb->ipcp_disabled = true; + } +#endif + return NSAPI_ERROR_OK; +} + +nsapi_error_t ppp_service::ppp_if_connect() +{ + ppp_pcb *pcb = static_cast(ppp_service_pcb); + +#if PPP_AUTH_SUPPORT + ppp_set_auth(pcb, PPPAUTHTYPE_ANY, ppp_service_uname, ppp_service_password); +#endif //PPP_AUTH_SUPPORT + ppp_service_active = true; + ppp_service_terminating = false; + err_t ret = ppp_connect(pcb, 0); + // input must not be called until after connect + if (ret == ERR_OK) { + ppp_service_stream->sigio(mbed::callback(this, &ppp_service::ppp_stream_sigio_callback)); + } else { + ppp_service_active = false; + } + + return ret; +} + +nsapi_error_t ppp_service::ppp_if_disconnect() +{ + ppp_pcb *pcb = static_cast(ppp_service_pcb); + + err_t ret = ERR_OK; + if (ppp_service_active) { + ppp_service_terminating = true; + ret = ppp_close(pcb, 0); + if (ret == ERR_OK) { + /* close call made, now let's catch the response in the status callback */ + ppp_service_close_sem.try_acquire_for(PPP_TERMINATION_TIMEOUT); + } + ppp_service_active = false; + } + return ret; +} + +ppp_service::ppp_service() +{ + ppp_service_stream = NULL; + ppp_service_event_queue = NULL; + + ppp_service_netif = static_cast(malloc(sizeof(netif))); + if (ppp_service_netif) { + memset(ppp_service_netif, 0, sizeof(netif)); + ppp_service_netif->service_ptr = static_cast(this); + } + + ppp_service_pcb = NULL; + ppp_service_stack = IPV4_STACK; + ppp_service_uname = NULL; + ppp_service_password = NULL; + memory_manager = NULL; + ppp_service_active = false; + ppp_service_event_queued = false; + ppp_service_terminating = false; + ppp_link_state_up = false; +} + +bool ppp_service::link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack) +{ + netif *serv_netif = static_cast(ppp_service_netif); + + if (ppp_service_terminating) { + memory_manager->free(buf); + return true; + } + + struct pbuf *p = static_cast(ppp_memory_buffer_convert_to(memory_manager, buf)); + if (!p) { + memory_manager->free(buf); + return true; + } + +#if PPP_IPV4_SUPPORT && PPP_IPV6_SUPPORT + if (ip_stack == IPV4_STACK) { + serv_netif->output(serv_netif, p, NULL); + } else { + serv_netif->output_ip6(serv_netif, p, NULL); + } +#elif PPP_IPV4_SUPPORT + serv_netif->output(serv_netif, p, NULL); +#elif PPP_IPV6_SUPPORT + serv_netif->output_ip6(serv_netif, p, NULL); +#endif + + ppp_memory_buffer_free(p); // Not done on PPP lower layers + return true; +} + +bool ppp_service::power_up() +{ + if (!ppp_service_netif || !ppp_service_stream) { + return false; + } + + if (!prepare_event_queue()) { + return false; + } + + if (ppp_service_event_queue->call(mbed::callback(this, &ppp_service::power_up_call)) == 0) { + return false; + } + + return true; +} + +void ppp_service::power_up_call() +{ + nsapi_error_t err = ppp_stack_if_init(); + + if (err != NSAPI_ERROR_OK) { + return; + } + + err = ppp_if_connect(); + + if (err != NSAPI_ERROR_OK) { + return; + } +} + +uint32_t ppp_service::get_mtu_size() +{ + if (!ppp_service_netif) { + return 0; + } + + netif *serv_netif = static_cast(ppp_service_netif); + return serv_netif->mtu; +} + +uint32_t ppp_service::get_align_preference() const +{ + return 0; +} + +void ppp_service::get_ifname(char *name, uint8_t size) const +{ + memcpy(name, PPP_SERVICE_IF_NAME, (size < sizeof(PPP_SERVICE_IF_NAME)) ? size : sizeof(PPP_SERVICE_IF_NAME)); +} + +void ppp_service::set_link_input_cb(ppp_link_input_cb_t input_cb) +{ + ppp_link_input_cb = input_cb; +} + +void ppp_service::set_link_state_cb(ppp_link_state_change_cb_t state_cb) +{ + ppp_link_state_cb = state_cb; +} + +void ppp_service::power_down() +{ + ppp_if_disconnect(); +} + +void ppp_service::set_memory_manager(NetStackMemoryManager &mem_mngr) +{ + memory_manager = &mem_mngr; + + if (!ppp_service_netif) { + return; + } + ppp_service_netif->memory_manager = &mem_mngr; +} + +void ppp_service::set_stream(mbed::FileHandle *stream) +{ + ppp_service_stream = stream; + if (!ppp_service_netif) { + return; + } + ppp_service_netif->stream = stream; +} + +void ppp_service::set_ip_stack(nsapi_ip_stack_t ip_stack) +{ + ppp_service_stack = ip_stack; +} + +void ppp_service::set_credentials(const char *uname, const char *password) +{ + if (strlen(uname) > 0) { + ppp_service_uname = uname; + } else { + ppp_service_uname = NULL; + } + if (strlen(password) > 0) { + ppp_service_password = password; + } else { + password = NULL; + } +} + +const nsapi_addr_t *ppp_service::get_ip_address(nsapi_version_t version) +{ +#if PPP_IPV6_SUPPORT || PPP_IPV4_SUPPORT + netif *serv_netif = static_cast(ppp_service_netif); +#endif + +#if PPP_IPV6_SUPPORT + if (version == NSAPI_IPv6 && serv_netif->ipv6_addr.version == NSAPI_IPv6) { + return &serv_netif->ipv6_addr; + } +#endif + +#if PPP_IPV4_SUPPORT + if (version == NSAPI_IPv4 && serv_netif->ipv4_addr.version == NSAPI_IPv4) { + return &serv_netif->ipv4_addr; + } +#endif + + return NULL; +} + +const nsapi_addr_t *ppp_service::get_netmask() +{ +#if PPP_IPV4_SUPPORT + if (ppp_service_netif->ipv4_netmask.version == NSAPI_IPv4) { + return &ppp_service_netif->ipv4_netmask; + } +#endif + + return NULL; +} + +const nsapi_addr_t *ppp_service::get_gateway() +{ +#if PPP_IPV4_SUPPORT + if (ppp_service_netif->ipv4_gateway.version == NSAPI_IPv4) { + return &ppp_service_netif->ipv4_gateway; + } +#endif + + return NULL; +} + +const nsapi_addr_t *ppp_service::get_dns_server(uint8_t index) +{ +#if PPP_IPV4_SUPPORT + if (index > 1) { + return NULL; + } + if (ppp_service_netif->ipv4_dns_server[index].version == NSAPI_IPv4) { + return &ppp_service_netif->ipv4_dns_server[index]; + } +#endif + + return NULL; +} + +void ppp_service::link_state(bool up) +{ + if (!ppp_service_active) { + return; + } + + bool call_link_state = false; +#if PPP_IPV4_SUPPORT && PPP_IPV6_SUPPORT + bool callin_link_state = false; + if (ppp_service_stack == IPV4V6_STACK) { + if (up) { + if (ppp_service_netif->ipv4_up && ppp_service_netif->ipv6_up) { + call_link_state = true; + } else { + callin_link_state = true; + } + } else { + call_link_state = true; + } + } else { + call_link_state = true; + } +#else + call_link_state = true; +#endif + + if (call_link_state) { + if (ppp_service_event_queue->call(mbed::callback(this, &ppp_service::link_state_call), up) == 0) { + return; + } + } +#if PPP_IPV4_SUPPORT && PPP_IPV6_SUPPORT + if (callin_link_state) { + if (ppp_service_event_queue->call_in(PPP_IPCP_IPCP6_DELAY, mbed::callback(this, &ppp_service::link_state_call), up) == 0) { + return; + } + } +#endif +} + +void ppp_service::link_state_call(bool up) +{ + if (ppp_link_state_up != up) { + ppp_link_state_up = up; + ppp_link_state_cb(up); + } +} + +void ppp_service::link_input(net_stack_mem_buf_t *buf) +{ + if (ppp_service_terminating) { + memory_manager->free(buf); + return; + } + + ppp_link_input_cb(buf); +} + +events::EventQueue *ppp_service::event_queue_get() +{ + return ppp_service_event_queue; +} + +void ppp_service::resource_lock() +{ + ppp_service_mutex.lock(); +} + +void ppp_service::resource_unlock() +{ + ppp_service_mutex.unlock(); +} + +ppp_service &ppp_service::get_instance() +{ + static ppp_service ppp_service_instance; + return ppp_service_instance; +} + +// Weak so a module can override +MBED_WEAK PPP &PPP::get_default_instance() +{ + return ppp_service::get_instance(); +} + +#endif + +/** + * @} + */ + +/* --------------------------------- End Of File ------------------------------ */ + diff --git a/features/netsocket/ppp/ppp_service.h b/features/netsocket/ppp/ppp_service.h new file mode 100644 index 0000000000..56c81ac4de --- /dev/null +++ b/features/netsocket/ppp/ppp_service.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PPP_SERVICE_H +#define PPP_SERVICE_H + +#include +#include "Callback.h" +#include "Semaphore.h" +#include "NetStackMemoryManager.h" +#include "FileHandle.h" +#include "events/EventQueue.h" +#include "netsocket/PPP.h" + +/** + * This interface should be used to abstract low level access to networking hardware + * All operations receive a `void *` hardware pointer which an ppp device provides when + * it is registered with a stack. + */ +class ppp_service : public PPP { +public: + ppp_service(); + + static ppp_service &get_instance(); + + /** + * Callback to be registered with PPP interface and to be called for received packets + * + * @param buf Received data + */ + //typedef void (*ppp_link_input_fn)(void *data, net_stack_mem_buf_t *buf); + typedef mbed::Callback ppp_link_input_cb_t; + + /** + * Callback to be registered with PPP interface and to be called for link status changes + * + * @param up Link status + */ + //typedef void (*ppp_link_state_change_fn)(void *data, bool up); + typedef mbed::Callback ppp_link_state_change_cb_t; + + /** + * Return maximum transmission unit + * + * @return MTU in bytes + */ + virtual uint32_t get_mtu_size(); + + /** + * Gets memory buffer alignment preference + * + * Gets preferred memory buffer alignment of the ppp device. + * @return Memory alignment requirement in bytes + */ + virtual uint32_t get_align_preference() const; + + /** + * Return interface name + * + * @param name Pointer to where the name should be written + * @param size Maximum number of characters to copy + */ + virtual void get_ifname(char *name, uint8_t size) const; + + /** + * Sends the packet over the link + * + * That cannot be called from an interrupt context. + * + * @param buf Packet to be send + * @return True if the packet was send successfully, false otherwise + */ + virtual bool link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack); + + /** + * Initializes the hardware + * + * @return True on success, False in case of an error. + */ + virtual bool power_up(); + /** + * Deinitializes the hardware + * + */ + virtual void power_down(); + + /** + * Sets a callback that needs to be called for packets received for that interface + * + * @param input_cb Function to be register as a callback + */ + virtual void set_link_input_cb(ppp_link_input_cb_t input_cb); + + /** + * Sets a callback that needs to be called on link status changes for given interface + * + * @param state_cb Function to be register as a callback + */ + virtual void set_link_state_cb(ppp_link_state_change_cb_t state_cb); + + /** Sets memory manager that is used to handle memory buffers + * + * @param mem_mngr Pointer to memory manager + */ + virtual void set_memory_manager(NetStackMemoryManager &mem_mngr); + + /** Sets file stream used to communicate with modem + * + * @param stream Pointer to file handle + */ + virtual void set_stream(mbed::FileHandle *stream); + + /** Sets IP protocol versions of IP stack + * + * @param ip_stack IP protocol version + */ + virtual void set_ip_stack(nsapi_ip_stack_t ip_stack); + + /** Sets user name and password for PPP protocol + * + * @param uname User name + * @param password Password + */ + virtual void set_credentials(const char *uname, const char *password); + + /** Gets local IP address + * + * @param version IP address version + * @return IP address + */ + virtual const nsapi_addr_t *get_ip_address(nsapi_version_t version); + + /** Get the local network mask. + * + * @return Local network mask or null if no network mask has been received. + */ + virtual const nsapi_addr_t *get_netmask(); + + /** Get the local gateway. + * + * @return Local gateway or null if no network mask has been received. + */ + virtual const nsapi_addr_t *get_gateway(); + + /** Gets DNS server address + * + * @param index Server index + */ + virtual const nsapi_addr_t *get_dns_server(uint8_t index); + + /** Link state indication from PPP + * + * @param up Link status + */ + virtual void link_state(bool up); + + /** Received IP packet from PPP to stack + * + * @param buf Received packet + */ + virtual void link_input(net_stack_mem_buf_t *buf); + + /** Handle to PPP event queue + * + * @return Event queue + */ + virtual events::EventQueue *event_queue_get(); + + /** Lock PPP resource + * + */ + virtual void resource_lock(); + + /** Unlock PPP resource + * + */ + virtual void resource_unlock(); + +private: + + // PPP library interface to service + bool prepare_event_queue(); + void ppp_input(); + void ppp_stream_sigio_callback(); + void ppp_handle_modem_hangup(); + static void ppp_link_status(struct ppp_pcb_s *pcb, int err_code, void *ctx); + void power_up_call(); + void link_state_call(bool up); + + // PPP status functions + nsapi_error_t ppp_stack_if_init(); + nsapi_error_t ppp_if_connect(); + nsapi_error_t ppp_if_disconnect(); + + // Internal data + mbed::FileHandle *ppp_service_stream; + rtos::Semaphore ppp_service_close_sem; + rtos::Mutex ppp_service_mutex; + events::EventQueue *ppp_service_event_queue; + NetStackMemoryManager *memory_manager; /**< Memory manager */ + ppp_link_input_cb_t ppp_link_input_cb; /**< Callback for incoming data */ + ppp_link_state_change_cb_t ppp_link_state_cb; /**< Link state change callback */ + + struct netif *ppp_service_netif; + void *ppp_service_pcb; + nsapi_ip_stack_t ppp_service_stack; + const char *ppp_service_uname; + const char *ppp_service_password; + nsapi_error_t ppp_service_connect_error_code; + bool ppp_service_active : 1; + bool ppp_service_event_queued : 1; + bool ppp_service_terminating : 1; + bool ppp_link_state_up : 1; +}; + +#endif /* PPP_SERVICE_H */ diff --git a/features/netsocket/ppp/ppp_service_if.cpp b/features/netsocket/ppp/ppp_service_if.cpp new file mode 100644 index 0000000000..7b983e2840 --- /dev/null +++ b/features/netsocket/ppp/ppp_service_if.cpp @@ -0,0 +1,579 @@ +/* + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "mbed_interface.h" +#include "mbed_trace.h" +#include "netsocket/nsapi_types.h" +#include "mbed_shared_queues.h" +#include "mbed_poll.h" +#include "ip4string.h" +#include "ip6string.h" +#include "ppp_service.h" +#include "ppp_impl.h" + +#if PPP_SUPPORT + +#define TRACE_GROUP "ppp_serv_if" + +typedef void (*ppp_sys_timeout_handler)(void *arg); + +// Number of timers running simultaneous +#define PPP_TIMER_NUM 5 +// Number of simultaneous memory buffers +#define PPP_PBUF_HANDLE_NUM 10 + +typedef struct { + ppp_service *ppp_drv; + ppp_sys_timeout_handler handler; + void *arg; + int equeue_id; + uint8_t id; +} ppp_sys_timeout_t; + +static ppp_sys_timeout_t *timeout[PPP_TIMER_NUM]; +static SingletonPtr ppp_service_if_mutex; +static uint8_t ppp_service_sys_timeout_id = 0; +static pbuf pbuf_handles[PPP_PBUF_HANDLE_NUM]; + +#if PPP_TRACE_ENABLE +#define OUTPUT_BUFFER 0 +#define INPUT_BUFFER 1 + +#define BUFFER_SIZE 5000 + +typedef struct { + char buffer[BUFFER_SIZE]; + int buffer_index = 0; + int line_len = 0; +} trace_buf_t; + +static trace_buf_t output_trace_buffer; +static trace_buf_t input_trace_buffer; + +#if PPP_TRACE_BUFFER_SIZE > 0 +static char cont_trace_buffer[PPP_TRACE_BUFFER_SIZE]; +static int cont_trace_buffer_index = 0; +#endif +#endif + +#if BYTE_ORDER == LITTLE_ENDIAN +#if !defined(ppp_htons) +/** + * Convert an u16_t from host- to network byte order. + * + * @param n u16_t in host byte order + * @return n in network byte order + */ +uint16_t ppp_htons(uint16_t n) +{ + return PP_HTONS(n); +} +#endif /* ppp_htons */ + +#if !defined(ppp_htonl) +/** + * Convert an u32_t from host- to network byte order. + * + * @param n u32_t in host byte order + * @return n in network byte order + */ +uint32_t ppp_htonl(uint32_t n) +{ + return PP_HTONL(n); +} +#endif /* ppp_htonl */ + +#endif /* BYTE_ORDER == LITTLE_ENDIAN */ + +extern "C" { + + void ppp_ip4_addr_set(nsapi_addr_t *addr, uint32_t *src) + { + memset(addr->bytes, 0, NSAPI_IP_BYTES); + memcpy(addr->bytes, src, 4); + addr->version = NSAPI_IPv4; + } + + struct netif *ppp_netif_add(struct netif *netif, void *state, netif_init_fn init) + { +#if PPP_IPV4_SUPPORT + netif->output = NULL; + netif->ipv4_up = false; +#endif /* PPP_IPV4_SUPPORT */ +#if PPP_IPV6_SUPPORT + netif->output_ip6 = NULL; + netif->ipv6_up = false; +#endif + netif->mtu = 0; + netif->input = NULL; + netif->state = state; + + /* call user specified initialization function for netif */ + if (init(netif) != ERR_OK) { + return NULL; + } + + return netif; + } + + err_t ppp_ip_input(struct pbuf *p, struct netif *inp) + { + ppp_service *ppp_service_ptr = static_cast(inp->service_ptr); + void *buffer = ppp_memory_buffer_convert_from(p); + ppp_service_ptr->link_input(static_cast(buffer)); + return ERR_OK; + } + + void ppp_set_link_up(struct netif *netif) + { + ppp_service *ppp_service_ptr = static_cast(netif->service_ptr); + ppp_service_ptr->link_state(true); + } + + void ppp_set_link_down(struct netif *netif) + { + ppp_service *ppp_service_ptr = static_cast(netif->service_ptr); + ppp_service_ptr->link_state(false); + } + + err_t ppp_call_callback(void *service_ptr, ppp_service_cb callback, void *arg) + { + ppp_service *ppp_service_ptr = static_cast(service_ptr); + + int unique_id = ppp_service_ptr->event_queue_get()->call(mbed::callback(callback, arg)); + if (unique_id == 0) { + return ERR_MEM; + } + + return ERR_OK; + } + + pbuf *ppp_memory_buffer_allocate(void *memory_manager, uint16_t size, ppp_buf_type_e type) + { + ppp_service_if_mutex->lock(); + + int8_t free_index = -1; + for (int8_t index = 0; index < PPP_PBUF_HANDLE_NUM; index++) { + if (pbuf_handles[index].buffer == NULL) { + free_index = index; + break; + } + } + + if (free_index < 0) { + ppp_service_if_mutex->unlock(); + return NULL; + } + + NetStackMemoryManager *mem_mngr = static_cast(memory_manager); + + void *buffer; + if (type == PPP_BUF_HEAP) { + buffer = mem_mngr->alloc_heap(size, 0); + } else { + buffer = mem_mngr->alloc_pool(size, 0); + } + + if (!buffer) { + ppp_service_if_mutex->unlock(); + return NULL; + } + + // Must be continuous buffer from pool on alloc + if (mem_mngr->get_next(buffer) != NULL) { + mem_mngr->free(buffer); + ppp_service_if_mutex->unlock(); + return NULL; + } + + pbuf_handles[free_index].next = NULL; + pbuf_handles[free_index].buffer = buffer; + pbuf_handles[free_index].memory_manager = memory_manager; + pbuf_handles[free_index].payload = static_cast(mem_mngr->get_ptr(buffer)); + pbuf_handles[free_index].len = size; + pbuf_handles[free_index].tot_len = size; + pbuf_handles[free_index].payload_start = pbuf_handles[free_index].payload; + + ppp_service_if_mutex->unlock(); + + return &pbuf_handles[free_index]; + } + + void ppp_memory_buffer_free(pbuf *buffer) + { + ppp_service_if_mutex->lock(); + + int8_t buffer_index = -1; + for (int8_t index = 0; index < PPP_PBUF_HANDLE_NUM; index++) { + if (&pbuf_handles[index] == buffer) { + buffer_index = index; + break; + } + } + + if (buffer_index < 0) { + ppp_service_if_mutex->unlock(); + return; + } + + if (pbuf_handles[buffer_index].buffer != NULL) { + NetStackMemoryManager *mem_mngr = static_cast(pbuf_handles[buffer_index].memory_manager); + mem_mngr->free(pbuf_handles[buffer_index].buffer); + } + + memset(&pbuf_handles[buffer_index], 0, sizeof(pbuf)); + + ppp_service_if_mutex->unlock(); + } + + uint16_t ppp_memory_buffer_pool_alloc_unit_get(void *memory_manager) + { + NetStackMemoryManager *mem_mngr = static_cast(memory_manager); + return mem_mngr->get_pool_alloc_unit(0); + } + + void ppp_memory_buffer_cat(void *memory_manager, pbuf *to_buf, pbuf *cat_buf) + { + for (struct pbuf *buf = to_buf; buf != NULL; buf = buf->next) { + if (buf->next == NULL) { + buf->next = cat_buf; + break; + } + } + } + + void ppp_memory_buffer_set_len(void *memory_manager, pbuf *buf, uint16_t len) + { + NetStackMemoryManager *mem_mngr = static_cast(memory_manager); + mem_mngr->set_len(buf->buffer, len); + } + + struct pbuf *ppp_memory_buffer_convert_to(void *memory_manager, net_stack_mem_buf_t *mem_buf) + { + ppp_service_if_mutex->lock(); + + int8_t free_index = -1; + for (int8_t index = 0; index < PPP_PBUF_HANDLE_NUM; index++) { + if (pbuf_handles[index].buffer == NULL) { + free_index = index; + break; + } + } + + if (free_index < 0) { + ppp_service_if_mutex->unlock(); + return NULL; + } + + NetStackMemoryManager *mem_mngr = static_cast(memory_manager); + + pbuf_handles[free_index].buffer = mem_buf; + pbuf_handles[free_index].memory_manager = memory_manager; + pbuf_handles[free_index].payload = mem_mngr->get_ptr(mem_buf); + pbuf_handles[free_index].len = mem_mngr->get_len(mem_buf); + pbuf_handles[free_index].tot_len = mem_mngr->get_total_len(mem_buf); + pbuf_handles[free_index].payload_start = pbuf_handles[free_index].payload; + + ppp_service_if_mutex->unlock(); + + return &pbuf_handles[free_index]; + } + + net_stack_mem_buf_t *ppp_memory_buffer_convert_from(struct pbuf *p) + { + NetStackMemoryManager *mem_mngr = static_cast(p->memory_manager); + + net_stack_mem_buf_t *first_buffer = p->buffer; + + struct pbuf *buf_next; + for (struct pbuf *buf = p; buf != NULL; buf = buf_next) { + + // Set actual memory buffer length + mem_mngr->set_len(buf->buffer, buf->len); + + // Trim the headroom away from buffer if set + if (buf->payload_start < buf->payload) { + memmove(buf->payload_start, buf->payload, buf->len); + } + + buf_next = buf->next; + + // If not first buffer cat to first buffer and free + if (buf->buffer != first_buffer) { + mem_mngr->cat(first_buffer, buf->buffer); + buf->buffer = NULL; + ppp_memory_buffer_free(buf); + } + } + + // Going to upper levels, do not deallocate the actual buffer + p->buffer = NULL; + ppp_memory_buffer_free(p); + + return first_buffer; + } + + uint8_t ppp_memory_buffer_remove_header(pbuf *buffer, uint16_t header_len) + { + uint8_t *payload = static_cast(buffer->payload); + payload += header_len; + buffer->payload = payload; + buffer->len -= header_len; + return 0; + } + + uint8_t ppp_memory_buffer_add_header(struct pbuf *buffer, uint16_t header_len) + { + uint32_t payload_headroom_len = static_cast(buffer->payload) - static_cast(buffer->payload_start); + + if (payload_headroom_len < header_len) { + return 1; // failure + } + + buffer->payload = static_cast(buffer->payload) - header_len; + buffer->len += header_len; + + return 0; + } + + uint32_t ppp_sys_now(void) + { + return osKernelGetTickCount(); + } + + uint32_t ppp_sys_jiffies(void) + { + return ppp_sys_now(); + } + + sys_prot_t ppp_sys_arch_protect(void *service_ptr) + { + ppp_service *ppp_service_ptr = static_cast(service_ptr); + ppp_service_ptr->resource_lock(); + + return (sys_prot_t) 1; + } + + void ppp_sys_arch_unprotect(void *service_ptr, sys_prot_t p) + { + ppp_service *ppp_service_ptr = static_cast(service_ptr); + ppp_service_ptr->resource_unlock(); + } + +#if PPP_TRACE_ENABLE + void ppp_trace_to_ascii_hex_dump(int buffer, int len, char *data) + { + char prefix[10]; + trace_buf_t *trace_buffer = NULL; + if (buffer == OUTPUT_BUFFER) { + strcpy(prefix, "O:"); + trace_buffer = &output_trace_buffer; + } else if (buffer == INPUT_BUFFER) { + strcpy(prefix, "I:"); + trace_buffer = &input_trace_buffer; + } + + static char line[100]; + memset(line, 0, 100); + int index = 0; + + bool add_prefix = false; + if (trace_buffer->buffer_index == 0) { + index += sprintf(&line[index], "\n %" PRIi32 " len: %i buffer index %i line len %i \n", ppp_sys_now(), len, trace_buffer->buffer_index, trace_buffer->line_len); + add_prefix = true; + } + + for (int i = 0; i < len; i++) { + if ((trace_buffer->line_len % 16) == 0) { + if (trace_buffer->line_len != 0) { + index += sprintf(&line[index], "\n"); + trace_buffer->buffer_index += sprintf(&trace_buffer->buffer[trace_buffer->buffer_index], "%s", line); + index = 0; + } + + bool add_ppp_flag = false; + if (add_prefix) { + if (data[i] == 0xff || (data[i] == 0x57 && (data[i + 1] == 0x60 || data[i + 1] == 0x6a))) { + add_ppp_flag = true; + } + } + + index += sprintf(&line[index], "%s %06x%s%s", prefix, trace_buffer->line_len, add_prefix ? " 00 00 88 81" : "", add_ppp_flag ? " 7e" : ""); + if (add_prefix) { + trace_buffer->line_len += 4; + } + if (add_ppp_flag) { + trace_buffer->line_len += 1; + } + add_prefix = false; + } + trace_buffer->line_len++; + index += sprintf(&line[index], " %02x", data[i]); + } + + trace_buffer->buffer_index += sprintf(&trace_buffer->buffer[trace_buffer->buffer_index], "%s", line); + } + + void ppp_trace_to_ascii_hex_dump_print(int buffer) + { + trace_buf_t *trace_buffer = NULL; + if (buffer == OUTPUT_BUFFER) { + trace_buffer = &output_trace_buffer; + } else if (buffer == INPUT_BUFFER) { + trace_buffer = &input_trace_buffer; + } + +#if PPP_TRACE_BUFFER_SIZE == 0 + tr_info("%s", trace_buffer->buffer); +#endif + +#if PPP_TRACE_BUFFER_SIZE > 0 + cont_trace_buffer_index += sprintf(&cont_trace_buffer[cont_trace_buffer_index], "%s", trace_buffer->buffer); + memset(trace_buffer->buffer, 0, BUFFER_SIZE); + + if (cont_trace_buffer_index > (PPP_TRACE_BUFFER_SIZE - PPP_TRACE_BUFFER_SIZE / 5)) { + cont_trace_buffer_index = 0; + } +#endif + + trace_buffer->buffer_index = 0; + trace_buffer->line_len = 0; + } + +#endif + + void ppp_sys_timeout_callback(void *cb_ptr) + { + ppp_service_if_mutex->lock(); + + int id = reinterpret_cast(cb_ptr); + + ppp_sys_timeout_handler handler = NULL; + void *arg = NULL; + + for (int8_t i = 0; i < PPP_TIMER_NUM; i++) { + if (timeout[i] && timeout[i]->id == id) { + handler = timeout[i]->handler; + arg = timeout[i]->arg; + free(timeout[i]); + timeout[i] = NULL; + //tr_info("sys timer timeout, i: %i h/a: %p %p, id: %i", i, handler, arg, timeout[i]->equeue_id); + } + } + + ppp_service_if_mutex->unlock(); + + if (handler) { + handler(arg); + } else { + tr_error("Cancelled timeout"); + } + } + + void ppp_sys_timeout(void *service_ptr, u32_t msecs, ppp_sys_timeout_handler handler, void *arg) + { + ppp_service *ppp_service_ptr = static_cast(service_ptr); + + ppp_service_if_mutex->lock(); + + int8_t free_index = -1; + + for (int8_t i = 0; i < PPP_TIMER_NUM; i++) { + if (timeout[i] == NULL && free_index < 0) { + free_index = i; + } else if (timeout[i] != NULL && timeout[i]->handler == handler && timeout[i]->arg == arg) { + tr_error("Timeout already set"); + ppp_service_if_mutex->unlock(); + return; + } + } + + if (free_index < 0) { + tr_error("No free timeouts"); + ppp_service_if_mutex->unlock(); + } + + timeout[free_index] = static_cast(malloc(sizeof(ppp_sys_timeout_t))); + if (!timeout[free_index]) { + tr_error("No free memory for timeout"); + ppp_service_if_mutex->unlock(); + return; + } + + void *cb_ptr = reinterpret_cast(ppp_service_sys_timeout_id); + int unique_id = ppp_service_ptr->event_queue_get()->call_in(msecs, mbed::callback(ppp_sys_timeout_callback, cb_ptr)); + if (unique_id == 0) { + tr_error("No free memory for timeout equeue"); + ppp_service_if_mutex->unlock(); + return; + } + + timeout[free_index]->ppp_drv = ppp_service_ptr; + timeout[free_index]->handler = handler; + timeout[free_index]->arg = arg; + timeout[free_index]->equeue_id = unique_id; + timeout[free_index]->id = ppp_service_sys_timeout_id++; + + //tr_info("sys timer start, i: %i h/a: %p %p, t: %" PRIx32 " id: %i", free_index, handler, arg, msecs, unique_id); + + ppp_service_if_mutex->unlock(); + } + + void ppp_sys_untimeout(ppp_sys_timeout_handler handler, void *arg) + { + ppp_service_if_mutex->lock(); + + for (int8_t i = 0; i < PPP_TIMER_NUM; i++) { + if (timeout[i] != NULL && timeout[i]->handler == handler && timeout[i]->arg == arg) { + int unique_id = timeout[i]->equeue_id; + timeout[i]->ppp_drv->event_queue_get()->cancel(unique_id); + //tr_info("sys timer cancel, i: %i h/a: %p %p, id: %i", i, timeout[i]->handler, timeout[i]->arg, unique_id); + free(timeout[i]); + timeout[i] = NULL; + } + } + + ppp_service_if_mutex->unlock(); + } + +} // extern "C" + +#if PPP_TRACE_ENABLE && PPP_TRACE_BUFFER_SIZE > 0 +void ppp_trace_to_ascii_hex_dump_print_final(void) +{ + int start_i = 0; + + for (int i = 0; i < PPP_TRACE_BUFFER_SIZE; i++) { + if (cont_trace_buffer[i] == '\n' || cont_trace_buffer[i] == '\0') { + memcpy(output_trace_buffer.buffer, &cont_trace_buffer[start_i], i - start_i); + output_trace_buffer.buffer[i - start_i] = 0; + + tr_info("%s", output_trace_buffer.buffer); + + if (cont_trace_buffer[i] == '\0') { + break; + } + + start_i = i + 1; + } + } +} +#endif + +#endif diff --git a/features/netsocket/ppp/ppp_service_if.h b/features/netsocket/ppp/ppp_service_if.h new file mode 100644 index 0000000000..77e856dd09 --- /dev/null +++ b/features/netsocket/ppp/ppp_service_if.h @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PPP_SERVICE_IF_H +#define PPP_SERVICE_IF_H + +#include "nsapi_types.h" + +#include + +typedef uint8_t u8_t; +typedef int8_t s8_t; +typedef uint16_t u16_t; +typedef int16_t s16_t; +typedef uint32_t u32_t; +typedef int32_t s32_t; + +typedef s8_t err_t; + +#include +#ifndef X8_F +#define X8_F "02" PRIx8 +#endif +#ifndef U16_F +#define U16_F PRIu16 +#endif +#ifndef S16_F +#define S16_F PRId16 +#endif +#ifndef X16_F +#define X16_F PRIx16 +#endif +#ifndef U32_F +#define U32_F PRIu32 +#endif +#ifndef S32_F +#define S32_F PRId32 +#endif +#ifndef X32_F +#define X32_F PRIx32 +#endif +#ifndef SZT_F +#define SZT_F PRIuPTR +#endif + +struct netif; + +typedef enum { + /** No error, everything OK. */ + ERR_OK = 0, + /** Out of memory error. */ + ERR_MEM = -1, + /** Buffer error. */ + ERR_BUF = -2, + /** Timeout. */ + ERR_TIMEOUT = -3, + /** Routing problem. */ + ERR_RTE = -4, + /** Operation in progress */ + ERR_INPROGRESS = -5, + /** Illegal value. */ + ERR_VAL = -6, + /** Operation would block. */ + ERR_WOULDBLOCK = -7, + /** Address in use. */ + ERR_USE = -8, + /** Already connecting. */ + ERR_ALREADY = -9, + /** Conn already established.*/ + ERR_ISCONN = -10, + /** Not connected. */ + ERR_CONN = -11, + /** Low-level netif error */ + ERR_IF = -12, + + /** Connection aborted. */ + ERR_ABRT = -13, + /** Connection reset. */ + ERR_RST = -14, + /** Connection closed. */ + ERR_CLSD = -15, + /** Illegal argument. */ + ERR_ARG = -16 +} err_enum_t; + +/** Eliminates compiler warning about unused arguments */ +#ifndef PPP_UNUSED_ARG +#define PPP_UNUSED_ARG(x) (void)x +#endif /* PPP_UNUSED_ARG */ + +#define PPP_MAX(x , y) (((x) > (y)) ? (x) : (y)) +#define PPP_MIN(x , y) (((x) < (y)) ? (x) : (y)) + +typedef nsapi_addr_t ip4_addr_t; +typedef nsapi_addr_t ip6_addr_t; +typedef nsapi_addr_t ip_addr_t; + +#define IPADDR_STRLEN_MAX 46 + +#define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0) +#define IP_CLASSA_NET 0xff000000 +#define IP_CLASSA_NSHIFT 24 +#define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET) +#define IP_CLASSA_MAX 128 + +#define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL) +#define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */ +#define IP_CLASSD_NSHIFT 28 /* net and host fields, but */ +#define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */ +#define IP_MULTICAST(a) IP_CLASSD(a) + +#define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL) + +#define IP_LOOPBACKNET 127 /* official! */ + +#define ip4_addr_set_u32(dest_ipaddr, src_u32) \ + ppp_ip4_addr_set((nsapi_addr_t *)dest_ipaddr, &src_u32) + +#define ip_addr_set_ip4_u32_val(ipaddr, val) \ + ppp_ip4_addr_set((nsapi_addr_t *)&ipaddr, &val) + +struct pbuf { + struct pbuf *next; // Next buffer on the chain + void *memory_manager; // Memory manager used to allocate buffer + void *buffer; // Buffer allocated by memory manager + void *payload; // Pointer to payload of the first buffer on the chain (payload_start + headroom) + void *payload_start; // Pointer to payload start of the first buffer on the chain + uint16_t len; // Length of the first buffer on the chain (equals to total length on alloc) + uint16_t tot_len; // Total length of the first buffer on the chain +}; + +typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); +#if PPP_IPV4_SUPPORT +typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, + const ip4_addr_t *ipaddr); +#endif +#if PPP_IPV6_SUPPORT +typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, + const ip6_addr_t *ipaddr); +#endif +typedef err_t (*netif_init_fn)(struct netif *netif); + +struct netif { + /** Pointer to PPP Service */ + void *service_ptr; + /** Pointer to memory manager */ + void *memory_manager; + /** Pointer to memory stream */ + void *stream; + /** This function is called by the PPP service + * to pass a packet up the TCP/IP stack. */ + netif_input_fn input; +#if PPP_IPV4_SUPPORT + /** This function is called by the IP module when it wants + * to send a packet on the interface. */ + netif_output_fn output; + nsapi_addr_t ipv4_addr; + nsapi_addr_t ipv4_netmask; + nsapi_addr_t ipv4_gateway; + nsapi_addr_t ipv4_dns_server[2]; + u8_t ipv4_up; +#endif /* PPP_IPV4_SUPPORT */ +#if PPP_IPV6_SUPPORT + /** This function is called by the IPv6 module when it wants + * to send a packet on the interface. */ + netif_output_ip6_fn output_ip6; + nsapi_addr_t ipv6_addr; + u8_t ipv6_up; +#endif /* PPP_IPV6_SUPPORT */ + /** This field can be set by the PPP protocol and could point + * to state information for the protocol. */ + void *state; + /** maximum transfer unit (in bytes) */ + u16_t mtu; +#if PPP_DEBUG + u8_t num; +#endif +}; + +#define netif_set_link_up(netif) ppp_netif_set_link_up(netif) +#define netif_set_link_down(netif) ppp_netif_set_link_down(netif) + +#define PPP_MEMPOOL_PROTOTYPE(name) +#define PPP_MEMPOOL_INIT(name) +#define PPP_MEMPOOL_ALLOC(name) 1 +#define PPP_MEMPOOL_FREE(name, x) + +#define PPP_MEMPOOL_DECLARE(name,num,size,desc) \ + uint32_t name = size; + +#define PBUF_RAW 1 +#define PBUF_POOL 2 +#define PBUF_RAM 2 + +typedef enum { + PPP_BUF_HEAP = 0, + PPP_BUF_POOL +} ppp_buf_type_e; + +#define MEMPOOL_ALLOC(size) \ + malloc(size) + +#define MEMPOOL_FREE(x, ptr) \ + free(ptr) + +#define pbuf_remove_header(buf, size) \ + ppp_memory_buffer_remove_header(buf, size) + +#define pbuf_add_header(buf, size) \ + ppp_memory_buffer_add_header(buf, size) + +#define LINK_STATS_INC(x) +#define MIB2_STATS_NETIF_INC(n, x) +#define MIB2_INIT_NETIF(netif, type, speed) +#define MIB2_STATS_NETIF_ADD(n, x, val) + +#define PPP_ASSERT(message, assertion) + +typedef int sys_prot_t; + +#define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev +#define SYS_ARCH_PROTECT(lev) lev = ppp_sys_arch_protect(ppp->netif->service_ptr) +#define SYS_ARCH_UNPROTECT(lev) ppp_sys_arch_unprotect(ppp->netif->service_ptr, lev) + +#define PPPOS_DECL_PROTECT(lev) SYS_ARCH_DECL_PROTECT(lev) +#define PPPOS_PROTECT(lev) SYS_ARCH_PROTECT(lev) +#define PPPOS_UNPROTECT(lev) SYS_ARCH_UNPROTECT(lev) + +#include +#define ppp_isdigit(c) isdigit((unsigned char)(c)) + +#define sys_now ppp_sys_now +#define sys_jiffies() ppp_sys_jiffies(); + +#define TIMEOUT(f, a, t) do { ppp_sys_untimeout((f), (a)); ppp_sys_timeout(pcb->netif->service_ptr, (t)*1000, (f), (a)); } while(0) +#define TIMEOUTMS(f, a, t) do { ppp_sys_untimeout((f), (a)); ppp_sys_timeout(pcb->netif->service_ptr, (t), (f), (a)); } while(0) +#define UNTIMEOUT(f, a) do { ppp_sys_untimeout((f), (a)); } while(0) + +#define sys_timeout(msecs, handler, arg) ppp_sys_timeout(pcb->netif->service_ptr, msecs, (ppp_sys_timeout_handler) handler, (void *) arg) +#define sys_untimeout(handler, arg) ppp_sys_untimeout(handler, (void *) arg) + +#define OUTPUT_BUFFER 0 +#define INPUT_BUFFER 1 + +#if defined(__arm__) && defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 6010050) +/* Keil uVision4 tools */ +#define PACK_STRUCT_BEGIN __packed +#define PACK_STRUCT_STRUCT +#define PACK_STRUCT_END +#define PACK_STRUCT_FIELD(fld) fld +#define ALIGNED(n) __align(n) +#elif defined (__IAR_SYSTEMS_ICC__) +/* IAR Embedded Workbench tools */ +#define PACK_STRUCT_BEGIN __packed +#define PACK_STRUCT_STRUCT +#define PACK_STRUCT_END +#define PACK_STRUCT_FIELD(fld) fld +#define IAR_STR(a) #a +#define ALIGNED(n) _Pragma(IAR_STR(data_alignment= ## n ##)) +#else +/* GCC tools (CodeSourcery) */ +#define PACK_STRUCT_BEGIN +#define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) +#define PACK_STRUCT_END +#define PACK_STRUCT_FIELD(fld) fld +#define ALIGNED(n) __attribute__((aligned (n))) +#endif + +/** + * MEMCPY: override this if you have a faster implementation at hand than the + * one included in your C library + */ +#if !defined MEMCPY +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif + +#define UNUSED_ARG(x) (void)x + +#ifdef __cplusplus +extern "C" { +#endif + +struct pbuf *ppp_memory_buffer_allocate(void *memory_manager, uint16_t size, ppp_buf_type_e type); +void ppp_memory_buffer_free(struct pbuf *buffer); +uint16_t ppp_memory_buffer_pool_alloc_unit_get(void *memory_manager); +void ppp_memory_buffer_cat(void *memory_manager, struct pbuf *to_buf, struct pbuf *cat_buf); +void ppp_memory_buffer_set_len(void *memory_manager, struct pbuf *buf, uint16_t len); +uint8_t ppp_memory_buffer_remove_header(struct pbuf *buffer, uint16_t header_len); +uint8_t ppp_memory_buffer_add_header(struct pbuf *buffer, uint16_t header_len); + +struct pbuf *ppp_memory_buffer_convert_to(void *memory_manager, void *mem_buf); +void *ppp_memory_buffer_convert_from(struct pbuf *pbuf); + +struct netif *ppp_netif_add(struct netif *netif, void *state, netif_init_fn init); +#define ppp_netif_remove(param) +err_t ppp_ip_input(struct pbuf *p, struct netif *inp); +void ppp_ip4_addr_set(nsapi_addr_t *addr, uint32_t *src); + +void ppp_set_link_up(struct netif *netif); +void ppp_set_link_down(struct netif *netif); + +typedef void ppp_service_cb(void *arg); +err_t ppp_call_callback(void *service_ptr, ppp_service_cb callback, void *arg); + +sys_prot_t ppp_sys_arch_protect(void *service_ptr); +void ppp_sys_arch_unprotect(void *service_ptr, sys_prot_t p); + +typedef void (*ppp_sys_timeout_handler)(void *arg); +void ppp_sys_timeout(void *service_ptr, u32_t msecs, ppp_sys_timeout_handler handler, void *arg); +void ppp_sys_untimeout(ppp_sys_timeout_handler handler, void *arg); + +uint32_t ppp_sys_now(void); +uint32_t ppp_sys_jiffies(void); + +void ppp_trace_to_ascii_hex_dump(int output, int len, char *data); +void ppp_trace_to_ascii_hex_dump_print(int output); + +#ifdef __cplusplus +} +#endif + +#endif /* PPP_SERVICE_IF_H */ diff --git a/features/netsocket/ppp/PPPD_FOLLOWUP b/features/netsocket/ppp/source/PPPD_FOLLOWUP similarity index 100% rename from features/netsocket/ppp/PPPD_FOLLOWUP rename to features/netsocket/ppp/source/PPPD_FOLLOWUP diff --git a/features/netsocket/ppp/auth.c b/features/netsocket/ppp/source/auth.c similarity index 99% rename from features/netsocket/ppp/auth.c rename to features/netsocket/ppp/source/auth.c index e836bd73ee..dc403fe467 100644 --- a/features/netsocket/ppp/auth.c +++ b/features/netsocket/ppp/source/auth.c @@ -69,7 +69,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #if 0 /* UNUSED */ #include @@ -89,10 +89,6 @@ #include #endif -#include -#include -#include - #ifdef HAS_SHADOW #include #ifndef PW_PPP @@ -546,7 +542,7 @@ set_permitted_number(argv) * An Open on LCP has requested a change from Dead to Establish phase. */ void link_required(ppp_pcb *pcb) { - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); } #if 0 @@ -1029,7 +1025,7 @@ int auth_check_passwd(ppp_pcb *pcb, char *auser, int userlen, char *apasswd, int * The peer has failed to authenticate himself using `protocol'. */ void auth_peer_fail(ppp_pcb *pcb, int protocol) { - LWIP_UNUSED_ARG(protocol); + PPP_UNUSED_ARG(protocol); /* * Authentication failure: take the link down */ @@ -1046,8 +1042,8 @@ void auth_peer_fail(ppp_pcb *pcb, int protocol) { void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char *name, int namelen) { int bit; #ifndef HAVE_MULTILINK - LWIP_UNUSED_ARG(name); - LWIP_UNUSED_ARG(namelen); + PPP_UNUSED_ARG(name); + PPP_UNUSED_ARG(namelen); #endif /* HAVE_MULTILINK */ switch (protocol) { @@ -1115,7 +1111,7 @@ void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char * * We have failed to authenticate ourselves to the peer using `protocol'. */ void auth_withpeer_fail(ppp_pcb *pcb, int protocol) { - LWIP_UNUSED_ARG(protocol); + PPP_UNUSED_ARG(protocol); /* * We've failed to authenticate ourselves to our peer. * @@ -1199,7 +1195,7 @@ void np_up(ppp_pcb *pcb, int proto) { #if PPP_IDLETIMELIMIT int tlim; #endif /* PPP_IDLETIMELIMIT */ - LWIP_UNUSED_ARG(proto); + PPP_UNUSED_ARG(proto); if (pcb->num_np_up == 0) { /* @@ -1247,7 +1243,7 @@ void np_up(ppp_pcb *pcb, int proto) { * np_down - a network protocol has gone down. */ void np_down(ppp_pcb *pcb, int proto) { - LWIP_UNUSED_ARG(proto); + PPP_UNUSED_ARG(proto); if (--pcb->num_np_up == 0) { #if PPP_IDLETIMELIMIT UNTIMEOUT(check_idle, (void*)pcb); @@ -1266,7 +1262,7 @@ void np_down(ppp_pcb *pcb, int proto) { * np_finished - a network protocol has finished using the link. */ void np_finished(ppp_pcb *pcb, int proto) { - LWIP_UNUSED_ARG(proto); + PPP_UNUSED_ARG(proto); if (--pcb->num_np_open <= 0) { /* no further use for the link: shut up shop. */ lcp_close(pcb, "No network protocols running"); @@ -1331,7 +1327,7 @@ static void check_idle(void *arg) { tlim = idle_time_hook(&idle); } else { #endif /* UNUSED */ - itime = LWIP_MIN(idle.xmit_idle, idle.recv_idle); + itime = PPP_MIN(idle.xmit_idle, idle.recv_idle); tlim = pcb->settings.idle_time_limit - itime; #if 0 /* UNUSED */ } @@ -1903,8 +1899,8 @@ have_srp_secret(client, server, need_ip, lacks_ipp) */ int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server) { int len; - LWIP_UNUSED_ARG(server); - LWIP_UNUSED_ARG(am_server); + PPP_UNUSED_ARG(server); + PPP_UNUSED_ARG(am_server); if (!client || !client[0] || !pcb->settings.user || !pcb->settings.passwd || strcmp(client, pcb->settings.user)) { return 0; @@ -2121,10 +2117,10 @@ set_allowed_addrs(unit, addrs, opts) } else { np = getnetbyname (ptr_word); if (np != NULL && np->n_addrtype == AF_INET) { - a = lwip_htonl ((u32_t)np->n_net); + a = ppp_htonl ((u32_t)np->n_net); if (ptr_mask == NULL) { /* calculate appropriate mask for net */ - ah = lwip_ntohl(a); + ah = ppp_ntohl(a); if (IN_CLASSA(ah)) mask = IN_CLASSA_NET; else if (IN_CLASSB(ah)) @@ -2150,10 +2146,10 @@ set_allowed_addrs(unit, addrs, opts) ifunit, ptr_word); continue; } - a = lwip_htonl((lwip_ntohl(a) & mask) + offset); + a = ppp_htonl((ppp_ntohl(a) & mask) + offset); mask = ~(u32_t)0; } - ip[n].mask = lwip_htonl(mask); + ip[n].mask = ppp_htonl(mask); ip[n].base = a & ip[n].mask; ++n; if (~mask == 0 && suggested_ip == 0) @@ -2234,7 +2230,7 @@ int bad_ip_adrs(addr) u32_t addr; { - addr = lwip_ntohl(addr); + addr = ppp_ntohl(addr); return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || IN_MULTICAST(addr) || IN_BADCLASS(addr); } diff --git a/features/netsocket/ppp/ccp.c b/features/netsocket/ppp/source/ccp.c similarity index 99% rename from features/netsocket/ppp/ccp.c rename to features/netsocket/ppp/source/ccp.c index adf0493c41..4d3cd267ef 100644 --- a/features/netsocket/ppp/ccp.c +++ b/features/netsocket/ppp/source/ccp.c @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include #include @@ -486,8 +486,8 @@ static void ccp_input(ppp_pcb *pcb, u_char *p, int len) { */ static int ccp_extcode(fsm *f, int code, int id, u_char *p, int len) { ppp_pcb *pcb = f->pcb; - LWIP_UNUSED_ARG(p); - LWIP_UNUSED_ARG(len); + PPP_UNUSED_ARG(p); + PPP_UNUSED_ARG(len); switch (code) { case CCP_RESETREQ: @@ -930,10 +930,10 @@ static int ccp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { ccp_options *go = &pcb->ccp_gotoptions; ccp_options no; /* options we've seen already */ ccp_options try_; /* options to ask for next time */ - LWIP_UNUSED_ARG(treat_as_reject); + PPP_UNUSED_ARG(treat_as_reject); #if !MPPE_SUPPORT && !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT - LWIP_UNUSED_ARG(p); - LWIP_UNUSED_ARG(len); + PPP_UNUSED_ARG(p); + PPP_UNUSED_ARG(len); #endif /* !MPPE_SUPPORT && !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT */ memset(&no, 0, sizeof(no)); @@ -1388,7 +1388,7 @@ static int ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak) { static const char *method_name(ccp_options *opt, ccp_options *opt2) { static char result[64]; #if !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT - LWIP_UNUSED_ARG(opt2); + PPP_UNUSED_ARG(opt2); #endif /* !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT */ if (!ccp_anycompress(opt)) @@ -1533,7 +1533,7 @@ static int ccp_printpkt(const u_char *p, int plen, void (*printer) (void *, cons if (len < HEADERLEN || len > plen) return 0; - if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(ccp_codenames) && ccp_codenames[code-1] != NULL) + if (code >= 1 && code <= (int)PPP_ARRAYSIZE(ccp_codenames) && ccp_codenames[code-1] != NULL) printer(arg, " %s", ccp_codenames[code-1]); else printer(arg, " code=0x%x", code); @@ -1662,8 +1662,8 @@ static void ccp_datainput(ppp_pcb *pcb, u_char *pkt, int len) { #if MPPE_SUPPORT ccp_options *go = &pcb->ccp_gotoptions; #endif /* MPPE_SUPPORT */ - LWIP_UNUSED_ARG(pkt); - LWIP_UNUSED_ARG(len); + PPP_UNUSED_ARG(pkt); + PPP_UNUSED_ARG(len); f = &pcb->ccp_fsm; if (f->state == PPP_FSM_OPENED) { diff --git a/features/netsocket/ppp/chap-md5.c b/features/netsocket/ppp/source/chap-md5.c similarity index 82% rename from features/netsocket/ppp/chap-md5.c rename to features/netsocket/ppp/source/chap-md5.c index 4f330495aa..9d19c5fcb9 100644 --- a/features/netsocket/ppp/chap-md5.c +++ b/features/netsocket/ppp/source/chap-md5.c @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #if 0 /* UNUSED */ #include @@ -51,7 +51,7 @@ #if PPP_SERVER static void chap_md5_generate_challenge(ppp_pcb *pcb, unsigned char *cp) { int clen; - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); clen = MD5_MIN_CHALLENGE + magic_pow(MD5_MIN_MAX_POWER_OF_TWO_CHALLENGE); *cp++ = clen; @@ -62,24 +62,24 @@ 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; + 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); + PPP_UNUSED_ARG(name); + PPP_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); + MD5_Init(&ctx); + MD5_starts(&ctx); + MD5_update(&ctx, &idbyte, 1); + MD5_update(&ctx, secret, secret_len); + MD5_update(&ctx, challenge, challenge_len); + MD5_finish(&ctx, hash); + MD5_free(&ctx); /* Test if our hash matches the peer's response */ if (memcmp(hash, response, MD5_HASH_SIZE) == 0) { @@ -95,20 +95,20 @@ static int chap_md5_verify_response(ppp_pcb *pcb, int id, const char *name, 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; + MD5_context ctx; unsigned char idbyte = id; int challenge_len = *challenge++; - LWIP_UNUSED_ARG(our_name); - LWIP_UNUSED_ARG(private_); - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(our_name); + PPP_UNUSED_ARG(private_); + PPP_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); + MD5_init(&ctx); + MD5_starts(&ctx); + MD5_update(&ctx, &idbyte, 1); + MD5_update(&ctx, (const u_char *)secret, secret_len); + MD5_update(&ctx, challenge, challenge_len); + MD5_finish(&ctx, &response[1]); + MD5_free(&ctx); response[0] = MD5_HASH_SIZE; } diff --git a/features/netsocket/ppp/chap-new.c b/features/netsocket/ppp/source/chap-new.c similarity index 95% rename from features/netsocket/ppp/chap-new.c rename to features/netsocket/ppp/source/chap-new.c index 49119b27ba..eb6cba13f8 100644 --- a/features/netsocket/ppp/chap-new.c +++ b/features/netsocket/ppp/source/chap-new.c @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #if 0 /* UNUSED */ #include @@ -122,7 +122,7 @@ static const struct chap_digest_type* const chap_digests[] = { * chap_init - reset to initial state. */ static void chap_init(ppp_pcb *pcb) { - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); #if 0 /* Not necessary, everything is cleared in ppp_new() */ memset(&pcb->chap_client, 0, sizeof(chap_client_state)); @@ -236,11 +236,13 @@ static void chap_timeout(void *arg) { return; } - p = pbuf_alloc(PBUF_RAW, (u16_t)(pcb->chap_server.challenge_pktlen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(pcb->chap_server.challenge_pktlen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(pcb->chap_server.challenge_pktlen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } MEMCPY(p->payload, pcb->chap_server.challenge, pcb->chap_server.challenge_pktlen); @@ -345,11 +347,13 @@ static void chap_handle_response(ppp_pcb *pcb, int id, /* send the response */ mlen = strlen(message); len = CHAP_HDRLEN + mlen; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +len), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN +len), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +len), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -441,11 +445,13 @@ static void chap_respond(ppp_pcb *pcb, int id, char rname[MAXNAMELEN+1]; char secret[MAXSECRETLEN+1]; - p = pbuf_alloc(PBUF_RAW, (u16_t)(RESP_MAX_PKTLEN), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(RESP_MAX_PKTLEN), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(RESP_MAX_PKTLEN), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -490,14 +496,15 @@ static void chap_respond(ppp_pcb *pcb, int id, outp[2] = len >> 8; outp[3] = len; - pbuf_realloc(p, PPP_HDRLEN + len); + p->len = PPP_HDRLEN + len; + //pbuf_realloc(p, PPP_HDRLEN + len); ppp_write(pcb, p); } static void chap_handle_status(ppp_pcb *pcb, int code, int id, unsigned char *pkt, int len) { const char *msg = NULL; - LWIP_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); if ((pcb->chap_client.flags & (AUTH_DONE|AUTH_STARTED|LOWERUP)) != (AUTH_STARTED|LOWERUP)) @@ -604,7 +611,7 @@ static int chap_print_pkt(const unsigned char *p, int plen, if (len < CHAP_HDRLEN || len > plen) return 0; - if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(chap_code_names)) + if (code >= 1 && code <= (int)PPP_ARRAYSIZE(chap_code_names)) printer(arg, " %s", chap_code_names[code-1]); else printer(arg, " code=0x%x", code); diff --git a/features/netsocket/ppp/chap_ms.c b/features/netsocket/ppp/source/chap_ms.c similarity index 87% rename from features/netsocket/ppp/chap_ms.c rename to features/netsocket/ppp/source/chap_ms.c index e06e1f2e40..3d3a66ec5e 100644 --- a/features/netsocket/ppp/chap_ms.c +++ b/features/netsocket/ppp/source/chap_ms.c @@ -75,7 +75,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #if 0 /* UNUSED */ #include @@ -223,7 +223,7 @@ static option_t chapms_option_list[] = { * at challenge[1]. */ static void chapms_generate_challenge(ppp_pcb *pcb, unsigned char *challenge) { - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); *challenge++ = 8; #ifdef DEBUGMPPEKEY @@ -235,7 +235,7 @@ static void chapms_generate_challenge(ppp_pcb *pcb, unsigned char *challenge) { } static void chapms2_generate_challenge(ppp_pcb *pcb, unsigned char *challenge) { - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); *challenge++ = 16; #ifdef DEBUGMPPEKEY @@ -253,8 +253,8 @@ static int chapms_verify_response(ppp_pcb *pcb, int id, const char *name, unsigned char md[MS_CHAP_RESPONSE_LEN]; int diff; int challenge_len, response_len; - LWIP_UNUSED_ARG(id); - LWIP_UNUSED_ARG(name); + PPP_UNUSED_ARG(id); + PPP_UNUSED_ARG(name); challenge_len = *challenge++; /* skip length, is 8 */ response_len = *response++; @@ -301,7 +301,7 @@ static int chapms2_verify_response(ppp_pcb *pcb, int id, const char *name, unsigned char md[MS_CHAP2_RESPONSE_LEN]; char saresponse[MS_AUTH_RESPONSE_LENGTH+1]; int challenge_len, response_len; - LWIP_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); challenge_len = *challenge++; /* skip length, is 16 */ response_len = *response++; @@ -374,9 +374,9 @@ static int chapms2_verify_response(ppp_pcb *pcb, int id, const char *name, static void chapms_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_UNUSED_ARG(id); - LWIP_UNUSED_ARG(our_name); - LWIP_UNUSED_ARG(private_); + PPP_UNUSED_ARG(id); + PPP_UNUSED_ARG(our_name); + PPP_UNUSED_ARG(private_); challenge++; /* skip length, should be 8 */ *response++ = MS_CHAP_RESPONSE_LEN; ChapMS(pcb, challenge, secret, secret_len, response); @@ -385,7 +385,7 @@ static void chapms_make_response(ppp_pcb *pcb, unsigned char *response, int id, static void chapms2_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_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); challenge++; /* skip length, should be 16 */ *response++ = MS_CHAP2_RESPONSE_LEN; ChapMS2(pcb, challenge, @@ -399,7 +399,7 @@ static void chapms2_make_response(ppp_pcb *pcb, unsigned char *response, int id, } static int chapms2_check_success(ppp_pcb *pcb, unsigned char *msg, int len, unsigned char *private_) { - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); if ((len < MS_AUTH_RESPONSE_LENGTH + 2) || strncmp((char *)msg, "S=", 2) != 0) { @@ -432,10 +432,10 @@ static void chapms_handle_failure(ppp_pcb *pcb, unsigned char *inp, int len) { int err; const char *p; char msg[64]; - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); /* We want a null-terminated string for strxxx(). */ - len = LWIP_MIN(len, 63); + len = PPP_MIN(len, 63); MEMCPY(msg, inp, len); msg[len] = 0; p = msg; @@ -497,7 +497,7 @@ static void ChallengeResponse(const u_char *challenge, const u_char PasswordHash[MD4_SIGNATURE_SIZE], u_char response[24]) { u_char ZPasswordHash[21]; - lwip_des_context des; + Des_context des; u_char des_key[8]; BZERO(ZPasswordHash, sizeof(ZPasswordHash)); @@ -509,22 +509,22 @@ static void ChallengeResponse(const u_char *challenge, #endif pppcrypt_56_to_64_bit_key(ZPasswordHash + 0, des_key); - lwip_des_init(&des); - lwip_des_setkey_enc(&des, des_key); - lwip_des_crypt_ecb(&des, challenge, response +0); - lwip_des_free(&des); + Des_init(&des); + Des_setkey_enc(&des, des_key); + Des_crypt_ecb(&des, challenge, response +0); + Des_free(&des); pppcrypt_56_to_64_bit_key(ZPasswordHash + 7, des_key); - lwip_des_init(&des); - lwip_des_setkey_enc(&des, des_key); - lwip_des_crypt_ecb(&des, challenge, response +8); - lwip_des_free(&des); + Des_init(&des); + Des_setkey_enc(&des, des_key); + Des_crypt_ecb(&des, challenge, response +8); + Des_free(&des); pppcrypt_56_to_64_bit_key(ZPasswordHash + 14, des_key); - lwip_des_init(&des); - lwip_des_setkey_enc(&des, des_key); - lwip_des_crypt_ecb(&des, challenge, response +16); - lwip_des_free(&des); + Des_init(&des); + Des_setkey_enc(&des, des_key); + Des_crypt_ecb(&des, challenge, response +16); + Des_free(&des); #if 0 dbglog("ChallengeResponse - response %.24B", response); @@ -533,7 +533,7 @@ static void ChallengeResponse(const u_char *challenge, static void ChallengeHash(const u_char PeerChallenge[16], const u_char *rchallenge, const char *username, u_char Challenge[8]) { - lwip_sha1_context sha1Context; + SHA1_context sha1Context; u_char sha1Hash[SHA1_SIGNATURE_SIZE]; const char *user; @@ -543,13 +543,13 @@ static void ChallengeHash(const u_char PeerChallenge[16], const u_char *rchallen else user = username; - lwip_sha1_init(&sha1Context); - lwip_sha1_starts(&sha1Context); - lwip_sha1_update(&sha1Context, PeerChallenge, 16); - lwip_sha1_update(&sha1Context, rchallenge, 16); - lwip_sha1_update(&sha1Context, (const unsigned char*)user, strlen(user)); - lwip_sha1_finish(&sha1Context, sha1Hash); - lwip_sha1_free(&sha1Context); + SHA1_init(&sha1Context); + SHA1_starts(&sha1Context); + SHA1_update(&sha1Context, PeerChallenge, 16); + SHA1_update(&sha1Context, rchallenge, 16); + SHA1_update(&sha1Context, (const unsigned char*)user, strlen(user)); + SHA1_finish(&sha1Context, sha1Hash); + SHA1_free(&sha1Context); MEMCPY(Challenge, sha1Hash, 8); } @@ -570,13 +570,13 @@ static void ascii2unicode(const char ascii[], int ascii_len, u_char unicode[]) { } static void NTPasswordHash(u_char *secret, int secret_len, u_char hash[MD4_SIGNATURE_SIZE]) { - lwip_md4_context md4Context; + MD4_context md4Context; - lwip_md4_init(&md4Context); - lwip_md4_starts(&md4Context); - lwip_md4_update(&md4Context, secret, secret_len); - lwip_md4_finish(&md4Context, hash); - lwip_md4_free(&md4Context); + MD4_init(&md4Context); + MD4_starts(&md4Context); + MD4_update(&md4Context, secret, secret_len); + MD4_finish(&md4Context, hash); + MD4_free(&md4Context); } static void ChapMS_NT(const u_char *rchallenge, const char *secret, int secret_len, @@ -614,7 +614,7 @@ static void ChapMS_LANMan(u_char *rchallenge, char *secret, int secret_len, int i; u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */ u_char PasswordHash[MD4_SIGNATURE_SIZE]; - lwip_des_context des; + Des_context des; u_char des_key[8]; /* LANMan password is case insensitive */ @@ -623,16 +623,16 @@ static void ChapMS_LANMan(u_char *rchallenge, char *secret, int secret_len, UcasePassword[i] = (u_char)toupper(secret[i]); pppcrypt_56_to_64_bit_key(UcasePassword +0, des_key); - lwip_des_init(&des); - lwip_des_setkey_enc(&des, des_key); - lwip_des_crypt_ecb(&des, StdText, PasswordHash +0); - lwip_des_free(&des); + Des_init(&des); + Des_setkey_enc(&des, des_key); + Des_crypt_ecb(&des, StdText, PasswordHash +0); + Des_free(&des); pppcrypt_56_to_64_bit_key(UcasePassword +7, des_key); - lwip_des_init(&des); - lwip_des_setkey_enc(&des, des_key); - lwip_des_crypt_ecb(&des, StdText, PasswordHash +8); - lwip_des_free(&des); + Des_init(&des); + Des_setkey_enc(&des, des_key); + Des_crypt_ecb(&des, StdText, PasswordHash +8); + Des_free(&des); ChallengeResponse(rchallenge, PasswordHash, &response[MS_CHAP_LANMANRESP]); } @@ -659,30 +659,30 @@ static void GenerateAuthenticatorResponse(const u_char PasswordHashHash[MD4_SIGN 0x6E }; int i; - lwip_sha1_context sha1Context; + SHA1_context sha1Context; u_char Digest[SHA1_SIGNATURE_SIZE]; u_char Challenge[8]; - lwip_sha1_init(&sha1Context); - lwip_sha1_starts(&sha1Context); - lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - lwip_sha1_update(&sha1Context, NTResponse, 24); - lwip_sha1_update(&sha1Context, Magic1, sizeof(Magic1)); - lwip_sha1_finish(&sha1Context, Digest); - lwip_sha1_free(&sha1Context); + SHA1_init(&sha1Context); + SHA1_starts(&sha1Context); + SHA1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1_update(&sha1Context, NTResponse, 24); + SHA1_update(&sha1Context, Magic1, sizeof(Magic1)); + SHA1_finish(&sha1Context, Digest); + SHA1_free(&sha1Context); ChallengeHash(PeerChallenge, rchallenge, username, Challenge); - lwip_sha1_init(&sha1Context); - lwip_sha1_starts(&sha1Context); - lwip_sha1_update(&sha1Context, Digest, sizeof(Digest)); - lwip_sha1_update(&sha1Context, Challenge, sizeof(Challenge)); - lwip_sha1_update(&sha1Context, Magic2, sizeof(Magic2)); - lwip_sha1_finish(&sha1Context, Digest); - lwip_sha1_free(&sha1Context); + SHA1_init(&sha1Context); + SHA1_starts(&sha1Context); + SHA1_update(&sha1Context, Digest, sizeof(Digest)); + SHA1_update(&sha1Context, Challenge, sizeof(Challenge)); + SHA1_update(&sha1Context, Magic2, sizeof(Magic2)); + SHA1_finish(&sha1Context, Digest); + SHA1_free(&sha1Context); /* Convert to ASCII hex string. */ - for (i = 0; i < LWIP_MAX((MS_AUTH_RESPONSE_LENGTH / 2), (int)sizeof(Digest)); i++) + for (i = 0; i < PPP_MAX((MS_AUTH_RESPONSE_LENGTH / 2), (int)sizeof(Digest)); i++) sprintf((char *)&authResponse[i * 2], "%02X", Digest[i]); } @@ -715,7 +715,7 @@ static void Set_Start_Key(ppp_pcb *pcb, const u_char *rchallenge, const char *se u_char unicodePassword[MAX_NT_PASSWORD * 2]; u_char PasswordHash[MD4_SIGNATURE_SIZE]; u_char PasswordHashHash[MD4_SIGNATURE_SIZE]; - lwip_sha1_context sha1Context; + SHA1_context sha1Context; u_char Digest[SHA1_SIGNATURE_SIZE]; /* >= MPPE_MAX_KEY_LEN */ /* Hash (x2) the Unicode version of the secret (== password). */ @@ -723,13 +723,13 @@ static void Set_Start_Key(ppp_pcb *pcb, const u_char *rchallenge, const char *se NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash); NTPasswordHash(PasswordHash, sizeof(PasswordHash), PasswordHashHash); - lwip_sha1_init(&sha1Context); - lwip_sha1_starts(&sha1Context); - lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - lwip_sha1_update(&sha1Context, rchallenge, 8); - lwip_sha1_finish(&sha1Context, Digest); - lwip_sha1_free(&sha1Context); + SHA1_init(&sha1Context); + SHA1_starts(&sha1Context); + SHA1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1_update(&sha1Context, rchallenge, 8); + SHA1_finish(&sha1Context, Digest); + SHA1_free(&sha1Context); /* Same key in both directions. */ mppe_set_key(pcb, &pcb->mppe_comp, Digest); @@ -745,7 +745,7 @@ static void SetMasterKeys(ppp_pcb *pcb, const char *secret, int secret_len, u_ch u_char unicodePassword[MAX_NT_PASSWORD * 2]; u_char PasswordHash[MD4_SIGNATURE_SIZE]; u_char PasswordHashHash[MD4_SIGNATURE_SIZE]; - lwip_sha1_context sha1Context; + SHA1_context sha1Context; u_char MasterKey[SHA1_SIGNATURE_SIZE]; /* >= MPPE_MAX_KEY_LEN */ u_char Digest[SHA1_SIGNATURE_SIZE]; /* >= MPPE_MAX_KEY_LEN */ const u_char *s; @@ -785,13 +785,13 @@ static void SetMasterKeys(ppp_pcb *pcb, const char *secret, int secret_len, u_ch NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash); NTPasswordHash(PasswordHash, sizeof(PasswordHash), PasswordHashHash); - lwip_sha1_init(&sha1Context); - lwip_sha1_starts(&sha1Context); - lwip_sha1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - lwip_sha1_update(&sha1Context, NTResponse, 24); - lwip_sha1_update(&sha1Context, Magic1, sizeof(Magic1)); - lwip_sha1_finish(&sha1Context, MasterKey); - lwip_sha1_free(&sha1Context); + SHA1_init(&sha1Context); + SHA1_starts(&sha1Context); + SHA1_update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1_update(&sha1Context, NTResponse, 24); + SHA1_update(&sha1Context, Magic1, sizeof(Magic1)); + SHA1_finish(&sha1Context, MasterKey); + SHA1_free(&sha1Context); /* * generate send key @@ -800,14 +800,14 @@ static void SetMasterKeys(ppp_pcb *pcb, const char *secret, int secret_len, u_ch s = Magic3; else s = Magic2; - lwip_sha1_init(&sha1Context); - lwip_sha1_starts(&sha1Context); - lwip_sha1_update(&sha1Context, MasterKey, 16); - lwip_sha1_update(&sha1Context, mppe_sha1_pad1, SHA1_PAD_SIZE); - lwip_sha1_update(&sha1Context, s, 84); - lwip_sha1_update(&sha1Context, mppe_sha1_pad2, SHA1_PAD_SIZE); - lwip_sha1_finish(&sha1Context, Digest); - lwip_sha1_free(&sha1Context); + SHA1_init(&sha1Context); + SHA1_starts(&sha1Context); + SHA1_update(&sha1Context, MasterKey, 16); + SHA1_update(&sha1Context, mppe_sha1_pad1, SHA1_PAD_SIZE); + SHA1_update(&sha1Context, s, 84); + SHA1_update(&sha1Context, mppe_sha1_pad2, SHA1_PAD_SIZE); + SHA1_finish(&sha1Context, Digest); + SHA1_free(&sha1Context); mppe_set_key(pcb, &pcb->mppe_comp, Digest); @@ -818,14 +818,14 @@ static void SetMasterKeys(ppp_pcb *pcb, const char *secret, int secret_len, u_ch s = Magic2; else s = Magic3; - lwip_sha1_init(&sha1Context); - lwip_sha1_starts(&sha1Context); - lwip_sha1_update(&sha1Context, MasterKey, 16); - lwip_sha1_update(&sha1Context, mppe_sha1_pad1, SHA1_PAD_SIZE); - lwip_sha1_update(&sha1Context, s, 84); - lwip_sha1_update(&sha1Context, mppe_sha1_pad2, SHA1_PAD_SIZE); - lwip_sha1_finish(&sha1Context, Digest); - lwip_sha1_free(&sha1Context); + SHA1_init(&sha1Context); + SHA1_starts(&sha1Context); + SHA1_update(&sha1Context, MasterKey, 16); + SHA1_update(&sha1Context, mppe_sha1_pad1, SHA1_PAD_SIZE); + SHA1_update(&sha1Context, s, 84); + SHA1_update(&sha1Context, mppe_sha1_pad2, SHA1_PAD_SIZE); + SHA1_finish(&sha1Context, Digest); + SHA1_free(&sha1Context); mppe_set_key(pcb, &pcb->mppe_decomp, Digest); @@ -838,7 +838,7 @@ static void SetMasterKeys(ppp_pcb *pcb, const char *secret, int secret_len, u_ch static void ChapMS(ppp_pcb *pcb, const u_char *rchallenge, const char *secret, int secret_len, unsigned char *response) { #if !MPPE_SUPPORT - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); #endif /* !MPPE_SUPPORT */ BZERO(response, MS_CHAP_RESPONSE_LEN); @@ -874,9 +874,9 @@ static void ChapMS2(ppp_pcb *pcb, const u_char *rchallenge, const u_char *PeerCh const char *user, const char *secret, int secret_len, unsigned char *response, u_char authResponse[], int authenticator) { /* ARGSUSED */ - LWIP_UNUSED_ARG(authenticator); + PPP_UNUSED_ARG(authenticator); #if !MPPE_SUPPORT - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); #endif /* !MPPE_SUPPORT */ BZERO(response, MS_CHAP2_RESPONSE_LEN); diff --git a/features/netsocket/ppp/demand.c b/features/netsocket/ppp/source/demand.c similarity index 99% rename from features/netsocket/ppp/demand.c rename to features/netsocket/ppp/source/demand.c index 374c1dcdc2..859026178e 100644 --- a/features/netsocket/ppp/demand.c +++ b/features/netsocket/ppp/source/demand.c @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && DEMAND_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && DEMAND_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include #include @@ -98,7 +98,7 @@ demand_conf() flush_flag = 0; fcs = PPP_INITFCS; - netif_set_mtu(pcb, LWIP_MIN(lcp_allowoptions[0].mru, PPP_MRU)); + netif_set_mtu(pcb, PPP_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"); diff --git a/features/netsocket/ppp/eap.c b/features/netsocket/ppp/source/eap.c similarity index 95% rename from features/netsocket/ppp/eap.c rename to features/netsocket/ppp/source/eap.c index 95f1dace23..4bb771042d 100644 --- a/features/netsocket/ppp/eap.c +++ b/features/netsocket/ppp/source/eap.c @@ -44,7 +44,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include "ppp_impl.h" #include "eap.h" @@ -251,11 +251,13 @@ static void eap_send_failure(ppp_pcb *pcb) { struct pbuf *p; u_char *outp; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -282,11 +284,13 @@ static void eap_send_success(ppp_pcb *pcb) { struct pbuf *p; u_char *outp; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -683,11 +687,13 @@ static void eap_send_request(ppp_pcb *pcb) { return; } - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_CTRL_PBUF_MAX_SIZE), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_CTRL_PBUF_MAX_SIZE), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_CTRL_PBUF_MAX_SIZE), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -1018,11 +1024,13 @@ static void eap_send_response(ppp_pcb *pcb, u_char id, u_char typenum, const u_c int msglen; msglen = EAP_HEADERLEN + sizeof (u_char) + lenstr; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN + msglen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -1052,11 +1060,13 @@ static void eap_chap_response(ppp_pcb *pcb, u_char id, u_char *hash, const char msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + MD5_SIGNATURE_SIZE + namelen; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN + msglen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -1097,11 +1107,13 @@ int lenstr; int msglen; msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + lenstr; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN + msglen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -1139,11 +1151,13 @@ u_char *str; msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + sizeof (u32_t) + SHA_DIGESTSIZE; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN + msglen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -1170,11 +1184,13 @@ static void eap_send_nak(ppp_pcb *pcb, u_char id, u_char type) { int msglen; msglen = EAP_HEADERLEN + 2 * sizeof (u_char); - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN + msglen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -1314,7 +1330,7 @@ static void eap_request(ppp_pcb *pcb, u_char *inp, int id, int len) { int secret_len; char secret[MAXSECRETLEN]; char rhostname[MAXNAMELEN]; - lwip_md5_context mdContext; + MD5_context mdContext; u_char hash[MD5_SIGNATURE_SIZE]; #ifdef USE_SRP struct t_client *tc; @@ -1443,15 +1459,15 @@ static void eap_request(ppp_pcb *pcb, u_char *inp, int id, int len) { eap_send_nak(pcb, id, EAPT_SRP); break; } - lwip_md5_init(&mdContext); - lwip_md5_starts(&mdContext); + MD5_init(&mdContext); + MD5_starts(&mdContext); typenum = id; - lwip_md5_update(&mdContext, &typenum, 1); - lwip_md5_update(&mdContext, (u_char *)secret, secret_len); + MD5_update(&mdContext, &typenum, 1); + MD5_update(&mdContext, (u_char *)secret, secret_len); BZERO(secret, sizeof (secret)); - lwip_md5_update(&mdContext, inp, vallen); - lwip_md5_finish(&mdContext, hash); - lwip_md5_free(&mdContext); + MD5_update(&mdContext, inp, vallen); + MD5_finish(&mdContext, hash); + MD5_free(&mdContext); eap_chap_response(pcb, id, hash, pcb->eap.es_client.ea_name, pcb->eap.es_client.ea_namelen); break; @@ -1728,7 +1744,7 @@ static void eap_response(ppp_pcb *pcb, u_char *inp, int id, int len) { int secret_len; char secret[MAXSECRETLEN]; char rhostname[MAXNAMELEN]; - lwip_md5_context mdContext; + MD5_context mdContext; u_char hash[MD5_SIGNATURE_SIZE]; #ifdef USE_SRP struct t_server *ts; @@ -1871,14 +1887,14 @@ static void eap_response(ppp_pcb *pcb, u_char *inp, int id, int len) { eap_send_failure(pcb); break; } - lwip_md5_init(&mdContext); - lwip_md5_starts(&mdContext); - lwip_md5_update(&mdContext, &pcb->eap.es_server.ea_id, 1); - lwip_md5_update(&mdContext, (u_char *)secret, secret_len); + MD5_init(&mdContext); + MD5_starts(&mdContext); + MD5_update(&mdContext, &pcb->eap.es_server.ea_id, 1); + MD5_update(&mdContext, (u_char *)secret, secret_len); BZERO(secret, sizeof (secret)); - lwip_md5_update(&mdContext, pcb->eap.es_challenge, pcb->eap.es_challen); - lwip_md5_finish(&mdContext, hash); - lwip_md5_free(&mdContext); + MD5_update(&mdContext, pcb->eap.es_challenge, pcb->eap.es_challen); + MD5_finish(&mdContext, hash); + MD5_free(&mdContext); if (BCMP(hash, inp, MD5_SIGNATURE_SIZE) != 0) { eap_send_failure(pcb); break; @@ -2015,7 +2031,7 @@ static void eap_response(ppp_pcb *pcb, u_char *inp, int id, int len) { * eap_success - Receive EAP Success message (client mode). */ static void eap_success(ppp_pcb *pcb, u_char *inp, int id, int len) { - LWIP_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); if (pcb->eap.es_client.ea_state != eapOpen && !eap_client_active(pcb)) { ppp_dbglog("EAP unexpected success message in state %s (%d)", @@ -2041,7 +2057,7 @@ static void eap_success(ppp_pcb *pcb, u_char *inp, int id, int len) { * eap_failure - Receive EAP Failure message (client mode). */ static void eap_failure(ppp_pcb *pcb, u_char *inp, int id, int len) { - LWIP_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); if (!eap_client_active(pcb)) { ppp_dbglog("EAP unexpected failure message in state %s (%d)", @@ -2146,7 +2162,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c if (len < EAP_HEADERLEN || len > inlen) return (0); - if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(eap_codenames)) + if (code >= 1 && code <= (int)PPP_ARRAYSIZE(eap_codenames)) printer(arg, " %s", eap_codenames[code-1]); else printer(arg, " code=0x%x", code); @@ -2160,7 +2176,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c } GETCHAR(rtype, inp); len--; - if (rtype >= 1 && rtype <= (int)LWIP_ARRAYSIZE(eap_typenames)) + if (rtype >= 1 && rtype <= (int)PPP_ARRAYSIZE(eap_typenames)) printer(arg, " %s", eap_typenames[rtype-1]); else printer(arg, " type=0x%x", rtype); @@ -2298,7 +2314,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c break; GETCHAR(rtype, inp); len--; - if (rtype >= 1 && rtype <= (int)LWIP_ARRAYSIZE(eap_typenames)) + if (rtype >= 1 && rtype <= (int)PPP_ARRAYSIZE(eap_typenames)) printer(arg, " %s", eap_typenames[rtype-1]); else printer(arg, " type=0x%x", rtype); @@ -2321,7 +2337,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c GETCHAR(rtype, inp); len--; printer(arg, " = 1 && rtype < (int)LWIP_ARRAYSIZE(eap_typenames)) + if (rtype >= 1 && rtype < (int)PPP_ARRAYSIZE(eap_typenames)) printer(arg, " (%s)", eap_typenames[rtype-1]); printer(arg, ">"); break; diff --git a/features/netsocket/ppp/eui64.c b/features/netsocket/ppp/source/eui64.c similarity index 98% rename from features/netsocket/ppp/eui64.c rename to features/netsocket/ppp/source/eui64.c index 05036c6863..ef3faeb8da 100644 --- a/features/netsocket/ppp/eui64.c +++ b/features/netsocket/ppp/source/eui64.c @@ -36,7 +36,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include "ppp_impl.h" #include "eui64.h" diff --git a/features/netsocket/ppp/fsm.c b/features/netsocket/ppp/source/fsm.c similarity index 96% rename from features/netsocket/ppp/fsm.c rename to features/netsocket/ppp/source/fsm.c index 84caf656d4..4423a82eb3 100644 --- a/features/netsocket/ppp/fsm.c +++ b/features/netsocket/ppp/source/fsm.c @@ -41,7 +41,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ /* * @todo: @@ -236,7 +236,7 @@ static void terminate_layer(fsm *f, int nextstate) { */ void fsm_close(fsm *f, const char *reason) { f->term_reason = reason; - f->term_reason_len = (reason == NULL? 0: (u8_t)LWIP_MIN(strlen(reason), 0xFF) ); + f->term_reason_len = (reason == NULL? 0: (u8_t)PPP_MIN(strlen(reason), 0xFF) ); switch( f->state ){ case PPP_FSM_STARTING: f->state = PPP_FSM_INITIAL; @@ -735,23 +735,26 @@ static void fsm_sconfreq(fsm *f, int retransmit) { } else cilen = 0; - p = pbuf_alloc(PBUF_RAW, (u16_t)(cilen + HEADERLEN + PPP_HDRLEN), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, cilen + HEADERLEN + PPP_HDRLEN, PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(cilen + HEADERLEN + PPP_HDRLEN), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } /* send the request to our peer */ outp = (u_char*)p->payload; + MAKEHEADER(outp, f->protocol); PUTCHAR(CONFREQ, outp); PUTCHAR(f->reqid, outp); PUTSHORT(cilen + HEADERLEN, outp); if (cilen != 0) { (*f->callbacks->addci)(f, outp, &cilen); - LWIP_ASSERT("cilen == p->len - HEADERLEN - PPP_HDRLEN", cilen == p->len - HEADERLEN - PPP_HDRLEN); + PPP_ASSERT("cilen == p->len - HEADERLEN - PPP_HDRLEN", cilen == p->len - HEADERLEN - PPP_HDRLEN); } ppp_write(pcb, p); @@ -778,15 +781,18 @@ void fsm_sdata(fsm *f, u_char code, u_char id, const u_char *data, int datalen) datalen = pcb->peer_mru - HEADERLEN; outlen = datalen + HEADERLEN; - p = pbuf_alloc(PBUF_RAW, (u16_t)(outlen + PPP_HDRLEN), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(outlen + PPP_HDRLEN), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(outlen + PPP_HDRLEN), PPP_CTRL_PBUF_TYPE); + if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } - outp = (u_char*)p->payload; + if (datalen) /* && data != outp + PPP_HDRLEN + HEADERLEN) -- was only for fsm_sconfreq() */ MEMCPY(outp + PPP_HDRLEN + HEADERLEN, data, datalen); MAKEHEADER(outp, f->protocol); diff --git a/features/netsocket/ppp/ipcp.c b/features/netsocket/ppp/source/ipcp.c similarity index 96% rename from features/netsocket/ppp/ipcp.c rename to features/netsocket/ppp/source/ipcp.c index 540029121c..11427b40bc 100644 --- a/features/netsocket/ppp/ipcp.c +++ b/features/netsocket/ppp/source/ipcp.c @@ -41,7 +41,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPP_IPV4_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPP_IPV4_SUPPORT /* don't build if not configured for use in ppp_opts.h */ /* * @todo: @@ -59,10 +59,10 @@ #include #endif /* UNUSED */ -#include "netif/ppp/ppp_impl.h" +#include "ppp_impl.h" -#include "netif/ppp/fsm.h" -#include "netif/ppp/ipcp.h" +#include "fsm.h" +#include "ipcp.h" #if 0 /* UNUSED */ /* global vars */ @@ -322,7 +322,7 @@ static void ipcp_clear_addrs(ppp_pcb *pcb, u32_t ouraddr, u32_t hisaddr, u8_t re #define CODENAME(x) ((x) == CONFACK ? "ACK" : \ (x) == CONFNAK ? "NAK" : "REJ") -#if 0 /* UNUSED, already defined by lwIP */ +#if 0 /* UNUSED, already defined by stack */ /* * Make a string representation of a network IP address. */ @@ -335,7 +335,7 @@ u32_t ipaddr; slprintf(b, sizeof(b), "%I", ipaddr); return b; } -#endif /* UNUSED, already defined by lwIP */ +#endif /* UNUSED, already defined by stack */ /* * Option parsing. @@ -539,7 +539,7 @@ setnetmask(argv) p = *argv; n = parse_dotted_ip(p, &mask); - mask = lwip_htonl(mask); + mask = ppp_htonl(mask); if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) { option_error("invalid netmask value '%s'", *argv); @@ -726,9 +726,9 @@ static void ipcp_resetci(fsm *f) { wo->accept_local = 1; if (wo->hisaddr == 0) wo->accept_remote = 1; -#if LWIP_DNS +#if PPP_DNS wo->req_dns1 = wo->req_dns2 = pcb->settings.usepeerdns; /* Request DNS addresses from the peer */ -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ *go = *wo; if (!pcb->ask_for_local) go->ouraddr = 0; @@ -761,9 +761,9 @@ static int ipcp_cilen(fsm *f) { #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0) #endif /* VJ_SUPPORT */ #define LENCIADDR(neg) (neg ? CILEN_ADDR : 0) -#if LWIP_DNS +#if PPP_DNS #define LENCIDNS(neg) LENCIADDR(neg) -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ #define LENCIWINS(neg) LENCIADDR(neg) #endif /* UNUSED - WINS */ @@ -792,10 +792,10 @@ static int ipcp_cilen(fsm *f) { LENCIVJ(go->neg_vj, go->old_vj) + #endif /* VJ_SUPPORT */ LENCIADDR(go->neg_addr) + -#if LWIP_DNS +#if PPP_DNS LENCIDNS(go->req_dns1) + LENCIDNS(go->req_dns2) + -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ LENCIWINS(go->winsaddr[0]) + LENCIWINS(go->winsaddr[1]) + @@ -819,9 +819,9 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDRS, ucp); \ - l = lwip_ntohl(val1); \ + l = ppp_ntohl(val1); \ PUTLONG(l, ucp); \ - l = lwip_ntohl(val2); \ + l = ppp_ntohl(val2); \ PUTLONG(l, ucp); \ len -= CILEN_ADDRS; \ } else \ @@ -852,27 +852,27 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDR, ucp); \ - l = lwip_ntohl(val); \ + l = ppp_ntohl(val); \ PUTLONG(l, ucp); \ len -= CILEN_ADDR; \ } else \ neg = 0; \ } -#if LWIP_DNS +#if PPP_DNS #define ADDCIDNS(opt, neg, addr) \ if (neg) { \ if (len >= CILEN_ADDR) { \ u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDR, ucp); \ - l = lwip_ntohl(addr); \ + l = ppp_ntohl(addr); \ PUTLONG(l, ucp); \ len -= CILEN_ADDR; \ } else \ neg = 0; \ } -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ #define ADDCIWINS(opt, addr) \ @@ -881,7 +881,7 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDR, ucp); \ - l = lwip_ntohl(addr); \ + l = ppp_ntohl(addr); \ PUTLONG(l, ucp); \ len -= CILEN_ADDR; \ } else \ @@ -899,11 +899,11 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { ADDCIADDR(CI_ADDR, go->neg_addr, go->ouraddr); -#if LWIP_DNS +#if PPP_DNS ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]); ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]); -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ ADDCIWINS(CI_MS_WINS1, go->winsaddr[0]); @@ -950,11 +950,11 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ if (val1 != cilong) \ goto bad; \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ if (val2 != cilong) \ goto bad; \ } @@ -995,12 +995,12 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ if (val != cilong) \ goto bad; \ } -#if LWIP_DNS +#if PPP_DNS #define ACKCIDNS(opt, neg, addr) \ if (neg) { \ u32_t l; \ @@ -1011,11 +1011,11 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { if (cilen != CILEN_ADDR || citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ if (addr != cilong) \ goto bad; \ } -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ #define ACKCIWINS(opt, addr) \ @@ -1028,7 +1028,7 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { if (cilen != CILEN_ADDR || citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ if (addr != cilong) \ goto bad; \ } @@ -1044,11 +1044,11 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { ACKCIADDR(CI_ADDR, go->neg_addr, go->ouraddr); -#if LWIP_DNS +#if PPP_DNS ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]); ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]); -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ ACKCIWINS(CI_MS_WINS1, go->winsaddr[0]); @@ -1087,9 +1087,9 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { u_short cishort; #endif /* VJ_SUPPORT */ u32_t ciaddr1, ciaddr2, l; -#if LWIP_DNS +#if PPP_DNS u32_t cidnsaddr; -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ ipcp_options no; /* options we've seen Naks for */ ipcp_options try_; /* options to request next time */ @@ -1109,9 +1109,9 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - ciaddr1 = lwip_htonl(l); \ + ciaddr1 = ppp_htonl(l); \ GETLONG(l, p); \ - ciaddr2 = lwip_htonl(l); \ + ciaddr2 = ppp_htonl(l); \ no.old_addrs = 1; \ code \ } @@ -1138,12 +1138,12 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - ciaddr1 = lwip_htonl(l); \ + ciaddr1 = ppp_htonl(l); \ no.neg = 1; \ code \ } -#if LWIP_DNS +#if PPP_DNS #define NAKCIDNS(opt, neg, code) \ if (go->neg && \ ((cilen = p[1]) == CILEN_ADDR) && \ @@ -1152,11 +1152,11 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cidnsaddr = lwip_htonl(l); \ + cidnsaddr = ppp_htonl(l); \ no.neg = 1; \ code \ } -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ /* * Accept the peer's idea of {our,his} address, if different @@ -1220,7 +1220,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { } ); -#if LWIP_DNS +#if PPP_DNS NAKCIDNS(CI_MS_DNS1, req_dns1, if (treat_as_reject) { try_.req_dns1 = 0; @@ -1236,7 +1236,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { try_.dnsaddr[1] = cidnsaddr; } ); -#endif /* #if LWIP_DNS */ +#endif /* #if PPP_DNS */ /* * There may be remaining CIs, if the peer is requesting negotiation @@ -1268,11 +1268,11 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { goto bad; try_.neg_addr = 0; GETLONG(l, p); - ciaddr1 = lwip_htonl(l); + ciaddr1 = ppp_htonl(l); if (ciaddr1 && go->accept_local) try_.ouraddr = ciaddr1; GETLONG(l, p); - ciaddr2 = lwip_htonl(l); + ciaddr2 = ppp_htonl(l); if (ciaddr2 && go->accept_remote) try_.hisaddr = ciaddr2; no.old_addrs = 1; @@ -1282,19 +1282,19 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { goto bad; try_.old_addrs = 0; GETLONG(l, p); - ciaddr1 = lwip_htonl(l); + ciaddr1 = ppp_htonl(l); if (ciaddr1 && go->accept_local) try_.ouraddr = ciaddr1; if (try_.ouraddr != 0) try_.neg_addr = 1; no.neg_addr = 1; break; -#if LWIP_DNS +#if PPP_DNS case CI_MS_DNS1: if (go->req_dns1 || no.req_dns1 || cilen != CILEN_ADDR) goto bad; GETLONG(l, p); - try_.dnsaddr[0] = lwip_htonl(l); + try_.dnsaddr[0] = ppp_htonl(l); try_.req_dns1 = 1; no.req_dns1 = 1; break; @@ -1302,18 +1302,18 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { if (go->req_dns2 || no.req_dns2 || cilen != CILEN_ADDR) goto bad; GETLONG(l, p); - try_.dnsaddr[1] = lwip_htonl(l); + try_.dnsaddr[1] = ppp_htonl(l); try_.req_dns2 = 1; no.req_dns2 = 1; break; -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ case CI_MS_WINS1: case CI_MS_WINS2: if (cilen != CILEN_ADDR) goto bad; GETLONG(l, p); - ciaddr1 = lwip_htonl(l); + ciaddr1 = ppp_htonl(l); if (ciaddr1) try_.winsaddr[citype == CI_MS_WINS2] = ciaddr1; break; @@ -1369,12 +1369,12 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ /* Check rejected value. */ \ if (cilong != val1) \ goto bad; \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ /* Check rejected value. */ \ if (cilong != val2) \ goto bad; \ @@ -1414,14 +1414,14 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ /* Check rejected value. */ \ if (cilong != val) \ goto bad; \ try_.neg = 0; \ } -#if LWIP_DNS +#if PPP_DNS #define REJCIDNS(opt, neg, dnsaddr) \ if (go->neg && \ ((cilen = p[1]) == CILEN_ADDR) && \ @@ -1431,13 +1431,13 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ /* Check rejected value. */ \ if (cilong != dnsaddr) \ goto bad; \ try_.neg = 0; \ } -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ #define REJCIWINS(opt, addr) \ @@ -1449,7 +1449,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = lwip_htonl(l); \ + cilong = ppp_htonl(l); \ /* Check rejected value. */ \ if (cilong != addr) \ goto bad; \ @@ -1467,11 +1467,11 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { REJCIADDR(CI_ADDR, neg_addr, go->ouraddr); -#if LWIP_DNS +#if PPP_DNS REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]); REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]); -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ REJCIWINS(CI_MS_WINS1, go->winsaddr[0]); @@ -1527,9 +1527,9 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { #if VJ_SUPPORT u_char maxslotindex, cflag; #endif /* VJ_SUPPORT */ -#if LWIP_DNS +#if PPP_DNS int d; -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ /* * Reset all his options. @@ -1572,13 +1572,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { * then accept it. */ GETLONG(tl, p); /* Parse source address (his) */ - ciaddr1 = lwip_htonl(tl); + ciaddr1 = ppp_htonl(tl); if (ciaddr1 != wo->hisaddr && (ciaddr1 == 0 || !wo->accept_remote)) { orc = CONFNAK; if (!reject_if_disagree) { DECPTR(sizeof(u32_t), p); - tl = lwip_ntohl(wo->hisaddr); + tl = ppp_ntohl(wo->hisaddr); PUTLONG(tl, p); } } else if (ciaddr1 == 0 && wo->hisaddr == 0) { @@ -1595,13 +1595,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { * but disagree about it, then NAK it with our idea. */ GETLONG(tl, p); /* Parse desination address (ours) */ - ciaddr2 = lwip_htonl(tl); + ciaddr2 = ppp_htonl(tl); if (ciaddr2 != wo->ouraddr) { if (ciaddr2 == 0 || !wo->accept_local) { orc = CONFNAK; if (!reject_if_disagree) { DECPTR(sizeof(u32_t), p); - tl = lwip_ntohl(wo->ouraddr); + tl = ppp_ntohl(wo->ouraddr); PUTLONG(tl, p); } } else { @@ -1628,13 +1628,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { * then accept it. */ GETLONG(tl, p); /* Parse source address (his) */ - ciaddr1 = lwip_htonl(tl); + ciaddr1 = ppp_htonl(tl); if (ciaddr1 != wo->hisaddr && (ciaddr1 == 0 || !wo->accept_remote)) { orc = CONFNAK; if (!reject_if_disagree) { DECPTR(sizeof(u32_t), p); - tl = lwip_ntohl(wo->hisaddr); + tl = ppp_ntohl(wo->hisaddr); PUTLONG(tl, p); } } else if (ciaddr1 == 0 && wo->hisaddr == 0) { @@ -1650,7 +1650,7 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { ho->hisaddr = ciaddr1; break; -#if LWIP_DNS +#if PPP_DNS case CI_MS_DNS1: case CI_MS_DNS2: /* Microsoft primary or secondary DNS request */ @@ -1663,14 +1663,14 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { break; } GETLONG(tl, p); - if (lwip_htonl(tl) != ao->dnsaddr[d]) { + if (ppp_htonl(tl) != ao->dnsaddr[d]) { DECPTR(sizeof(u32_t), p); - tl = lwip_ntohl(ao->dnsaddr[d]); + tl = ppp_ntohl(ao->dnsaddr[d]); PUTLONG(tl, p); orc = CONFNAK; } break; -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ case CI_MS_WINS1: @@ -1685,9 +1685,9 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { break; } GETLONG(tl, p); - if (lwip_htonl(tl) != ao->winsaddr[d]) { + if (ppp_htonl(tl) != ao->winsaddr[d]) { DECPTR(sizeof(u32_t), p); - tl = lwip_ntohl(ao->winsaddr[d]); + tl = ppp_ntohl(ao->winsaddr[d]); PUTLONG(tl, p); orc = CONFNAK; } @@ -1790,7 +1790,7 @@ endswitch: } PUTCHAR(CI_ADDR, ucp); PUTCHAR(CILEN_ADDR, ucp); - tl = lwip_ntohl(wo->hisaddr); + tl = ppp_ntohl(wo->hisaddr); PUTLONG(tl, ucp); } @@ -1847,12 +1847,12 @@ ip_demand_conf(u) if (wo->hisaddr == 0 && !pcb->settings.noremoteip) { /* make up an arbitrary address for the peer */ - wo->hisaddr = lwip_htonl(0x0a707070 + ifunit); + wo->hisaddr = ppp_htonl(0x0a707070 + ifunit); wo->accept_remote = 1; } if (wo->ouraddr == 0) { /* make up an arbitrary address for us */ - wo->ouraddr = lwip_htonl(0x0a404040 + ifunit); + wo->ouraddr = ppp_htonl(0x0a404040 + ifunit); wo->accept_local = 1; ask_for_local = 0; /* don't tell the peer this address */ } @@ -1914,7 +1914,7 @@ static void ipcp_up(fsm *f) { return; } if (ho->hisaddr == 0 && !pcb->settings.noremoteip) { - ho->hisaddr = lwip_htonl(0x0a404040); + ho->hisaddr = ppp_htonl(0x0a404040); ppp_warn("Could not determine remote IP address: defaulting to %I", ho->hisaddr); } @@ -1924,7 +1924,7 @@ static void ipcp_up(fsm *f) { script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1); #endif /* UNUSED */ -#if LWIP_DNS +#if PPP_DNS if (!go->req_dns1) go->dnsaddr[0] = 0; if (!go->req_dns2) @@ -1942,13 +1942,13 @@ static void ipcp_up(fsm *f) { create_resolv(go->dnsaddr[0], go->dnsaddr[1]); #endif /* UNUSED */ } -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ /* * Check that the peer is allowed to use the IP address it wants. */ if (ho->hisaddr != 0) { - u32_t addr = lwip_ntohl(ho->hisaddr); + u32_t addr = ppp_ntohl(ho->hisaddr); if ((addr >> IP_CLASSA_NSHIFT) == IP_LOOPBACKNET || IP_MULTICAST(addr) || IP_BADCLASS(addr) /* @@ -2089,12 +2089,12 @@ static void ipcp_up(fsm *f) { ppp_notice("local IP address %I", go->ouraddr); if (ho->hisaddr != 0) ppp_notice("remote IP address %I", ho->hisaddr); -#if LWIP_DNS +#if PPP_DNS if (go->dnsaddr[0]) ppp_notice("primary DNS address %I", go->dnsaddr[0]); if (go->dnsaddr[1]) ppp_notice("secondary DNS address %I", go->dnsaddr[1]); -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ } #if PPP_STATS_SUPPORT @@ -2170,9 +2170,9 @@ static void ipcp_down(fsm *f) { sifdown(pcb); ipcp_clear_addrs(pcb, go->ouraddr, ho->hisaddr, 0); -#if LWIP_DNS +#if PPP_DNS cdns(pcb, go->dnsaddr[0], go->dnsaddr[1]); -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ } } @@ -2182,7 +2182,7 @@ static void ipcp_down(fsm *f) { * proxy arp entries, etc. */ static void ipcp_clear_addrs(ppp_pcb *pcb, u32_t ouraddr, u32_t hisaddr, u8_t replacedefaultroute) { - LWIP_UNUSED_ARG(replacedefaultroute); + PPP_UNUSED_ARG(replacedefaultroute); #if 0 /* UNUSED - PROXY ARP */ if (pcb->proxy_arp_set) { @@ -2259,7 +2259,7 @@ static int ipcp_printpkt(const u_char *p, int plen, if (len < HEADERLEN || len > plen) return 0; - if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(ipcp_codenames)) + if (code >= 1 && code <= (int)PPP_ARRAYSIZE(ipcp_codenames)) printer(arg, " %s", ipcp_codenames[code-1]); else printer(arg, " code=0x%x", code); @@ -2286,9 +2286,9 @@ static int ipcp_printpkt(const u_char *p, int plen, if (olen == CILEN_ADDRS) { p += 2; GETLONG(cilong, p); - printer(arg, "addrs %I", lwip_htonl(cilong)); + printer(arg, "addrs %I", ppp_htonl(cilong)); GETLONG(cilong, p); - printer(arg, " %I", lwip_htonl(cilong)); + printer(arg, " %I", ppp_htonl(cilong)); } break; #if VJ_SUPPORT @@ -2314,10 +2314,10 @@ static int ipcp_printpkt(const u_char *p, int plen, if (olen == CILEN_ADDR) { p += 2; GETLONG(cilong, p); - printer(arg, "addr %I", lwip_htonl(cilong)); + printer(arg, "addr %I", ppp_htonl(cilong)); } break; -#if LWIP_DNS +#if PPP_DNS case CI_MS_DNS1: case CI_MS_DNS2: p += 2; @@ -2325,13 +2325,13 @@ static int ipcp_printpkt(const u_char *p, int plen, printer(arg, "ms-dns%d %I", (code == CI_MS_DNS1? 1: 2), htonl(cilong)); break; -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if 0 /* UNUSED - WINS */ case CI_MS_WINS1: case CI_MS_WINS2: p += 2; GETLONG(cilong, p); - printer(arg, "ms-wins %I", lwip_htonl(cilong)); + printer(arg, "ms-wins %I", ppp_htonl(cilong)); break; #endif /* UNUSED - WINS */ default: diff --git a/features/netsocket/ppp/ipv6cp.c b/features/netsocket/ppp/source/ipv6cp.c similarity index 99% rename from features/netsocket/ppp/ipv6cp.c rename to features/netsocket/ppp/source/ipv6cp.c index fca2861585..616e8605bc 100644 --- a/features/netsocket/ppp/ipv6cp.c +++ b/features/netsocket/ppp/source/ipv6cp.c @@ -148,7 +148,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #if 0 /* UNUSED */ #include @@ -1098,7 +1098,7 @@ static void ipv6_check_options() { if (!wo->opt_local) { /* init interface identifier */ if (wo->use_ip && eui64_iszero(wo->ourid)) { - eui64_setlo32(wo->ourid, lwip_ntohl(ipcp_wantoptions[0].ouraddr)); + eui64_setlo32(wo->ourid, ppp_ntohl(ipcp_wantoptions[0].ouraddr)); if (!eui64_iszero(wo->ourid)) wo->opt_local = 1; } @@ -1109,7 +1109,7 @@ static void ipv6_check_options() { if (!wo->opt_remote) { if (wo->use_ip && eui64_iszero(wo->hisid)) { - eui64_setlo32(wo->hisid, lwip_ntohl(ipcp_wantoptions[0].hisaddr)); + eui64_setlo32(wo->hisid, ppp_ntohl(ipcp_wantoptions[0].hisaddr)); if (!eui64_iszero(wo->hisid)) wo->opt_remote = 1; } @@ -1421,7 +1421,7 @@ static int ipv6cp_printpkt(const u_char *p, int plen, if (len < HEADERLEN || len > plen) return 0; - if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(ipv6cp_codenames)) + if (code >= 1 && code <= (int)PPP_ARRAYSIZE(ipv6cp_codenames)) printer(arg, " %s", ipv6cp_codenames[code-1]); else printer(arg, " code=0x%x", code); diff --git a/features/netsocket/ppp/lcp.c b/features/netsocket/ppp/source/lcp.c similarity index 99% rename from features/netsocket/ppp/lcp.c rename to features/netsocket/ppp/source/lcp.c index 1c15839e30..3a5110c7b1 100644 --- a/features/netsocket/ppp/lcp.c +++ b/features/netsocket/ppp/source/lcp.c @@ -41,7 +41,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ /* * @todo: @@ -1443,7 +1443,7 @@ static int lcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { ); } #else /* HAVE_MULTILINK */ - LWIP_UNUSED_ARG(treat_as_reject); + PPP_UNUSED_ARG(treat_as_reject); #endif /* HAVE_MULTILINK */ /* @@ -1842,16 +1842,21 @@ static int lcp_reqci(fsm *f, u_char *inp, int *lenp, int reject_if_disagree) { /* * Process all his options. */ + next = inp; - nakp = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_CTRL_PBUF_MAX_SIZE), PPP_CTRL_PBUF_TYPE); + + nakp = ppp_memory_buffer_allocate(pcb->netif->memory_manager, PPP_CTRL_PBUF_MAX_SIZE, PPP_BUF_HEAP); + //nakp = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_CTRL_PBUF_MAX_SIZE), PPP_CTRL_PBUF_TYPE); if(NULL == nakp) return 0; if(nakp->tot_len != nakp->len) { - pbuf_free(nakp); + ppp_memory_buffer_free(nakp); + //pbuf_free(nakp); return 0; } nakoutp = (u_char*)nakp->payload; + rejp = inp; while (l) { orc = CONFACK; /* Assume success */ @@ -2268,7 +2273,8 @@ endswitch: /* * Copy the Nak'd options from the nak buffer to the caller's buffer. */ - *lenp = nakoutp - (u_char*)nakp->payload; + *lenp = nakoutp - (u_char*)nakp->payload; + MEMCPY(inp, nakp->payload, *lenp); break; case CONFREJ: @@ -2278,7 +2284,8 @@ endswitch: break; } - pbuf_free(nakp); + ppp_memory_buffer_free(nakp); + //pbuf_free(nakp); LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc))); return (rc); /* Return final code */ } @@ -2310,11 +2317,11 @@ static void lcp_up(fsm *f) { * MTU we want to use, and our link MRU. */ mtu = ho->neg_mru? ho->mru: PPP_MRU; - mru = go->neg_mru? LWIP_MAX(wo->mru, go->mru): PPP_MRU; + mru = go->neg_mru? PPP_MAX(wo->mru, go->mru): PPP_MRU; #ifdef HAVE_MULTILINK if (!(multilink && go->neg_mrru && ho->neg_mrru)) #endif /* HAVE_MULTILINK */ - netif_set_mtu(pcb, LWIP_MIN(LWIP_MIN(mtu, mru), ao->mru)); + netif_set_mtu(pcb, PPP_MIN(PPP_MIN(mtu, mru), ao->mru)); ppp_send_config(pcb, mtu, (ho->neg_asyncmap? ho->asyncmap: 0xffffffff), ho->neg_pcompression, ho->neg_accompression); @@ -2397,7 +2404,7 @@ static int lcp_printpkt(const u_char *p, int plen, if (len < HEADERLEN || len > plen) return 0; - if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(lcp_codenames)) + if (code >= 1 && code <= (int)PPP_ARRAYSIZE(lcp_codenames)) printer(arg, " %s", lcp_codenames[code-1]); else printer(arg, " code=0x%x", code); @@ -2687,7 +2694,7 @@ static void lcp_received_echo_reply(fsm *f, int id, u_char *inp, int len) { ppp_pcb *pcb = f->pcb; lcp_options *go = &pcb->lcp_gotoptions; u32_t magic_val; - LWIP_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); /* Check the magic number - don't count replies from ourselves. */ if (len < 4) { diff --git a/features/netsocket/ppp/magic.c b/features/netsocket/ppp/source/magic.c similarity index 86% rename from features/netsocket/ppp/magic.c rename to features/netsocket/ppp/source/magic.c index c4578ea3de..df34c7f792 100644 --- a/features/netsocket/ppp/magic.c +++ b/features/netsocket/ppp/source/magic.c @@ -73,7 +73,7 @@ *****************************************************************************/ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include "ppp_impl.h" #include "magic.h" @@ -98,33 +98,33 @@ static u32_t magic_randomseed; /* Seed used for random number generation. */ * 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; + 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)); + /* PPP_DEBUGF(LOG_INFO, ("magic_churnrand: %u@%P\n", rand_len, rand_data)); */ + MD5_init(&md5_ctx); + MD5_starts(&md5_ctx); + 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); + 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 +#ifdef PPP_RAND u32_t rand; -#endif /* LWIP_RAND */ +#endif /* PPP_RAND */ } sys_data; magic_randomseed += sys_jiffies(); sys_data.jiffies = magic_randomseed; -#ifdef LWIP_RAND - sys_data.rand = LWIP_RAND(); -#endif /* LWIP_RAND */ +#ifdef PPP_RAND + sys_data.rand = PPP_RAND(); +#endif /* PPP_RAND */ /* Load sys_data fields here. */ - lwip_md5_update(&md5_ctx, (u_char *)&sys_data, sizeof(sys_data)); + 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")); */ + MD5_finish(&md5_ctx, (u_char *)magic_randpool); + MD5_free(&md5_ctx); +/* PPP_DEBUGF(LOG_INFO, ("magic_churnrand: -> 0\n")); */ } /* @@ -160,19 +160,19 @@ void magic_randomize(void) { * it was documented. */ void magic_random_bytes(unsigned char *buf, u32_t buf_len) { - lwip_md5_context md5_ctx; + 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); + MD5_init(&md5_ctx); + MD5_starts(&md5_ctx); + MD5_update(&md5_ctx, (u_char *)magic_randpool, sizeof(magic_randpool)); + MD5_update(&md5_ctx, (u_char *)&magic_randcount, sizeof(magic_randcount)); + MD5_finish(&md5_ctx, tmp); + MD5_free(&md5_ctx); magic_randcount++; - n = LWIP_MIN(buf_len, MD5_HASH_SIZE); + n = PPP_MIN(buf_len, MD5_HASH_SIZE); MEMCPY(buf, tmp, n); buf += n; buf_len -= n; @@ -195,9 +195,9 @@ u32_t magic(void) { /*****************************/ /*** LOCAL DATA STRUCTURES ***/ /*****************************/ -#ifndef LWIP_RAND +#ifndef PPP_RAND static int magic_randomized; /* Set when truely randomized. */ -#endif /* LWIP_RAND */ +#endif /* PPP_RAND */ static u32_t magic_randomseed; /* Seed used for random number generation. */ @@ -221,10 +221,10 @@ static u32_t magic_randomseed; /* Seed used for random number generation. * */ void magic_init(void) { magic_randomseed += sys_jiffies(); -#ifndef LWIP_RAND +#ifndef PPP_RAND /* Initialize the Borland random number generator. */ srand((unsigned)magic_randomseed); -#endif /* LWIP_RAND */ +#endif /* PPP_RAND */ } /* @@ -237,17 +237,17 @@ void magic_init(void) { * bits. */ void magic_randomize(void) { -#ifndef LWIP_RAND +#ifndef PPP_RAND if (!magic_randomized) { magic_randomized = !0; magic_init(); /* The initialization function also updates the seed. */ } else { -#endif /* LWIP_RAND */ +#endif /* PPP_RAND */ magic_randomseed += sys_jiffies(); -#ifndef LWIP_RAND +#ifndef PPP_RAND } -#endif /* LWIP_RAND */ +#endif /* PPP_RAND */ } /* @@ -261,11 +261,11 @@ void magic_randomize(void) { * seeded by the real time clock. */ u32_t magic(void) { -#ifdef LWIP_RAND - return LWIP_RAND() + magic_randomseed; -#else /* LWIP_RAND */ +#ifdef PPP_RAND + return PPP_RAND() + magic_randomseed; +#else /* PPP_RAND */ return ((u32_t)rand() << 16) + (u32_t)rand() + magic_randomseed; -#endif /* LWIP_RAND */ +#endif /* PPP_RAND */ } /* @@ -276,7 +276,7 @@ void magic_random_bytes(unsigned char *buf, u32_t buf_len) { while (buf_len > 0) { new_rand = magic(); - n = LWIP_MIN(buf_len, sizeof(new_rand)); + n = PPP_MIN(buf_len, sizeof(new_rand)); MEMCPY(buf, &new_rand, n); buf += n; buf_len -= n; diff --git a/features/netsocket/ppp/mppe.c b/features/netsocket/ppp/source/mppe.c similarity index 90% rename from features/netsocket/ppp/mppe.c rename to features/netsocket/ppp/source/mppe.c index 3cfea2ce32..d9ee8cd60a 100644 --- a/features/netsocket/ppp/mppe.c +++ b/features/netsocket/ppp/source/mppe.c @@ -24,12 +24,10 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include -#include "lwip/err.h" - #include "ppp_impl.h" #include "ccp.h" #include "mppe.h" @@ -60,28 +58,28 @@ */ static void mppe_rekey(ppp_mppe_state * state, int initial_key) { - lwip_sha1_context sha1_ctx; + ppp_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); + ppp_sha1_init(&sha1_ctx); + ppp_sha1_starts(&sha1_ctx); + ppp_sha1_update(&sha1_ctx, state->master_key, state->keylen); + ppp_sha1_update(&sha1_ctx, mppe_sha1_pad1, SHA1_PAD_SIZE); + ppp_sha1_update(&sha1_ctx, state->session_key, state->keylen); + ppp_sha1_update(&sha1_ctx, mppe_sha1_pad2, SHA1_PAD_SIZE); + ppp_sha1_finish(&sha1_ctx, sha1_digest); + ppp_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); + ARC4_init(&state->arc4); + ARC4_setup(&state->arc4, sha1_digest, state->keylen); + ARC4_crypt(&state->arc4, state->session_key, state->keylen); + ARC4_free(&state->arc4); } if (state->keylen == 8) { /* See RFC 3078 */ @@ -89,8 +87,8 @@ static void mppe_rekey(ppp_mppe_state * state, int initial_key) 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); + ARC4_init(&state->arc4); + ARC4_setup(&state->arc4, state->session_key, state->keylen); } /* @@ -98,7 +96,7 @@ static void mppe_rekey(ppp_mppe_state * state, int initial_key) * 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); + PPP_UNUSED_ARG(pcb); MEMCPY(state->master_key, key, MPPE_MAX_KEY_LEN); } @@ -180,7 +178,7 @@ mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options) */ void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state) { - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); state->bits |= MPPE_BIT_FLUSHED; } @@ -196,12 +194,13 @@ mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t proto u8_t *pl; err_t err; - LWIP_UNUSED_ARG(pcb); + PPP_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_RAM); + np = ppp_memory_buffer_allocate(pcb->netif->memory_manager, MPPE_OVHD + sizeof(protocol) + (*pb)->tot_len, PPP_BUF_HEAP); + //np = pbuf_alloc(PBUF_RAW, MPPE_OVHD + sizeof(protocol) + (*pb)->tot_len, PBUF_RAM); if (!np) { return ERR_MEM; } @@ -210,7 +209,8 @@ mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t proto pbuf_remove_header(np, MPPE_OVHD + sizeof(protocol)); if ((err = pbuf_copy(np, *pb)) != ERR_OK) { - pbuf_free(np); + ppp_memory_buffer_free(np); + //pbuf_free(np); return err; } @@ -250,7 +250,7 @@ mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t proto /* Encrypt packet */ for (n = np; n != NULL; n = n->next) { - lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len); + ARC4_crypt(&state->arc4, (u8_t*)n->payload, n->len); if (n->tot_len == n->len) { break; } @@ -267,8 +267,8 @@ mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t proto */ void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state) { - LWIP_UNUSED_ARG(pcb); - LWIP_UNUSED_ARG(state); + PPP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(state); return; } @@ -386,7 +386,7 @@ mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb) /* Decrypt the packet. */ for (n = n0; n != NULL; n = n->next) { - lwip_arc4_crypt(&state->arc4, (u8_t*)n->payload, n->len); + ARC4_crypt(&state->arc4, (u8_t*)n->payload, n->len); if (n->tot_len == n->len) { break; } diff --git a/features/netsocket/ppp/multilink.c b/features/netsocket/ppp/source/multilink.c similarity index 98% rename from features/netsocket/ppp/multilink.c rename to features/netsocket/ppp/source/multilink.c index eb0087105f..0c3a322bd9 100644 --- a/features/netsocket/ppp/multilink.c +++ b/features/netsocket/ppp/source/multilink.c @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && defined(HAVE_MULTILINK) /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && defined(HAVE_MULTILINK) /* don't build if not configured for use in ppp_opts.h */ /* Multilink support * @@ -195,7 +195,7 @@ mp_join_bundle() * For demand mode, we only need to configure the bundle * and attach the link. */ - mtu = LWIP_MIN(ho->mrru, ao->mru); + mtu = PPP_MIN(ho->mrru, ao->mru); if (demand) { cfg_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf); netif_set_mtu(pcb, mtu); @@ -469,7 +469,7 @@ get_default_epdisc(ep) if (hp != NULL) { addr = *(u32_t *)hp->h_addr; if (!bad_ip_adrs(addr)) { - addr = lwip_ntohl(addr); + addr = ppp_ntohl(addr); if (!LOCAL_IP_ADDR(addr)) { ep->class = EPD_IP; set_ip_epdisc(ep, addr); @@ -504,7 +504,7 @@ epdisc_to_str(ep) u32_t addr; GETLONG(addr, p); - slprintf(str, sizeof(str), "IP:%I", lwip_htonl(addr)); + slprintf(str, sizeof(str), "IP:%I", ppp_htonl(addr)); return str; } diff --git a/features/netsocket/ppp/ppp.c b/features/netsocket/ppp/source/ppp.c similarity index 90% rename from features/netsocket/ppp/ppp.c rename to features/netsocket/ppp/source/ppp.c index 2f1be85631..208cc9a63e 100644 --- a/features/netsocket/ppp/ppp.c +++ b/features/netsocket/ppp/source/ppp.c @@ -86,19 +86,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ - -#include "lwip/pbuf.h" -#include "lwip/stats.h" -#include "lwip/sys.h" -#include "lwip/tcpip.h" -#include "lwip/api.h" -#include "lwip/snmp.h" -#include "lwip/ip4.h" /* for ip4_input() */ -#if PPP_IPV6_SUPPORT -#include "lwip/ip6.h" /* for ip6_input() */ -#endif /* PPP_IPV6_SUPPORT */ -#include "lwip/dns.h" +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include "ppp_impl.h" #include "pppos.h" @@ -141,18 +129,18 @@ /* Memory pools */ #if PPPOS_SUPPORT -LWIP_MEMPOOL_PROTOTYPE(PPPOS_PCB); +PPP_MEMPOOL_PROTOTYPE(PPPOS_PCB); #endif #if PPPOE_SUPPORT -LWIP_MEMPOOL_PROTOTYPE(PPPOE_IF); +PPP_MEMPOOL_PROTOTYPE(PPPOE_IF); #endif #if PPPOL2TP_SUPPORT -LWIP_MEMPOOL_PROTOTYPE(PPPOL2TP_PCB); +PPP_MEMPOOL_PROTOTYPE(PPPOL2TP_PCB); #endif -#if LWIP_PPP_API && LWIP_MPU_COMPATIBLE -LWIP_MEMPOOL_PROTOTYPE(PPPAPI_MSG); +#if PPP_API && PPP_MPU_COMPATIBLE +PPP_MEMPOOL_PROTOTYPE(PPPAPI_MSG); #endif -LWIP_MEMPOOL_DECLARE(PPP_PCB, MEMP_NUM_PPP_PCB, sizeof(ppp_pcb), "PPP_PCB") +PPP_MEMPOOL_DECLARE(PPP_PCB, MEMP_NUM_PPP_PCB, sizeof(ppp_pcb), "PPP_PCB") /* FIXME: add stats per PPP session */ #if PPP_STATS_SUPPORT @@ -216,7 +204,6 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc /***********************************/ #if PPP_AUTH_SUPPORT void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd) { - LWIP_ASSERT_CORE_LOCKED(); #if PAP_SUPPORT pcb->settings.refuse_pap = !(authtype & PPPAUTHTYPE_PAP); #endif /* PAP_SUPPORT */ @@ -269,7 +256,6 @@ void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_p * established before calling this. */ err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff) { - LWIP_ASSERT_CORE_LOCKED(); if (pcb->phase != PPP_PHASE_DEAD) { return ERR_ALREADY; } @@ -298,7 +284,6 @@ err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff) { * established before calling this. */ err_t ppp_listen(ppp_pcb *pcb) { - LWIP_ASSERT_CORE_LOCKED(); if (pcb->phase != PPP_PHASE_DEAD) { return ERR_ALREADY; } @@ -330,8 +315,6 @@ err_t ppp_listen(ppp_pcb *pcb) { err_t ppp_close(ppp_pcb *pcb, u8_t nocarrier) { - LWIP_ASSERT_CORE_LOCKED(); - pcb->err_code = PPPERR_USER; /* holdoff phase, cancel the reconnection */ @@ -392,18 +375,17 @@ ppp_close(ppp_pcb *pcb, u8_t nocarrier) */ err_t ppp_free(ppp_pcb *pcb) { err_t err; - LWIP_ASSERT_CORE_LOCKED(); if (pcb->phase != PPP_PHASE_DEAD) { return ERR_CONN; } PPPDEBUG(LOG_DEBUG, ("ppp_free[%d]\n", pcb->netif->num)); - netif_remove(pcb->netif); + ppp_netif_remove(pcb->netif); err = pcb->link_cb->free(pcb, pcb->link_ctx_cb); - LWIP_MEMPOOL_FREE(PPP_PCB, pcb); + MEMPOOL_FREE(PPP_PCB, pcb); return err; } @@ -412,7 +394,6 @@ err_t ppp_free(ppp_pcb *pcb) { err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg) { - LWIP_ASSERT_CORE_LOCKED(); if (pcb == NULL) { return ERR_VAL; } @@ -455,7 +436,7 @@ fail: static void ppp_do_connect(void *arg) { ppp_pcb *pcb = (ppp_pcb*)arg; - LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF); + PPP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF); new_phase(pcb, PPP_PHASE_INITIALIZE); pcb->link_cb->connect(pcb, pcb->link_ctx_cb); @@ -465,19 +446,16 @@ static void ppp_do_connect(void *arg) { * ppp_netif_init_cb - netif init callback */ static err_t ppp_netif_init_cb(struct netif *netif) { - netif->name[0] = 'p'; - netif->name[1] = 'p'; #if PPP_IPV4_SUPPORT netif->output = ppp_netif_output_ip4; #endif /* PPP_IPV4_SUPPORT */ #if PPP_IPV6_SUPPORT netif->output_ip6 = ppp_netif_output_ip6; #endif /* PPP_IPV6_SUPPORT */ - netif->flags = NETIF_FLAG_UP; -#if LWIP_NETIF_HOSTNAME +#if PPP_NETIF_HOSTNAME /* @todo: Initialize interface hostname */ - /* netif_set_hostname(netif, "lwip"); */ -#endif /* LWIP_NETIF_HOSTNAME */ + /* netif_set_hostname(netif, "ppp"); */ +#endif /* PPP_NETIF_HOSTNAME */ return ERR_OK; } @@ -486,7 +464,7 @@ static err_t ppp_netif_init_cb(struct netif *netif) { * Send an IPv4 packet on the given connection. */ static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr) { - LWIP_UNUSED_ARG(ipaddr); + PPP_UNUSED_ARG(ipaddr); return ppp_netif_output(netif, pb, PPP_IP); } #endif /* PPP_IPV4_SUPPORT */ @@ -496,7 +474,7 @@ static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip * Send an IPv6 packet on the given connection. */ static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr) { - LWIP_UNUSED_ARG(ipaddr); + PPP_UNUSED_ARG(ipaddr); return ppp_netif_output(netif, pb, PPP_IPV6); } #endif /* PPP_IPV6_SUPPORT */ @@ -574,7 +552,8 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc } /* if VJ compressor returned a new allocated pbuf, free it */ if (fpb) { - pbuf_free(fpb); + ppp_memory_buffer_free(fpb); + //pbuf_free(fpb); } /* mppe_compress() returns a new allocated pbuf, indicate we should free * our duplicated pbuf later */ @@ -598,7 +577,8 @@ err_rte_drop: MIB2_STATS_NETIF_INC(netif, ifoutdiscards); err: if (fpb) { - pbuf_free(fpb); + ppp_memory_buffer_free(fpb); + //pbuf_free(fpb); } return err; } @@ -611,19 +591,19 @@ err: int ppp_init(void) { #if PPPOS_SUPPORT - LWIP_MEMPOOL_INIT(PPPOS_PCB); + PPP_MEMPOOL_INIT(PPPOS_PCB); #endif #if PPPOE_SUPPORT - LWIP_MEMPOOL_INIT(PPPOE_IF); + PPP_MEMPOOL_INIT(PPPOE_IF); #endif #if PPPOL2TP_SUPPORT - LWIP_MEMPOOL_INIT(PPPOL2TP_PCB); + PPP_MEMPOOL_INIT(PPPOL2TP_PCB); #endif -#if LWIP_PPP_API && LWIP_MPU_COMPATIBLE - LWIP_MEMPOOL_INIT(PPPAPI_MSG); +#if PPP_API && PPP_MPU_COMPATIBLE + PPP_MEMPOOL_INIT(PPPAPI_MSG); #endif - LWIP_MEMPOOL_INIT(PPP_PCB); + PPP_MEMPOOL_INIT(PPP_PCB); /* * Initialize magic number generator now so that protocols may @@ -654,7 +634,7 @@ ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, vo return NULL; } - pcb = (ppp_pcb*)LWIP_MEMPOOL_ALLOC(PPP_PCB); + pcb = (ppp_pcb*)MEMPOOL_ALLOC(PPP_PCB); if (pcb == NULL) { return NULL; } @@ -698,12 +678,8 @@ ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, vo pcb->netif = pppif; MIB2_INIT_NETIF(pppif, snmp_ifType_ppp, 0); - if (!netif_add(pcb->netif, -#if LWIP_IPV4 - IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4, -#endif /* LWIP_IPV4 */ - (void *)pcb, ppp_netif_init_cb, NULL)) { - LWIP_MEMPOOL_FREE(PPP_PCB, pcb); + if (!ppp_netif_add(pcb->netif, (void *)pcb, ppp_netif_init_cb)) { + MEMPOOL_FREE(PPP_PCB, pcb); PPPDEBUG(LOG_ERR, ("ppp_new: netif_add failed\n")); return NULL; } @@ -770,8 +746,10 @@ void ppp_link_end(ppp_pcb *pcb) { * Pass the processed input packet to the appropriate handler. * This function and all handlers run in the context of the tcpip_thread */ +//void ppp_input(ppp_pcb *pcb, void *pb) void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { u16_t protocol; + u8_t *payload; #if PPP_DEBUG && PPP_PROTOCOLNAME const char *pname; #endif /* PPP_DEBUG && PPP_PROTOCOLNAME */ @@ -782,17 +760,19 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { PPPDEBUG(LOG_ERR, ("ppp_input[%d]: packet too short\n", pcb->netif->num)); goto drop; } - protocol = (((u8_t *)pb->payload)[0] << 8) | ((u8_t*)pb->payload)[1]; + + payload = (u8_t *)pb->payload; + protocol = (((u8_t *)payload)[0] << 8) | ((u8_t*)payload)[1]; #if PRINTPKT_SUPPORT - ppp_dump_packet(pcb, "rcvd", (unsigned char *)pb->payload, pb->len); + ppp_dump_packet(pcb, "rcvd", (unsigned char *)payload, mem_mngr->get_len(pb)); #endif /* PRINTPKT_SUPPORT */ pbuf_remove_header(pb, sizeof(protocol)); LINK_STATS_INC(link.recv); MIB2_STATS_NETIF_INC(pcb->netif, ifinucastpkts); - MIB2_STATS_NETIF_ADD(pcb->netif, ifinoctets, pb->tot_len); + MIB2_STATS_NETIF_ADD(pcb->netif, ifinoctets, pb->len); /* * Toss all non-LCP packets unless LCP is OPEN. @@ -877,14 +857,14 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { #if PPP_IPV4_SUPPORT case PPP_IP: /* Internet Protocol */ PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); - ip4_input(pb, pcb->netif); + ppp_ip_input(pb, pcb->netif); return; #endif /* PPP_IPV4_SUPPORT */ #if PPP_IPV6_SUPPORT case PPP_IPV6: /* Internet Protocol Version 6 */ PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip6 in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); - ip6_input(pb, pcb->netif); + ppp_ip_input(pb, pcb->netif); return; #endif /* PPP_IPV6_SUPPORT */ @@ -896,7 +876,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { */ PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_comp in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); if (pcb->vj_enabled && vj_uncompress_tcp(&pb, &pcb->vj_comp) >= 0) { - ip4_input(pb, pcb->netif); + ppp_ip4_input(pb, pcb->netif); return; } /* Something's wrong so drop it. */ @@ -910,7 +890,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { */ PPPDEBUG(LOG_INFO, ("ppp_input[%d]: vj_un in pbuf len=%d\n", pcb->netif->num, pb->tot_len)); if (pcb->vj_enabled && vj_uncompress_uncomp(pb, &pcb->vj_comp) >= 0) { - ip4_input(pb, pcb->netif); + ppp_ip4_input(pb, pcb->netif); return; } /* Something's wrong so drop it. */ @@ -927,8 +907,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { */ for (i = 0; (protp = protocols[i]) != NULL; ++i) { if (protp->protocol == protocol) { - pb = pbuf_coalesce(pb, PBUF_RAW); - (*protp->input)(pcb, (u8_t*)pb->payload, pb->len); + (*protp->input)(pcb, (u8_t *)pb->payload, (u32_t) pb->len); goto out; } #if 0 /* UNUSED @@ -975,14 +954,15 @@ drop: MIB2_STATS_NETIF_INC(pcb->netif, ifindiscards); out: - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); } /* * Write a pbuf to a ppp link, only used from PPP functions * to send PPP packets. * - * IPv4 and IPv6 packets from lwIP are sent, respectively, + * IPv4 and IPv6 packets from stack are sent, respectively, * with ppp_netif_output_ip4() and ppp_netif_output_ip6() * functions (which are callbacks of the netif PPP interface). */ @@ -1023,7 +1003,7 @@ void new_phase(ppp_pcb *pcb, int p) { * the ppp interface. */ int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp) { - LWIP_UNUSED_ARG(mtu); + PPP_UNUSED_ARG(mtu); /* pcb->mtu = mtu; -- set correctly with netif_set_mtu */ if (pcb->link_cb->send_config) { @@ -1039,7 +1019,7 @@ int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp) { * the ppp interface. */ int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp) { - LWIP_UNUSED_ARG(mru); + PPP_UNUSED_ARG(mru); if (pcb->link_cb->recv_config) { pcb->link_cb->recv_config(pcb, pcb->link_ctx_cb, accm, pcomp, accomp); @@ -1054,12 +1034,9 @@ int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp) { * sifaddr - Config the interface IP addresses and netmask. */ int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask) { - ip4_addr_t ip, nm, gw; - - ip4_addr_set_u32(&ip, our_adr); - ip4_addr_set_u32(&nm, netmask); - ip4_addr_set_u32(&gw, his_adr); - netif_set_addr(pcb->netif, &ip, &nm, &gw); + ip4_addr_set_u32(&pcb->netif->ipv4_addr, our_adr); + ip4_addr_set_u32(&pcb->netif->ipv4_netmask, netmask); + ip4_addr_set_u32(&pcb->netif->ipv4_gateway, his_adr); return 1; } @@ -1069,10 +1046,11 @@ int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask) { * through the interface if possible. */ int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr) { - LWIP_UNUSED_ARG(our_adr); - LWIP_UNUSED_ARG(his_adr); - - netif_set_addr(pcb->netif, IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4); + PPP_UNUSED_ARG(our_adr); + PPP_UNUSED_ARG(his_adr); + pcb->netif->ipv4_addr.version = NSAPI_UNSPEC; + pcb->netif->ipv4_netmask.version = NSAPI_UNSPEC; + pcb->netif->ipv4_gateway.version = NSAPI_UNSPEC; return 1; } @@ -1083,8 +1061,8 @@ int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr) { */ int sifproxyarp(ppp_pcb *pcb, u32_t his_adr) { - LWIP_UNUSED_ARG(pcb); - LWIP_UNUSED_ARG(his_adr); + PPP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(his_adr); return 0; } @@ -1094,24 +1072,19 @@ int sifproxyarp(ppp_pcb *pcb, u32_t his_adr) { */ int cifproxyarp(ppp_pcb *pcb, u32_t his_adr) { - LWIP_UNUSED_ARG(pcb); - LWIP_UNUSED_ARG(his_adr); + PPP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(his_adr); return 0; } #endif /* UNUSED - PROXY ARP */ -#if LWIP_DNS +#if PPP_DNS /* * sdns - Config the DNS servers */ int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) { - ip_addr_t ns; - LWIP_UNUSED_ARG(pcb); - - ip_addr_set_ip4_u32_val(ns, ns1); - dns_setserver(0, &ns, NULL); - ip_addr_set_ip4_u32_val(ns, ns2); - dns_setserver(1, &ns, NULL); + ip_addr_set_ip4_u32_val(pcb->netif->ipv4_dns_server[0], ns1); + ip_addr_set_ip4_u32_val(pcb->netif->ipv4_dns_server[1], ns2); return 1; } @@ -1120,23 +1093,16 @@ int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) { * cdns - Clear the DNS servers */ int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) { - const ip_addr_t *nsa; - ip_addr_t nsb; - LWIP_UNUSED_ARG(pcb); - nsa = dns_getserver(0, NULL); - ip_addr_set_ip4_u32_val(nsb, ns1); - if (ip_addr_cmp(nsa, &nsb)) { - dns_setserver(0, IP_ADDR_ANY, NULL); - } - nsa = dns_getserver(1, NULL); - ip_addr_set_ip4_u32_val(nsb, ns2); - if (ip_addr_cmp(nsa, &nsb)) { - dns_setserver(1, IP_ADDR_ANY, NULL); - } + PPP_UNUSED_ARG(ns1); + PPP_UNUSED_ARG(ns2); + + pcb->netif->ipv4_dns_server[0].version = NSAPI_UNSPEC; + pcb->netif->ipv4_dns_server[1].version = NSAPI_UNSPEC; + return 1; } -#endif /* LWIP_DNS */ +#endif /* PPP_DNS */ #if VJ_SUPPORT /******************************************************************** @@ -1158,8 +1124,9 @@ int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid) { */ int sifup(ppp_pcb *pcb) { pcb->if4_up = 1; + pcb->netif->ipv4_up = 1; pcb->err_code = PPPERR_NONE; - netif_set_link_up(pcb->netif); + ppp_set_link_up(pcb->netif); PPPDEBUG(LOG_DEBUG, ("sifup[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); @@ -1174,6 +1141,7 @@ int sifup(ppp_pcb *pcb) { int sifdown(ppp_pcb *pcb) { pcb->if4_up = 0; + pcb->netif->ipv4_up = 0; if (1 #if PPP_IPV6_SUPPORT @@ -1182,7 +1150,7 @@ int sifdown(ppp_pcb *pcb) { #endif /* PPP_IPV6_SUPPORT */ ) { /* make sure the netif link callback is called */ - netif_set_link_down(pcb->netif); + ppp_set_link_down(pcb->netif); } PPPDEBUG(LOG_DEBUG, ("sifdown[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); return 1; @@ -1201,7 +1169,7 @@ u32_t get_mask(u32_t addr) { #if 0 u32_t mask, nmask; - addr = lwip_htonl(addr); + addr = ppp_htonl(addr); if (IP_CLASSA(addr)) { /* determine network mask for address class */ nmask = IP_CLASSA_NET; } else if (IP_CLASSB(addr)) { @@ -1211,7 +1179,7 @@ u32_t get_mask(u32_t addr) { } /* class D nets are disallowed by bad_ip_adrs */ - mask = PP_HTONL(0xffffff00UL) | lwip_htonl(nmask); + mask = PP_HTONL(0xffffff00UL) | ppp_htonl(nmask); /* XXX * Scan through the system's network interfaces. @@ -1220,30 +1188,32 @@ u32_t get_mask(u32_t addr) { /* return mask; */ return mask; #endif /* 0 */ - LWIP_UNUSED_ARG(addr); - return IPADDR_BROADCAST; + PPP_UNUSED_ARG(addr); + + /** IPv4 255.255.255.255 */ + static const nsapi_addr_t ppp_addr_broadcast = { + .version = NSAPI_IPv4, + .bytes = {0xff, 0xff, 0xff, 0xff} + }; + + return ppp_addr_broadcast.bytes[0]; } #endif /* PPP_IPV4_SUPPORT */ #if PPP_IPV6_SUPPORT -#define IN6_LLADDR_FROM_EUI64(ip6, eui64) do { \ - ip6.addr[0] = PP_HTONL(0xfe800000); \ - ip6.addr[1] = 0; \ - eui64_copy(eui64, ip6.addr[2]); \ - } while (0) /******************************************************************** * * sif6addr - Config the interface with an IPv6 link-local address */ int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) { - ip6_addr_t ip6; - LWIP_UNUSED_ARG(his_eui64); + PPP_UNUSED_ARG(his_eui64); - IN6_LLADDR_FROM_EUI64(ip6, our_eui64); - netif_ip6_addr_set(pcb->netif, 0, &ip6); - netif_ip6_addr_set_state(pcb->netif, 0, IP6_ADDR_PREFERRED); - /* FIXME: should we add an IPv6 static neighbor using his_eui64 ? */ + pcb->netif->ipv6_addr.version = NSAPI_IPv6; + memset(pcb->netif->ipv6_addr.bytes, 0, NSAPI_IP_BYTES); + pcb->netif->ipv6_addr.bytes[0] = 0xfe; + pcb->netif->ipv6_addr.bytes[1] = 0x80; + memcpy(&pcb->netif->ipv6_addr.bytes[8], &our_eui64, 8); return 1; } @@ -1252,11 +1222,11 @@ int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) { * cif6addr - Remove IPv6 address from interface */ int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) { - LWIP_UNUSED_ARG(our_eui64); - LWIP_UNUSED_ARG(his_eui64); + PPP_UNUSED_ARG(our_eui64); + PPP_UNUSED_ARG(his_eui64); - netif_ip6_addr_set_state(pcb->netif, 0, IP6_ADDR_INVALID); - netif_ip6_addr_set(pcb->netif, 0, IP6_ADDR_ANY6); + pcb->netif->ipv6_addr.version = NSAPI_UNSPEC; + memset(pcb->netif->ipv6_addr.bytes, 0, NSAPI_IP_BYTES); return 1; } @@ -1266,8 +1236,9 @@ int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64) { int sif6up(ppp_pcb *pcb) { pcb->if6_up = 1; + pcb->netif->ipv6_up = 1; pcb->err_code = PPPERR_NONE; - netif_set_link_up(pcb->netif); + ppp_set_link_up(pcb->netif); PPPDEBUG(LOG_DEBUG, ("sif6up[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); @@ -1282,6 +1253,7 @@ int sif6up(ppp_pcb *pcb) { int sif6down(ppp_pcb *pcb) { pcb->if6_up = 0; + pcb->netif->ipv6_up = 0; if (1 #if PPP_IPV4_SUPPORT @@ -1290,7 +1262,7 @@ int sif6down(ppp_pcb *pcb) { #endif /* PPP_IPV4_SUPPORT */ ) { /* make sure the netif link callback is called */ - netif_set_link_down(pcb->netif); + ppp_set_link_down(pcb->netif); } PPPDEBUG(LOG_DEBUG, ("sif6down[%d]: err_code=%d\n", pcb->netif->num, pcb->err_code)); return 1; @@ -1302,9 +1274,9 @@ int sif6down(ppp_pcb *pcb) { * sifnpmode - Set the mode for handling packets for a given NP. */ int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode) { - LWIP_UNUSED_ARG(pcb); - LWIP_UNUSED_ARG(proto); - LWIP_UNUSED_ARG(mode); + PPP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(proto); + PPP_UNUSED_ARG(mode); return 0; } #endif /* DEMAND_SUPPORT */ @@ -1334,10 +1306,10 @@ int netif_get_mtu(ppp_pcb *pcb) { int ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit) { - LWIP_UNUSED_ARG(pcb); - LWIP_UNUSED_ARG(opt_ptr); - LWIP_UNUSED_ARG(opt_len); - LWIP_UNUSED_ARG(for_transmit); + PPP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(opt_ptr); + PPP_UNUSED_ARG(opt_len); + PPP_UNUSED_ARG(for_transmit); return -1; } #endif /* unused */ @@ -1348,8 +1320,8 @@ ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit) void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method) { - LWIP_UNUSED_ARG(isopen); - LWIP_UNUSED_ARG(isup); + PPP_UNUSED_ARG(isopen); + PPP_UNUSED_ARG(isup); pcb->ccp_receive_method = receive_method; pcb->ccp_transmit_method = transmit_method; PPPDEBUG(LOG_DEBUG, ("ccp_set[%d]: is_open=%d, is_up=%d, receive_method=%u, transmit_method=%u\n", @@ -1393,7 +1365,7 @@ ccp_reset_decomp(ppp_pcb *pcb) int ccp_fatal_error(ppp_pcb *pcb) { - LWIP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(pcb); return 1; } #endif /* unused */ @@ -1406,8 +1378,8 @@ ccp_fatal_error(ppp_pcb *pcb) */ int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip) { /* FIXME: add idle time support and make it optional */ - LWIP_UNUSED_ARG(pcb); - LWIP_UNUSED_ARG(ip); + PPP_UNUSED_ARG(pcb); + PPP_UNUSED_ARG(ip); return 1; } #endif /* PPP_IDLETIMELIMIT */ @@ -1580,7 +1552,7 @@ const char * protocol_name(int proto) { /* ---- Note on PPP Stats support ---- * * The one willing link stats support should add the get_ppp_stats() - * to fetch statistics from lwIP. + * to fetch statistics from stacks. */ /* diff --git a/features/netsocket/ppp/ppp_ecp.c b/features/netsocket/ppp/source/ppp_ecp.c similarity index 99% rename from features/netsocket/ppp/ppp_ecp.c rename to features/netsocket/ppp/source/ppp_ecp.c index a777c63bed..ab4711b4fd 100644 --- a/features/netsocket/ppp/ppp_ecp.c +++ b/features/netsocket/ppp/source/ppp_ecp.c @@ -58,7 +58,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include diff --git a/features/netsocket/ppp/pppapi.c b/features/netsocket/ppp/source/pppapi.c similarity index 97% rename from features/netsocket/ppp/pppapi.c rename to features/netsocket/ppp/source/pppapi.c index 2edf8f9787..19a11bbae5 100644 --- a/features/netsocket/ppp/pppapi.c +++ b/features/netsocket/ppp/source/pppapi.c @@ -33,16 +33,15 @@ #include "ppp_opts.h" -#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */ +#if PPP_API #include "pppapi.h" -#include "lwip/priv/tcpip_priv.h" #include "pppoe.h" #include "pppol2tp.h" #include "pppos.h" -#if LWIP_MPU_COMPATIBLE -LWIP_MEMPOOL_DECLARE(PPPAPI_MSG, MEMP_NUM_PPP_API_MSG, sizeof(struct pppapi_msg), "PPPAPI_MSG") +#if PPP_MPU_COMPATIBLE +PPP_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) @@ -241,8 +240,8 @@ pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipad PPPAPI_VAR_DECLARE(msg); PPPAPI_VAR_ALLOC_RETURN_NULL(msg); #if !PPPOL2TP_AUTH_SUPPORT - LWIP_UNUSED_ARG(secret); - LWIP_UNUSED_ARG(secret_len); + PPP_UNUSED_ARG(secret); + PPP_UNUSED_ARG(secret_len); #endif /* !PPPOL2TP_AUTH_SUPPORT */ PPPAPI_VAR_REF(msg).msg.ppp = NULL; @@ -424,4 +423,4 @@ pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg) return err; } -#endif /* LWIP_PPP_API */ +#endif diff --git a/features/netsocket/ppp/pppcrypt.c b/features/netsocket/ppp/source/pppcrypt.c similarity index 100% rename from features/netsocket/ppp/pppcrypt.c rename to features/netsocket/ppp/source/pppcrypt.c diff --git a/features/netsocket/ppp/pppoe.c b/features/netsocket/ppp/source/pppoe.c similarity index 91% rename from features/netsocket/ppp/pppoe.c rename to features/netsocket/ppp/source/pppoe.c index 5a596ca3ea..8ab347cd88 100644 --- a/features/netsocket/ppp/pppoe.c +++ b/features/netsocket/ppp/source/pppoe.c @@ -69,26 +69,20 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPPOE_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #if 0 /* UNUSED */ #include #include #endif /* UNUSED */ -#include "lwip/timeouts.h" -#include "lwip/memp.h" -#include "lwip/stats.h" -#include "lwip/snmp.h" - -#include "netif/ethernet.h" #include "ppp_impl.h" #include "lcp.h" #include "ipcp.h" #include "pppoe.h" /* Memory pool */ -LWIP_MEMPOOL_DECLARE(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF") +PPP_MEMPOOL_DECLARE(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF") /* Add a 16 bit unsigned value to a buffer pointed to by PTR */ #define PPPOE_ADD_16(PTR, VAL) \ @@ -108,7 +102,7 @@ LWIP_MEMPOOL_DECLARE(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_so #define PPPOE_DISC_MAXPADR 2 /* retry PADR twice */ #ifdef PPPOE_SERVER -#error "PPPOE_SERVER is not yet supported under lwIP!" +#error "PPPOE_SERVER is not yet supported" /* from if_spppsubr.c */ #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */ #endif @@ -175,18 +169,17 @@ ppp_pcb *pppoe_create(struct netif *pppif, { ppp_pcb *ppp; struct pppoe_softc *sc; - LWIP_UNUSED_ARG(service_name); - LWIP_UNUSED_ARG(concentrator_name); - LWIP_ASSERT_CORE_LOCKED(); + PPP_UNUSED_ARG(service_name); + PPP_UNUSED_ARG(concentrator_name); - sc = (struct pppoe_softc *)LWIP_MEMPOOL_ALLOC(PPPOE_IF); + sc = (struct pppoe_softc *)MEMPOOL_ALLOC(PPPOE_IF); if (sc == NULL) { return NULL; } ppp = ppp_new(pppif, &pppoe_callbacks, sc, link_status_cb, ctx_cb); if (ppp == NULL) { - LWIP_MEMPOOL_FREE(PPPOE_IF, sc); + MEMPOOL_FREE(PPPOE_IF, sc); return NULL; } @@ -207,18 +200,20 @@ static err_t pppoe_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) { #if MIB2_STATS u16_t tot_len; #else /* MIB2_STATS */ - LWIP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(ppp); #endif /* MIB2_STATS */ /* skip address & flags */ pbuf_remove_header(p, 2); - ph = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN), PBUF_RAM); + ph = ppp_memory_buffer_allocate(ppp->netif->memory_manager, (u16_t)(PPPOE_HEADERLEN), PPP_BUF_HEAP); + //ph = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN), PBUF_RAM); if(!ph) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return ERR_MEM; } @@ -250,11 +245,12 @@ static err_t pppoe_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_short #if MIB2_STATS u16_t tot_len; #else /* MIB2_STATS */ - LWIP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(ppp); #endif /* MIB2_STATS */ /* @todo: try to use pbuf_header() here! */ - pb = pbuf_alloc(PBUF_LINK, PPPOE_HEADERLEN + sizeof(protocol), PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, PPPOE_HEADERLEN + sizeof(protocol), PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_LINK, PPPOE_HEADERLEN + sizeof(protocol), PBUF_RAM); if(!pb) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); @@ -289,7 +285,7 @@ pppoe_destroy(ppp_pcb *ppp, void *ctx) { struct pppoe_softc *sc = (struct pppoe_softc *)ctx; struct pppoe_softc **copp, *freep; - LWIP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(ppp); sys_untimeout(pppoe_timeout, sc); @@ -309,7 +305,7 @@ pppoe_destroy(ppp_pcb *ppp, void *ctx) mem_free(sc->sc_service_name); } #endif /* PPPOE_TODO */ - LWIP_MEMPOOL_FREE(PPPOE_IF, sc); + MEMPOOL_FREE(PPPOE_IF, sc); return ERR_OK; } @@ -391,7 +387,8 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb) /* don't do anything if there is not a single PPPoE instance */ if (pppoe_softc_list == NULL) { - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return; } @@ -417,8 +414,8 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb) PPPDEBUG(LOG_DEBUG, ("pppoe: unknown version/type packet: 0x%x\n", ph->vertype)); goto done; } - session = lwip_ntohs(ph->session); - plen = lwip_ntohs(ph->plen); + session = ppp_ntohs(ph->session); + plen = ppp_ntohs(ph->plen); if (plen > (pb->len - off)) { PPPDEBUG(LOG_DEBUG, ("pppoe: packet content does not fit: data available = %d, packet size = %u\n", @@ -437,8 +434,8 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb) sc = NULL; while (off + sizeof(pt) <= pb->len) { MEMCPY(&pt, (u8_t*)pb->payload + off, sizeof(pt)); - tag = lwip_ntohs(pt.tag); - len = lwip_ntohs(pt.len); + tag = ppp_ntohs(pt.tag); + len = ppp_ntohs(pt.len); if (off + sizeof(pt) + len > pb->len) { PPPDEBUG(LOG_DEBUG, ("pppoe: tag 0x%x len 0x%x is too long\n", tag, len)); goto done; @@ -487,7 +484,7 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb) #if PPP_DEBUG if (err_msg != NULL) { char error_tmp[PPPOE_ERRORSTRING_LEN]; - u16_t error_len = LWIP_MIN(len, sizeof(error_tmp)-1); + u16_t error_len = PPP_MIN(len, sizeof(error_tmp)-1); strncpy(error_tmp, (char*)pb->payload + off + sizeof(pt), error_len); error_tmp[error_len] = '\0'; if (sc) { @@ -605,7 +602,7 @@ breakbreak:; sc->sc_state = PPPOE_STATE_PADR_SENT; if ((err = pppoe_send_padr(sc)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc); break; @@ -644,7 +641,8 @@ breakbreak:; } done: - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return; } @@ -682,7 +680,7 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb) goto drop; } - session = lwip_ntohs(ph->session); + session = ppp_ntohs(ph->session); sc = pppoe_find_softc_by_session(session, netif); if (sc == NULL) { #ifdef PPPOE_TERM_UNKNOWN_SESSIONS @@ -692,7 +690,7 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb) goto drop; } - plen = lwip_ntohs(ph->plen); + plen = ppp_ntohs(ph->plen); if (pbuf_remove_header(pb, PPPOE_HEADERLEN) != 0) { /* bail out */ @@ -714,7 +712,8 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb) return; drop: - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); } static err_t @@ -729,12 +728,13 @@ pppoe_output(struct pppoe_softc *sc, struct pbuf *pb) /* bail out */ PPPDEBUG(LOG_ERR, ("pppoe: %c%c%"U16_F": pppoe_output: could not allocate room for Ethernet header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); LINK_STATS_INC(link.lenerr); - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return ERR_BUF; } ethhdr = (struct eth_hdr *)pb->payload; etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC; - ethhdr->type = lwip_htons(etype); + ethhdr->type = ppp_htons(etype); MEMCPY(ðhdr->dest.addr, &sc->sc_dest.addr, sizeof(ethhdr->dest.addr)); MEMCPY(ðhdr->src.addr, &sc->sc_ethif->hwaddr, sizeof(ethhdr->src.addr)); @@ -746,7 +746,8 @@ pppoe_output(struct pppoe_softc *sc, struct pbuf *pb) res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb); - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return res; } @@ -773,15 +774,16 @@ pppoe_send_padi(struct pppoe_softc *sc) len += 2 + 2 + l2; } #endif /* PPPOE_TODO */ - LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff", + PPP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff", sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff); /* allocate a buffer */ - pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, (u16_t)(PPPOE_HEADERLEN + len), PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ @@ -849,11 +851,11 @@ pppoe_timeout(void *arg) } } /* initialize for quick retry mode */ - retry_wait = LWIP_MIN(PPPOE_DISC_TIMEOUT * sc->sc_padi_retried, PPPOE_SLOW_RETRY); + retry_wait = PPP_MIN(PPPOE_DISC_TIMEOUT * sc->sc_padi_retried, PPPOE_SLOW_RETRY); if ((err = pppoe_send_padi(sc)) != 0) { sc->sc_padi_retried--; PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to transmit PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_timeout(retry_wait, pppoe_timeout, sc); break; @@ -866,7 +868,7 @@ pppoe_timeout(void *arg) sc->sc_padr_retried = 0; if ((err = pppoe_send_padi(sc)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc); return; @@ -874,7 +876,7 @@ pppoe_timeout(void *arg) if ((err = pppoe_send_padr(sc)) != 0) { sc->sc_padr_retried--; PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc); break; @@ -996,13 +998,14 @@ pppoe_send_padr(struct pppoe_softc *sc) if (sc->sc_ac_cookie_len > 0) { len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */ } - LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff", + PPP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff", sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff); - pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, (u16_t)(PPPOE_HEADERLEN + len), PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len); PPPOE_ADD_16(p, PPPOE_TAG_SNAME); @@ -1038,16 +1041,18 @@ pppoe_send_padt(struct netif *outgoing_if, u_int session, const u8_t *dest) err_t res; u8_t *p; - pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN), PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, (u16_t)(PPPOE_HEADERLEN), PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN), PBUF_RAM); if (!pb) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); if (pbuf_add_header(pb, sizeof(struct eth_hdr))) { PPPDEBUG(LOG_ERR, ("pppoe: pppoe_send_padt: could not allocate room for PPPoE header\n")); LINK_STATS_INC(link.lenerr); - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return ERR_BUF; } ethhdr = (struct eth_hdr *)pb->payload; @@ -1060,7 +1065,8 @@ pppoe_send_padt(struct netif *outgoing_if, u_int session, const u8_t *dest) res = outgoing_if->linkoutput(outgoing_if, pb); - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return res; } @@ -1079,11 +1085,12 @@ pppoe_send_pado(struct pppoe_softc *sc) len += 2 + 2 + sizeof(sc); /* include hunique */ len += 2 + 2 + sc->sc_hunique_len; - pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, (u16_t)(PPPOE_HEADERLEN + len), PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len); PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE); @@ -1112,11 +1119,12 @@ pppoe_send_pads(struct pppoe_softc *sc) l1 = strlen(sc->sc_service_name); len += l1; } - pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, (u16_t)(PPPOE_HEADERLEN + len), PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len); PPPOE_ADD_16(p, PPPOE_TAG_SNAME); @@ -1147,7 +1155,8 @@ pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb) /* bail out */ PPPDEBUG(LOG_ERR, ("pppoe: %c%c%"U16_F": pppoe_xmit: could not allocate room for PPPoE header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); LINK_STATS_INC(link.lenerr); - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return ERR_BUF; } @@ -1189,7 +1198,7 @@ pppoe_ifattach_hook(void *arg, struct pbuf **mp, struct netif *ifp, int dir) static void pppoe_clear_softc(struct pppoe_softc *sc, const char *message) { - LWIP_UNUSED_ARG(message); + PPP_UNUSED_ARG(message); /* stop timer */ sys_untimeout(pppoe_timeout, sc); diff --git a/features/netsocket/ppp/pppol2tp.c b/features/netsocket/ppp/source/pppol2tp.c similarity index 91% rename from features/netsocket/ppp/pppol2tp.c rename to features/netsocket/ppp/source/pppol2tp.c index 0fd528bb77..86ac507c26 100644 --- a/features/netsocket/ppp/pppol2tp.c +++ b/features/netsocket/ppp/source/pppol2tp.c @@ -51,13 +51,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in lwipopts.h */ - -#include "lwip/err.h" -#include "lwip/memp.h" -#include "lwip/netif.h" -#include "lwip/udp.h" -#include "lwip/snmp.h" +#if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include "ppp_impl.h" #include "lcp.h" @@ -67,7 +61,7 @@ #include "magic.h" /* Memory pool */ -LWIP_MEMPOOL_DECLARE(PPPOL2TP_PCB, MEMP_NUM_PPPOL2TP_INTERFACES, sizeof(pppol2tp_pcb), "PPPOL2TP_PCB") +PPP_MEMPOOL_DECLARE(PPPOL2TP_PCB, MEMP_NUM_PPPOL2TP_INTERFACES, sizeof(pppol2tp_pcb), "PPPOL2TP_PCB") /* callbacks called from PPP core */ static err_t pppol2tp_write(ppp_pcb *ppp, void *ctx, struct pbuf *p); @@ -114,15 +108,15 @@ ppp_pcb *pppol2tp_create(struct netif *pppif, pppol2tp_pcb *l2tp; struct udp_pcb *udp; #if !PPPOL2TP_AUTH_SUPPORT - LWIP_UNUSED_ARG(secret); - LWIP_UNUSED_ARG(secret_len); + UNUSED_ARG(secret); + UNUSED_ARG(secret_len); #endif /* !PPPOL2TP_AUTH_SUPPORT */ if (ipaddr == NULL) { goto ipaddr_check_failed; } - l2tp = (pppol2tp_pcb *)LWIP_MEMPOOL_ALLOC(PPPOL2TP_PCB); + l2tp = (pppol2tp_pcb *)MEMPOOL_ALLOC(PPPOL2TP_PCB); if (l2tp == NULL) { goto memp_malloc_l2tp_failed; } @@ -155,7 +149,7 @@ ppp_pcb *pppol2tp_create(struct netif *pppif, ppp_new_failed: udp_remove(udp); udp_new_failed: - LWIP_MEMPOOL_FREE(PPPOL2TP_PCB, l2tp); + MEMPOOL_FREE(PPPOL2TP_PCB, l2tp); memp_malloc_l2tp_failed: ipaddr_check_failed: return NULL; @@ -169,15 +163,17 @@ static err_t pppol2tp_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) { #if MIB2_STATS u16_t tot_len; #else /* MIB2_STATS */ - LWIP_UNUSED_ARG(ppp); + UNUSED_ARG(ppp); #endif /* MIB2_STATS */ - ph = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(PPPOL2TP_OUTPUT_DATA_HEADER_LEN), PBUF_RAM); + ph = ppp_memory_buffer_allocate(ppp->netif->memory_manager, (u16_t)(PPPOL2TP_OUTPUT_DATA_HEADER_LEN), PPP_BUF_HEAP); + //ph = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(PPPOL2TP_OUTPUT_DATA_HEADER_LEN), PBUF_RAM); if(!ph) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return ERR_MEM; } @@ -209,11 +205,12 @@ static err_t pppol2tp_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_sh #if MIB2_STATS u16_t tot_len; #else /* MIB2_STATS */ - LWIP_UNUSED_ARG(ppp); + UNUSED_ARG(ppp); #endif /* MIB2_STATS */ /* @todo: try to use pbuf_header() here! */ - pb = pbuf_alloc(PBUF_TRANSPORT, PPPOL2TP_OUTPUT_DATA_HEADER_LEN + sizeof(protocol), PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, PPPOL2TP_OUTPUT_DATA_HEADER_LEN + sizeof(protocol), PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_TRANSPORT, PPPOL2TP_OUTPUT_DATA_HEADER_LEN + sizeof(protocol), PBUF_RAM); if(!pb) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); @@ -246,11 +243,11 @@ static err_t pppol2tp_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_sh /* Destroy a L2TP control block */ static err_t pppol2tp_destroy(ppp_pcb *ppp, void *ctx) { pppol2tp_pcb *l2tp = (pppol2tp_pcb *)ctx; - LWIP_UNUSED_ARG(ppp); + UNUSED_ARG(ppp); sys_untimeout(pppol2tp_timeout, l2tp); udp_remove(l2tp->udp); - LWIP_MEMPOOL_FREE(PPPOL2TP_PCB, l2tp); + MEMPOOL_FREE(PPPOL2TP_PCB, l2tp); return ERR_OK; } @@ -302,11 +299,11 @@ static void pppol2tp_connect(ppp_pcb *ppp, void *ctx) { /* Listen to a random source port, we need to do that instead of using udp_connect() * because the L2TP LNS might answer with its own random source port (!= 1701) */ -#if LWIP_IPV6 +#if PPP_IPV6_SUPPORT if (IP_IS_V6_VAL(l2tp->udp->local_ip)) { udp_bind(l2tp->udp, IP6_ADDR_ANY, 0); } else -#endif /* LWIP_IPV6 */ +#endif /* PPP_IPV6_SUPPORT */ udp_bind(l2tp->udp, IP_ADDR_ANY, 0); #if PPPOL2TP_AUTH_SUPPORT @@ -346,7 +343,7 @@ static void pppol2tp_input(void *arg, struct udp_pcb *pcb, struct pbuf *p, const pppol2tp_pcb *l2tp = (pppol2tp_pcb*)arg; u16_t hflags, hlen, len=0, tunnel_id=0, session_id=0, ns=0, nr=0, offset=0; u8_t *inp; - LWIP_UNUSED_ARG(pcb); + UNUSED_ARG(pcb); /* we can't unbound a UDP pcb, thus we can still receive UDP frames after the link is closed */ if (l2tp->phase < PPPOL2TP_STATE_SCCRQ_SENT) { @@ -479,7 +476,8 @@ static void pppol2tp_input(void *arg, struct udp_pcb *pcb, struct pbuf *p, const packet_too_short: PPPDEBUG(LOG_DEBUG, ("pppol2tp: packet too short: %d\n", p->len)); free_and_return: - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); } /* L2TP Control packet entry point */ @@ -488,7 +486,7 @@ static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, u16_t port, str u16_t avplen, avpflags, vendorid, attributetype, messagetype=0; err_t err; #if PPPOL2TP_AUTH_SUPPORT - lwip_md5_context md5_ctx; + MD5_context md5_ctx; u8_t md5_hash[16]; u8_t challenge_id = 0; #endif /* PPPOL2TP_AUTH_SUPPORT */ @@ -617,14 +615,14 @@ static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, u16_t port, str return; } /* Generate hash of ID, secret, challenge */ - lwip_md5_init(&md5_ctx); - lwip_md5_starts(&md5_ctx); + MD5_init(&md5_ctx); + MD5_starts(&md5_ctx); challenge_id = PPPOL2TP_MESSAGETYPE_SCCCN; - lwip_md5_update(&md5_ctx, &challenge_id, 1); - lwip_md5_update(&md5_ctx, l2tp->secret, l2tp->secret_len); - lwip_md5_update(&md5_ctx, inp, avplen); - lwip_md5_finish(&md5_ctx, l2tp->challenge_hash); - lwip_md5_free(&md5_ctx); + MD5_update(&md5_ctx, &challenge_id, 1); + MD5_update(&md5_ctx, l2tp->secret, l2tp->secret_len); + MD5_update(&md5_ctx, inp, avplen); + MD5_finish(&md5_ctx, l2tp->challenge_hash); + MD5_free(&md5_ctx); l2tp->send_challenge = 1; goto skipavp; case PPPOL2TP_AVPTYPE_CHALLENGERESPONSE: @@ -633,14 +631,14 @@ static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, u16_t port, str return; } /* Generate hash of ID, secret, challenge */ - lwip_md5_init(&md5_ctx); - lwip_md5_starts(&md5_ctx); + MD5_init(&md5_ctx); + MD5_starts(&md5_ctx); challenge_id = PPPOL2TP_MESSAGETYPE_SCCRP; - lwip_md5_update(&md5_ctx, &challenge_id, 1); - lwip_md5_update(&md5_ctx, l2tp->secret, l2tp->secret_len); - lwip_md5_update(&md5_ctx, l2tp->secret_rv, sizeof(l2tp->secret_rv)); - lwip_md5_finish(&md5_ctx, md5_hash); - lwip_md5_free(&md5_ctx); + MD5_update(&md5_ctx, &challenge_id, 1); + MD5_update(&md5_ctx, l2tp->secret, l2tp->secret_len); + MD5_update(&md5_ctx, l2tp->secret_rv, sizeof(l2tp->secret_rv)); + MD5_finish(&md5_ctx, md5_hash); + MD5_free(&md5_ctx); if ( memcmp(inp, md5_hash, sizeof(md5_hash)) ) { PPPDEBUG(LOG_DEBUG, ("pppol2tp: Received challenge response from peer and secret key do not match\n")); pppol2tp_abort_connect(l2tp); @@ -693,12 +691,12 @@ nextavp: l2tp->our_ns++; if ((err = pppol2tp_send_scccn(l2tp, l2tp->our_ns)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send SCCCN, error=%d\n", err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } l2tp->our_ns++; if ((err = pppol2tp_send_icrq(l2tp, l2tp->our_ns)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send ICRQ, error=%d\n", err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_untimeout(pppol2tp_timeout, l2tp); sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp); @@ -710,7 +708,7 @@ nextavp: l2tp->our_ns++; if ((err = pppol2tp_send_iccn(l2tp, l2tp->our_ns)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send ICCN, error=%d\n", err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_untimeout(pppol2tp_timeout, l2tp); sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp); @@ -746,12 +744,12 @@ static void pppol2tp_timeout(void *arg) { pppol2tp_abort_connect(l2tp); return; } - retry_wait = LWIP_MIN(PPPOL2TP_CONTROL_TIMEOUT * l2tp->sccrq_retried, PPPOL2TP_SLOW_RETRY); + retry_wait = PPP_MIN(PPPOL2TP_CONTROL_TIMEOUT * l2tp->sccrq_retried, PPPOL2TP_SLOW_RETRY); PPPDEBUG(LOG_DEBUG, ("pppol2tp: sccrq_retried=%d\n", l2tp->sccrq_retried)); if ((err = pppol2tp_send_sccrq(l2tp)) != 0) { l2tp->sccrq_retried--; PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send SCCRQ, error=%d\n", err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_timeout(retry_wait, pppol2tp_timeout, l2tp); break; @@ -767,7 +765,7 @@ static void pppol2tp_timeout(void *arg) { if ((err = pppol2tp_send_scccn(l2tp, l2tp->our_ns -1)) != 0) { l2tp->icrq_retried--; PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send SCCCN, error=%d\n", err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp); break; } @@ -775,7 +773,7 @@ static void pppol2tp_timeout(void *arg) { if ((err = pppol2tp_send_icrq(l2tp, l2tp->our_ns)) != 0) { l2tp->icrq_retried--; PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send ICRQ, error=%d\n", err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp); break; @@ -790,7 +788,7 @@ static void pppol2tp_timeout(void *arg) { if ((err = pppol2tp_send_iccn(l2tp, l2tp->our_ns)) != 0) { l2tp->iccn_retried--; PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send ICCN, error=%d\n", err)); - LWIP_UNUSED_ARG(err); /* if PPPDEBUG is disabled */ + UNUSED_ARG(err); /* if PPPDEBUG is disabled */ } sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp); break; @@ -822,11 +820,12 @@ static err_t pppol2tp_send_sccrq(pppol2tp_pcb *l2tp) { #endif /* PPPOL2TP_AUTH_SUPPORT */ /* allocate a buffer */ - pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, len, PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); if (pb == NULL) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ @@ -917,11 +916,12 @@ static err_t pppol2tp_send_scccn(pppol2tp_pcb *l2tp, u16_t ns) { #endif /* PPPOL2TP_AUTH_SUPPORT */ /* allocate a buffer */ - pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, len, PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); if (pb == NULL) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ @@ -964,11 +964,12 @@ static err_t pppol2tp_send_icrq(pppol2tp_pcb *l2tp, u16_t ns) { len = 12 +8 +8 +10; /* allocate a buffer */ - pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, len, PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); if (pb == NULL) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ @@ -1012,11 +1013,12 @@ static err_t pppol2tp_send_iccn(pppol2tp_pcb *l2tp, u16_t ns) { len = 12 +8 +10 +10; /* allocate a buffer */ - pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, len, PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); if (pb == NULL) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ @@ -1059,11 +1061,12 @@ static err_t pppol2tp_send_zlb(pppol2tp_pcb *l2tp, u16_t ns, u16_t nr) { len = 12; /* allocate a buffer */ - pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, len, PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); if (pb == NULL) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ @@ -1088,11 +1091,12 @@ static err_t pppol2tp_send_stopccn(pppol2tp_pcb *l2tp, u16_t ns) { len = 12 +8 +8 +8; /* allocate a buffer */ - pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); + pb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, len, PPP_BUF_HEAP); + //pb = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); if (pb == NULL) { return ERR_MEM; } - LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); + PPP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ @@ -1133,7 +1137,8 @@ static err_t pppol2tp_xmit(pppol2tp_pcb *l2tp, struct pbuf *pb) { /* bail out */ PPPDEBUG(LOG_ERR, ("pppol2tp: pppol2tp_pcb: could not allocate room for L2TP header\n")); LINK_STATS_INC(link.lenerr); - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return ERR_BUF; } @@ -1152,7 +1157,8 @@ static err_t pppol2tp_udp_send(pppol2tp_pcb *l2tp, struct pbuf *pb) { } else { err = udp_sendto(l2tp->udp, pb, &l2tp->remote_ip, l2tp->tunnel_port); } - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); return err; } diff --git a/features/netsocket/ppp/pppos.c b/features/netsocket/ppp/source/pppos.cpp similarity index 84% rename from features/netsocket/ppp/pppos.c rename to features/netsocket/ppp/source/pppos.cpp index 55d07db595..1059d1b666 100644 --- a/features/netsocket/ppp/pppos.c +++ b/features/netsocket/ppp/source/pppos.cpp @@ -32,27 +32,18 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include -#include "lwip/arch.h" -#include "lwip/err.h" -#include "lwip/pbuf.h" -#include "lwip/sys.h" -#include "lwip/memp.h" -#include "lwip/netif.h" -#include "lwip/snmp.h" -#include "lwip/priv/tcpip_priv.h" -#include "lwip/api.h" -#include "lwip/ip4.h" /* for ip4_input() */ - #include "ppp_impl.h" #include "pppos.h" #include "vj.h" +#include "NetStackMemoryManager.h" + /* Memory pool */ -LWIP_MEMPOOL_DECLARE(PPPOS_PCB, MEMP_NUM_PPPOS_INTERFACES, sizeof(pppos_pcb), "PPPOS_PCB") +PPP_MEMPOOL_DECLARE(PPPOS_PCB, MEMP_NUM_PPPOS_INTERFACES, sizeof(pppos_pcb), "PPPOS_PCB") /* callbacks called from PPP core */ static err_t pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p); @@ -155,17 +146,6 @@ ppp_get_fcs(u8_t byte) #define PPP_INITFCS 0xffff /* Initial FCS value */ #define PPP_GOODFCS 0xf0b8 /* Good final FCS value */ -#if PPP_INPROC_IRQ_SAFE -#define PPPOS_DECL_PROTECT(lev) SYS_ARCH_DECL_PROTECT(lev) -#define PPPOS_PROTECT(lev) SYS_ARCH_PROTECT(lev) -#define PPPOS_UNPROTECT(lev) SYS_ARCH_UNPROTECT(lev) -#else -#define PPPOS_DECL_PROTECT(lev) -#define PPPOS_PROTECT(lev) -#define PPPOS_UNPROTECT(lev) -#endif /* PPP_INPROC_IRQ_SAFE */ - - /* * Create a new PPP connection using the given serial I/O device. * @@ -176,16 +156,15 @@ ppp_pcb *pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb, { pppos_pcb *pppos; ppp_pcb *ppp; - LWIP_ASSERT_CORE_LOCKED(); - pppos = (pppos_pcb *)LWIP_MEMPOOL_ALLOC(PPPOS_PCB); + pppos = (pppos_pcb *)MEMPOOL_ALLOC(PPPOS_PCB); if (pppos == NULL) { return NULL; } ppp = ppp_new(pppif, &pppos_callbacks, pppos, link_status_cb, ctx_cb); if (ppp == NULL) { - LWIP_MEMPOOL_FREE(PPPOS_PCB, pppos); + MEMPOOL_FREE(PPPOS_PCB, pppos); return NULL; } @@ -205,35 +184,44 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) u16_t n; u16_t fcs_out; err_t err; - LWIP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(ppp); /* Grab an output buffer. Using PBUF_POOL here for tx is ok since the pbuf gets freed by 'pppos_output_last' before this function returns and thus cannot starve rx. */ - nb = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); - if (nb == NULL) { + u16_t pool_bufsize = ppp_memory_buffer_pool_alloc_unit_get(ppp->netif->memory_manager); + if (pool_bufsize > PBUF_POOL_BUFSIZE) { + pool_bufsize = PBUF_POOL_BUFSIZE; + } + nb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, pool_bufsize, PPP_BUF_POOL); + //nb = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); + + if (nb == NULL || nb->len != nb->tot_len) { PPPDEBUG(LOG_WARNING, ("pppos_write[%d]: alloc fail\n", ppp->netif->num)); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); - pbuf_free(p); + ppp_memory_buffer_free(p); return ERR_MEM; } + nb->len = 0; /* Set nb->tot_len to actual payload length */ - nb->tot_len = p->len; + //nb->tot_len = p->len; /* If the link has been idle, we'll send a fresh flag character to * flush any noise. */ err = ERR_OK; + if ((sys_now() - pppos->last_xmit) >= PPP_MAXIDLEFLAG) { - err = pppos_output_append(pppos, err, nb, PPP_FLAG, 0, NULL); + err = pppos_output_append(pppos, err, nb, PPP_FLAG, 0, NULL); } /* Load output buffer. */ fcs_out = PPP_INITFCS; s = (u8_t*)p->payload; n = p->len; + while (n-- > 0) { err = pppos_output_append(pppos, err, nb, *s++, 1, &fcs_out); } @@ -244,7 +232,9 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) } else { PPPDEBUG(LOG_WARNING, ("pppos_write[%d]: output failed len=%d\n", ppp->netif->num, p->len)); } - pbuf_free(p); + + ppp_memory_buffer_free(p); + //pbuf_free(p); return err; } @@ -256,13 +246,19 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u16_t protocol) struct pbuf *nb, *p; u16_t fcs_out; err_t err; - LWIP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(ppp); /* Grab an output buffer. Using PBUF_POOL here for tx is ok since the pbuf gets freed by 'pppos_output_last' before this function returns and thus cannot starve rx. */ - nb = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); - if (nb == NULL) { + u16_t pool_bufsize = ppp_memory_buffer_pool_alloc_unit_get(ppp->netif->memory_manager); + if (pool_bufsize > PBUF_POOL_BUFSIZE) { + pool_bufsize = PBUF_POOL_BUFSIZE; + } + nb = ppp_memory_buffer_allocate(ppp->netif->memory_manager, pool_bufsize, PPP_BUF_POOL); + // nb = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); + + if (nb == NULL || nb->len != nb->tot_len) { PPPDEBUG(LOG_WARNING, ("pppos_netif_output[%d]: alloc fail\n", ppp->netif->num)); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); @@ -270,8 +266,9 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u16_t protocol) return ERR_MEM; } + nb->len = 0; /* Set nb->tot_len to actual payload length */ - nb->tot_len = pb->tot_len; + //nb->tot_len = pb->tot_len; /* If the link has been idle, we'll send a fresh flag character to * flush any noise. */ @@ -290,21 +287,21 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u16_t protocol) } err = pppos_output_append(pppos, err, nb, protocol & 0xFF, 1, &fcs_out); - /* Load packet. */ - for(p = pb; p; p = p->next) { - u16_t n = p->len; - u8_t *s = (u8_t*)p->payload; + NetStackMemoryManager *mem_mngr = static_cast(ppp->netif->memory_manager); + for (p = static_cast(pb->buffer); p; p = static_cast(mem_mngr->get_next(p))) { + u16_t n = mem_mngr->get_len(p); + u8_t *s = (u8_t*) mem_mngr->get_ptr(p); - while (n-- > 0) { - err = pppos_output_append(pppos, err, nb, *s++, 1, &fcs_out); - } + while (n-- > 0) { + err = pppos_output_append(pppos, err, nb, *s++, 1, &fcs_out); + } } err = pppos_output_last(pppos, err, nb, &fcs_out); if (err == ERR_OK) { - PPPDEBUG(LOG_INFO, ("pppos_netif_output[%d]: proto=0x%"X16_F", len = %d\n", ppp->netif->num, protocol, pb->tot_len)); + PPPDEBUG(LOG_INFO, ("pppos_netif_output[%d]: proto=0x%" X16_F ", len = %d\n", ppp->netif->num, protocol, pb->tot_len)); } else { - PPPDEBUG(LOG_WARNING, ("pppos_netif_output[%d]: output failed proto=0x%"X16_F", len = %d\n", ppp->netif->num, protocol, pb->tot_len)); + PPPDEBUG(LOG_WARNING, ("pppos_netif_output[%d]: output failed proto=0x%" X16_F ", len = %d\n", ppp->netif->num, protocol, pb->tot_len)); } return err; } @@ -399,19 +396,19 @@ static err_t pppos_destroy(ppp_pcb *ppp, void *ctx) { pppos_pcb *pppos = (pppos_pcb *)ctx; - LWIP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(ppp); #if PPP_INPROC_IRQ_SAFE /* input pbuf left ? */ pppos_input_free_current_packet(pppos); #endif /* PPP_INPROC_IRQ_SAFE */ - LWIP_MEMPOOL_FREE(PPPOS_PCB, pppos); + MEMPOOL_FREE(PPPOS_PCB, pppos); return ERR_OK; } #if !NO_SYS && !PPP_INPROC_IRQ_SAFE -/** Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. +/** Pass received raw characters to PPPoS to be decoded through stacks TCPIP thread. * * This is one of the only functions that may be called outside of the TCPIP thread! * @@ -425,15 +422,18 @@ pppos_input_tcpip(ppp_pcb *ppp, u8_t *s, int l) struct pbuf *p; err_t err; - p = pbuf_alloc(PBUF_RAW, l, PBUF_POOL); + p = ppp_memory_buffer_allocate(ppp->netif->memory_manager, l, PPP_BUF_POOL); + //p = pbuf_alloc(PBUF_RAW, l, PBUF_POOL); if (!p) { return ERR_MEM; } - pbuf_take(p, s, l); + memcpy(p->payload, s, l); + //pbuf_take(p, s, l); err = tcpip_inpkt(p, ppp_netif(ppp), pppos_input_sys); if (err != ERR_OK) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); } return err; } @@ -442,12 +442,12 @@ pppos_input_tcpip(ppp_pcb *ppp, u8_t *s, int l) err_t pppos_input_sys(struct pbuf *p, struct netif *inp) { ppp_pcb *ppp = (ppp_pcb*)inp->state; struct pbuf *n; - LWIP_ASSERT_CORE_LOCKED(); for (n = p; n; n = n->next) { pppos_input(ppp, (u8_t*)n->payload, n->len); } - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return ERR_OK; } #endif /* !NO_SYS && !PPP_INPROC_IRQ_SAFE */ @@ -478,13 +478,10 @@ void pppos_input(ppp_pcb *ppp, u8_t *s, int l) { pppos_pcb *pppos = (pppos_pcb *)ppp->link_ctx_cb; - struct pbuf *next_pbuf; + //struct pbuf *next_pbuf; u8_t cur_char; u8_t escaped; PPPOS_DECL_PROTECT(lev); -#if !PPP_INPROC_IRQ_SAFE - LWIP_ASSERT_CORE_LOCKED(); -#endif PPPDEBUG(LOG_DEBUG, ("pppos_input[%d]: got %d bytes\n", ppp->netif->num, l)); while (l-- > 0) { @@ -526,7 +523,7 @@ pppos_input(ppp_pcb *ppp, u8_t *s, int l) /* If the fcs is invalid, drop the packet. */ } else if (pppos->in_fcs != PPP_GOODFCS) { PPPDEBUG(LOG_INFO, - ("pppos_input[%d]: Dropping bad fcs 0x%"X16_F" proto=0x%"X16_F"\n", + ("pppos_input[%d]: Dropping bad fcs 0x%" X16_F " proto=0x%" X16_F "\n", ppp->netif->num, pppos->in_fcs, pppos->in_protocol)); /* Note: If you get lots of these, check for UART frame errors or try different baud rate */ LINK_STATS_INC(link.chkerr); @@ -534,38 +531,43 @@ pppos_input(ppp_pcb *ppp, u8_t *s, int l) /* Otherwise it's a good packet so pass it on. */ } else { struct pbuf *inp; + /* Trim off the checksum. */ if(pppos->in_tail->len > 2) { pppos->in_tail->len -= 2; - - pppos->in_tail->tot_len = pppos->in_tail->len; if (pppos->in_tail != pppos->in_head) { - pbuf_cat(pppos->in_head, pppos->in_tail); + ppp_memory_buffer_cat(ppp->netif->memory_manager, pppos->in_head, pppos->in_tail); } } else { - pppos->in_tail->tot_len = pppos->in_tail->len; if (pppos->in_tail != pppos->in_head) { - pbuf_cat(pppos->in_head, pppos->in_tail); - } + for (struct pbuf *buf = pppos->in_head; buf != NULL; buf = buf->next) { + if (buf->next == NULL) { + uint16_t tail_len = pppos->in_tail->len; + buf->len = buf->len - 2 + tail_len; - pbuf_realloc(pppos->in_head, pppos->in_head->tot_len - 2); + ppp_memory_buffer_free(pppos->in_tail); + pppos->in_tail = NULL; + break; + } + } + } } +#if PPP_TRACE_ENABLE + ppp_trace_to_ascii_hex_dump_print(INPUT_BUFFER); +#endif /* Dispatch the packet thereby consuming it. */ inp = pppos->in_head; /* Packet consumed, release our references. */ pppos->in_head = NULL; pppos->in_tail = NULL; -#if IP_FORWARD || LWIP_IPV6_FORWARD - /* hide the room for Ethernet forwarding header */ - pbuf_remove_header(inp, PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN); -#endif /* IP_FORWARD || LWIP_IPV6_FORWARD */ #if PPP_INPROC_IRQ_SAFE - if(tcpip_try_callback(pppos_input_callback, inp) != ERR_OK) { - PPPDEBUG(LOG_ERR, ("pppos_input[%d]: tcpip_callback() failed, dropping packet\n", ppp->netif->num)); - pbuf_free(inp); - LINK_STATS_INC(link.drop); - MIB2_STATS_NETIF_INC(ppp->netif, ifindiscards); + if (ppp_call_callback(ppp->netif->service_ptr, pppos_input_callback, inp) != ERR_OK) { + PPPDEBUG(LOG_ERR, ("pppos_input[%d]: tcpip_callback() failed, dropping packet\n", ppp->netif->num)); + ppp_memory_buffer_free(inp); + //pbuf_free(inp); + LINK_STATS_INC(link.drop); + MIB2_STATS_NETIF_INC(ppp->netif, ifindiscards); } #else /* PPP_INPROC_IRQ_SAFE */ ppp_input(ppp, inp); @@ -651,19 +653,20 @@ pppos_input(ppp_pcb *ppp, u8_t *s, int l) break; case PDDATA: /* Process data byte. */ /* Make space to receive processed data. */ - if (pppos->in_tail == NULL || pppos->in_tail->len == PBUF_POOL_BUFSIZE) { + if (pppos->in_tail == NULL || pppos->in_tail->len == pppos->in_tail->tot_len) { u16_t pbuf_alloc_len; if (pppos->in_tail != NULL) { - pppos->in_tail->tot_len = pppos->in_tail->len; + //pppos->in_tail->tot_len = pppos->in_tail->len; if (pppos->in_tail != pppos->in_head) { - pbuf_cat(pppos->in_head, pppos->in_tail); + ppp_memory_buffer_cat(ppp->netif->memory_manager, pppos->in_head, pppos->in_tail); + //pbuf_cat(pppos->in_head, pppos->in_tail); /* give up the in_tail reference now */ pppos->in_tail = NULL; } } /* If we haven't started a packet, we need a packet header. */ pbuf_alloc_len = 0; -#if IP_FORWARD || LWIP_IPV6_FORWARD +#if IP_FORWARD || PPP_IPV6_FORWARD /* If IP forwarding is enabled we are reserving PBUF_LINK_ENCAPSULATION_HLEN * + PBUF_LINK_HLEN bytes so the packet is being allocated with enough header * space to be forwarded (to Ethernet for example). @@ -671,9 +674,12 @@ pppos_input(ppp_pcb *ppp, u8_t *s, int l) if (pppos->in_head == NULL) { pbuf_alloc_len = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN; } -#endif /* IP_FORWARD || LWIP_IPV6_FORWARD */ - next_pbuf = pbuf_alloc(PBUF_RAW, pbuf_alloc_len, PBUF_POOL); - if (next_pbuf == NULL) { +#endif /* IP_FORWARD || PPP_IPV6_FORWARD */ + u16_t pool_bufsize = ppp_memory_buffer_pool_alloc_unit_get(ppp->netif->memory_manager); + pbuf *next_pbuf = ppp_memory_buffer_allocate(ppp->netif->memory_manager, pool_bufsize, PPP_BUF_POOL); + + //next_pbuf = pbuf_alloc(PBUF_RAW, pbuf_alloc_len, PBUF_POOL); + if (next_pbuf == NULL || next_pbuf->len != next_pbuf->tot_len) { /* No free buffers. Drop the input packet and let the * higher layers deal with it. Continue processing * the received pbuf chain in case a new packet starts. */ @@ -683,6 +689,7 @@ pppos_input(ppp_pcb *ppp, u8_t *s, int l) pppos->in_state = PDSTART; /* Wait for flag sequence. */ break; } + next_pbuf->len = 0; if (pppos->in_head == NULL) { u8_t *payload = ((u8_t*)next_pbuf->payload) + pbuf_alloc_len; #if PPP_INPROC_IRQ_SAFE @@ -719,18 +726,20 @@ static void pppos_input_callback(void *arg) { ppp = ((struct pppos_input_header*)pb->payload)->ppp; if(pbuf_remove_header(pb, sizeof(struct pppos_input_header))) { - LWIP_ASSERT("pbuf_remove_header failed\n", 0); + PPP_ASSERT("pbuf_remove_header failed\n", 0); goto drop; } /* Dispatch the packet thereby consuming it. */ ppp_input(ppp, pb); + return; drop: LINK_STATS_INC(link.drop); MIB2_STATS_NETIF_INC(ppp->netif, ifindiscards); - pbuf_free(pb); + ppp_memory_buffer_free(pb); + //pbuf_free(pb); } #endif /* PPP_INPROC_IRQ_SAFE */ @@ -739,7 +748,7 @@ pppos_send_config(ppp_pcb *ppp, void *ctx, u32_t accm, int pcomp, int accomp) { int i; pppos_pcb *pppos = (pppos_pcb *)ctx; - LWIP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(ppp); pppos->pcomp = pcomp; pppos->accomp = accomp; @@ -760,9 +769,9 @@ pppos_recv_config(ppp_pcb *ppp, void *ctx, u32_t accm, int pcomp, int accomp) int i; pppos_pcb *pppos = (pppos_pcb *)ctx; PPPOS_DECL_PROTECT(lev); - LWIP_UNUSED_ARG(ppp); - LWIP_UNUSED_ARG(pcomp); - LWIP_UNUSED_ARG(accomp); + PPP_UNUSED_ARG(ppp); + PPP_UNUSED_ARG(pcomp); + PPP_UNUSED_ARG(accomp); /* Load the ACCM bits for the 32 control codes. */ PPPOS_PROTECT(lev); @@ -783,13 +792,17 @@ static void pppos_input_free_current_packet(pppos_pcb *pppos) { if (pppos->in_head != NULL) { - if (pppos->in_tail && (pppos->in_tail != pppos->in_head)) { - pbuf_free(pppos->in_tail); + struct pbuf *buf_next; + for (struct pbuf *buf = pppos->in_head; buf != NULL; buf = buf_next) { + buf_next = buf->next; + ppp_memory_buffer_free(buf); } - pbuf_free(pppos->in_head); - pppos->in_head = NULL; } - pppos->in_tail = NULL; + if (pppos->in_head != pppos->in_tail) { + ppp_memory_buffer_free(pppos->in_tail); + pppos->in_tail = NULL; + } + pppos->in_head = NULL; } /* @@ -829,7 +842,7 @@ pppos_output_append(pppos_pcb *pppos, err_t err, struct pbuf *nb, u8_t c, u8_t a /* Make sure there is room for the character and an escape code. * Sure we don't quite fill the buffer if the character doesn't * get escaped but is one character worth complicating this? */ - if ((PBUF_POOL_BUFSIZE - nb->len) < 2) { + if ((nb->tot_len - nb->len) < 2) { u32_t l = pppos->output_cb(pppos->ppp, (u8_t*)nb->payload, nb->len, pppos->ppp->ctx_cb); if (l != nb->len) { return ERR_IF; @@ -880,7 +893,8 @@ pppos_output_last(pppos_pcb *pppos, err_t err, struct pbuf *nb, u16_t *fcs) MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, nb->tot_len); MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts); LINK_STATS_INC(link.xmit); - pbuf_free(nb); + ppp_memory_buffer_free(nb); + //pbuf_free(nb); return ERR_OK; failed: @@ -888,7 +902,8 @@ failed: LINK_STATS_INC(link.err); LINK_STATS_INC(link.drop); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); - pbuf_free(nb); + ppp_memory_buffer_free(nb); + //pbuf_free(nb); return err; } diff --git a/features/netsocket/ppp/upap.c b/features/netsocket/ppp/source/upap.c similarity index 95% rename from features/netsocket/ppp/upap.c rename to features/netsocket/ppp/source/upap.c index e2185f55d9..b4e70cb194 100644 --- a/features/netsocket/ppp/upap.c +++ b/features/netsocket/ppp/source/upap.c @@ -41,7 +41,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && PAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ /* * @todo: @@ -159,9 +159,9 @@ void upap_authwithpeer(ppp_pcb *pcb, const char *user, const char *password) { /* Save the username and password we're given */ pcb->upap.us_user = user; - pcb->upap.us_userlen = (u8_t)LWIP_MIN(strlen(user), 0xff); + pcb->upap.us_userlen = (u8_t)PPP_MIN(strlen(user), 0xff); pcb->upap.us_passwd = password; - pcb->upap.us_passwdlen = (u8_t)LWIP_MIN(strlen(password), 0xff); + pcb->upap.us_passwdlen = (u8_t)PPP_MIN(strlen(password), 0xff); pcb->upap.us_transmits = 0; /* Lower layer up yet? */ @@ -458,7 +458,7 @@ static void upap_rauthreq(ppp_pcb *pcb, u_char *inp, int id, int len) { static void upap_rauthack(ppp_pcb *pcb, u_char *inp, int id, int len) { u_char msglen; char *msg; - LWIP_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); if (pcb->upap.us_clientstate != UPAPCS_AUTHREQ) /* XXX */ return; @@ -493,7 +493,7 @@ static void upap_rauthack(ppp_pcb *pcb, u_char *inp, int id, int len) { static void upap_rauthnak(ppp_pcb *pcb, u_char *inp, int id, int len) { u_char msglen; char *msg; - LWIP_UNUSED_ARG(id); + PPP_UNUSED_ARG(id); if (pcb->upap.us_clientstate != UPAPCS_AUTHREQ) /* XXX */ return; @@ -533,11 +533,13 @@ static void upap_sauthreq(ppp_pcb *pcb) { outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) + pcb->upap.us_userlen + pcb->upap.us_passwdlen; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN +outlen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -570,11 +572,13 @@ static void upap_sresp(ppp_pcb *pcb, u_char code, u_char id, const char *msg, in int outlen; outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen; - p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PPP_CTRL_PBUF_TYPE); + p = ppp_memory_buffer_allocate(pcb->netif->memory_manager, (u16_t)(PPP_HDRLEN +outlen), PPP_BUF_HEAP); + //p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PPP_CTRL_PBUF_TYPE); if(NULL == p) return; if(p->tot_len != p->len) { - pbuf_free(p); + ppp_memory_buffer_free(p); + //pbuf_free(p); return; } @@ -614,7 +618,7 @@ static int upap_printpkt(const u_char *p, int plen, void (*printer) (void *, con if (len < UPAP_HEADERLEN || len > plen) return 0; - if (code >= 1 && code <= (int)LWIP_ARRAYSIZE(upap_codenames)) + if (code >= 1 && code <= (int)PPP_ARRAYSIZE(upap_codenames)) printer(arg, " %s", upap_codenames[code-1]); else printer(arg, " code=0x%x", code); diff --git a/features/netsocket/ppp/utils.c b/features/netsocket/ppp/source/utils.c similarity index 98% rename from features/netsocket/ppp/utils.c rename to features/netsocket/ppp/source/utils.c index 546a86b23b..2b65728bd2 100644 --- a/features/netsocket/ppp/utils.c +++ b/features/netsocket/ppp/source/utils.c @@ -29,7 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #if 0 /* UNUSED */ #include @@ -178,7 +178,7 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args) { width = va_arg(args, int); c = *++fmt; } else { - while (lwip_isdigit(c)) { + while (ppp_isdigit(c)) { width = width * 10 + c - '0'; c = *++fmt; } @@ -190,7 +190,7 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args) { c = *++fmt; } else { prec = 0; - while (lwip_isdigit(c)) { + while (ppp_isdigit(c)) { prec = prec * 10 + c - '0'; c = *++fmt; } @@ -267,7 +267,7 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args) { #endif /* do we always have strerror() in embedded ? */ case 'I': ip = va_arg(args, u32_t); - ip = lwip_ntohl(ip); + ip = ppp_ntohl(ip); ppp_slprintf(num, sizeof(num), "%d.%d.%d.%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff); str = num; @@ -610,8 +610,8 @@ static void ppp_logit(int level, const char *fmt, va_list args) { } static void ppp_log_write(int level, char *buf) { - LWIP_UNUSED_ARG(level); /* necessary if PPPDEBUG is defined to an empty function */ - LWIP_UNUSED_ARG(buf); + PPP_UNUSED_ARG(level); /* necessary if PPPDEBUG is defined to an empty function */ + PPP_UNUSED_ARG(buf); PPPDEBUG(level, ("%s\n", buf) ); #if 0 if (log_to_fd >= 0 && (level != LOG_DEBUG || debug)) { @@ -636,7 +636,7 @@ void ppp_fatal(const char *fmt, ...) { ppp_logit(LOG_ERR, fmt, pvar); va_end(pvar); - LWIP_ASSERT("ppp_fatal", 0); /* as promised */ + PPP_ASSERT("ppp_fatal", 0); /* as promised */ } /* diff --git a/features/netsocket/ppp/vj.c b/features/netsocket/ppp/source/vj.c similarity index 87% rename from features/netsocket/ppp/vj.c rename to features/netsocket/ppp/source/vj.c index d8adde9e1b..67de4623f1 100644 --- a/features/netsocket/ppp/vj.c +++ b/features/netsocket/ppp/source/vj.c @@ -29,8 +29,7 @@ */ #include "ppp_opts.h" -#if PPP_SUPPORT && VJ_SUPPORT /* don't build if not configured for use in lwipopts.h */ - +#if PPP_SUPPORT && VJ_SUPPORT /* don't build if not configured for use in ppp_opts.h */ #include "ppp_impl.h" #include "pppdebug.h" @@ -95,32 +94,32 @@ vj_compress_init(struct vjcompress *comp) #define DECODEL(f) { \ if (*cp == 0) {\ - u32_t tmp_ = lwip_ntohl(f) + ((cp[1] << 8) | cp[2]); \ - (f) = lwip_htonl(tmp_); \ + u32_t tmp_ = ppp_ntohl(f) + ((cp[1] << 8) | cp[2]); \ + (f) = ppp_htonl(tmp_); \ cp += 3; \ } else { \ - u32_t tmp_ = lwip_ntohl(f) + (u32_t)*cp++; \ - (f) = lwip_htonl(tmp_); \ + u32_t tmp_ = ppp_ntohl(f) + (u32_t)*cp++; \ + (f) = ppp_htonl(tmp_); \ } \ } #define DECODES(f) { \ if (*cp == 0) {\ - u16_t tmp_ = lwip_ntohs(f) + (((u16_t)cp[1] << 8) | cp[2]); \ - (f) = lwip_htons(tmp_); \ + u16_t tmp_ = ppp_ntohs(f) + (((u16_t)cp[1] << 8) | cp[2]); \ + (f) = ppp_htons(tmp_); \ cp += 3; \ } else { \ - u16_t tmp_ = lwip_ntohs(f) + (u16_t)*cp++; \ - (f) = lwip_htons(tmp_); \ + u16_t tmp_ = ppp_ntohs(f) + (u16_t)*cp++; \ + (f) = ppp_htons(tmp_); \ } \ } #define DECODEU(f) { \ if (*cp == 0) {\ - (f) = lwip_htons(((u16_t)cp[1] << 8) | cp[2]); \ + (f) = ppp_htons(((u16_t)cp[1] << 8) | cp[2]); \ cp += 3; \ } else { \ - (f) = lwip_htons((u16_t)*cp++); \ + (f) = ppp_htons((u16_t)*cp++); \ } \ } @@ -301,7 +300,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) * needed in this section of code). */ if (TCPH_FLAGS(th) & TCP_URG) { - deltaS = lwip_ntohs(th->urgp); + deltaS = ppp_ntohs(th->urgp); ENCODEZ(deltaS); changes |= NEW_U; } else if (th->urgp != oth->urgp) { @@ -312,12 +311,12 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) goto uncompressed; } - if ((deltaS = (u16_t)(lwip_ntohs(th->wnd) - lwip_ntohs(oth->wnd))) != 0) { + if ((deltaS = (u16_t)(ppp_ntohs(th->wnd) - ppp_ntohs(oth->wnd))) != 0) { ENCODE(deltaS); changes |= NEW_W; } - if ((deltaL = lwip_ntohl(th->ackno) - lwip_ntohl(oth->ackno)) != 0) { + if ((deltaL = ppp_ntohl(th->ackno) - ppp_ntohl(oth->ackno)) != 0) { if (deltaL > 0xffff) { goto uncompressed; } @@ -326,7 +325,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) changes |= NEW_A; } - if ((deltaL = lwip_ntohl(th->seqno) - lwip_ntohl(oth->seqno)) != 0) { + if ((deltaL = ppp_ntohl(th->seqno) - ppp_ntohl(oth->seqno)) != 0) { if (deltaL > 0xffff) { goto uncompressed; } @@ -346,7 +345,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) * in case the other side missed the compressed version. */ if (IPH_LEN(ip) != IPH_LEN(&cs->cs_ip) && - lwip_ntohs(IPH_LEN(&cs->cs_ip)) == hlen) { + ppp_ntohs(IPH_LEN(&cs->cs_ip)) == hlen) { break; } /* no break */ @@ -361,7 +360,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) goto uncompressed; case NEW_S|NEW_A: - if (deltaS == deltaA && deltaS == lwip_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { + if (deltaS == deltaA && deltaS == ppp_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { /* special case for echoed terminal traffic */ changes = SPECIAL_I; cp = new_seq; @@ -369,7 +368,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) break; case NEW_S: - if (deltaS == lwip_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { + if (deltaS == ppp_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { /* special case for data xfer */ changes = SPECIAL_D; cp = new_seq; @@ -379,7 +378,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) break; } - deltaS = (u16_t)(lwip_ntohs(IPH_ID(ip)) - lwip_ntohs(IPH_ID(&cs->cs_ip))); + deltaS = (u16_t)(ppp_ntohs(IPH_ID(ip)) - ppp_ntohs(IPH_ID(&cs->cs_ip))); if (deltaS != 1) { ENCODEZ(deltaS); changes |= NEW_I; @@ -391,7 +390,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) * Grab the cksum before we overwrite it below. Then update our * state with this packet's header. */ - deltaA = lwip_ntohs(th->chksum); + deltaA = ppp_ntohs(th->chksum); MEMCPY(&cs->cs_ip, ip, hlen); /* @@ -409,7 +408,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) hlen -= deltaS + 4; if (pbuf_remove_header(np, hlen)){ /* Can we cope with this failing? Just assert for now */ - LWIP_ASSERT("pbuf_remove_header failed\n", 0); + PPP_ASSERT("pbuf_remove_header failed\n", 0); } cp = (u8_t*)np->payload; *cp++ = (u8_t)(changes | NEW_C); @@ -418,7 +417,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) hlen -= deltaS + 3; if (pbuf_remove_header(np, hlen)) { /* Can we cope with this failing? Just assert for now */ - LWIP_ASSERT("pbuf_remove_header failed\n", 0); + PPP_ASSERT("pbuf_remove_header failed\n", 0); } cp = (u8_t*)np->payload; *cp++ = (u8_t)changes; @@ -534,7 +533,7 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) cs = &comp->rstate[comp->last_recv]; hlen = IPH_HL(&cs->cs_ip) << 2; th = (struct tcp_hdr *)&((u8_t*)&cs->cs_ip)[hlen]; - th->chksum = lwip_htons((*cp << 8) | cp[1]); + th->chksum = ppp_htons((*cp << 8) | cp[1]); cp += 2; if (changes & TCP_PUSH_BIT) { TCPH_SET_FLAG(th, TCP_PSH); @@ -545,19 +544,19 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) switch (changes & SPECIALS_MASK) { case SPECIAL_I: { - u32_t i = lwip_ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; + u32_t i = ppp_ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; /* some compilers can't nest inline assembler.. */ - tmp = lwip_ntohl(th->ackno) + i; - th->ackno = lwip_htonl(tmp); - tmp = lwip_ntohl(th->seqno) + i; - th->seqno = lwip_htonl(tmp); + tmp = ppp_ntohl(th->ackno) + i; + th->ackno = ppp_htonl(tmp); + tmp = ppp_ntohl(th->seqno) + i; + th->seqno = ppp_htonl(tmp); } break; case SPECIAL_D: /* some compilers can't nest inline assembler.. */ - tmp = lwip_ntohl(th->seqno) + lwip_ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; - th->seqno = lwip_htonl(tmp); + tmp = ppp_ntohl(th->seqno) + ppp_ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; + th->seqno = ppp_htonl(tmp); break; default: @@ -581,8 +580,8 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) if (changes & NEW_I) { DECODES(cs->cs_ip._id); } else { - IPH_ID_SET(&cs->cs_ip, lwip_ntohs(IPH_ID(&cs->cs_ip)) + 1); - IPH_ID_SET(&cs->cs_ip, lwip_htons(IPH_ID(&cs->cs_ip))); + IPH_ID_SET(&cs->cs_ip, ppp_ntohs(IPH_ID(&cs->cs_ip)) + 1); + IPH_ID_SET(&cs->cs_ip, ppp_htons(IPH_ID(&cs->cs_ip))); } /* @@ -603,9 +602,9 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) #if BYTE_ORDER == LITTLE_ENDIAN tmp = n0->tot_len - vjlen + cs->cs_hlen; - IPH_LEN_SET(&cs->cs_ip, lwip_htons((u16_t)tmp)); + IPH_LEN_SET(&cs->cs_ip, ppp_htons((u16_t)tmp)); #else - IPH_LEN_SET(&cs->cs_ip, lwip_htons(n0->tot_len - vjlen + cs->cs_hlen)); + IPH_LEN_SET(&cs->cs_ip, ppp_htons(n0->tot_len - vjlen + cs->cs_hlen)); #endif /* recompute the ip header checksum */ @@ -621,11 +620,11 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) /* Remove the compressed header and prepend the uncompressed header. */ if (pbuf_remove_header(n0, vjlen)) { /* Can we cope with this failing? Just assert for now */ - LWIP_ASSERT("pbuf_remove_header failed\n", 0); + PPP_ASSERT("pbuf_remove_header failed\n", 0); goto bad; } - if(LWIP_MEM_ALIGN(n0->payload) != n0->payload) { + if(PPP_MEM_ALIGN(n0->payload) != n0->payload) { struct pbuf *np; #if IP_FORWARD @@ -633,9 +632,11 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) * the packet is being allocated with enough header space to be * forwarded (to Ethernet for example). */ - np = pbuf_alloc(PBUF_LINK, n0->len + cs->cs_hlen, PBUF_POOL); + np = ppp_memory_buffer_allocate(pcb->netif->memory_manager, n0->len + cs->cs_hlen, PPP_BUF_POOL); + //np = pbuf_alloc(PBUF_LINK, n0->len + cs->cs_hlen, PBUF_POOL); #else /* IP_FORWARD */ - np = pbuf_alloc(PBUF_RAW, n0->len + cs->cs_hlen, PBUF_POOL); + np = ppp_memory_buffer_allocate(pcb->netif->memory_manager, n0->len + cs->cs_hlen, PPP_BUF_POOL); + //np = pbuf_alloc(PBUF_RAW, n0->len + cs->cs_hlen, PBUF_POOL); #endif /* IP_FORWARD */ if(!np) { PPPDEBUG(LOG_WARNING, ("vj_uncompress_tcp: realign failed\n")); @@ -644,7 +645,7 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) if (pbuf_remove_header(np, cs->cs_hlen)) { /* Can we cope with this failing? Just assert for now */ - LWIP_ASSERT("pbuf_remove_header failed\n", 0); + PPP_ASSERT("pbuf_remove_header failed\n", 0); goto bad; } @@ -654,15 +655,17 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) pbuf_chain(np, n0->next); pbuf_dechain(n0); } - pbuf_free(n0); + ppp_memory_buffer_free(n0); + //pbuf_free(n0); n0 = np; } if (pbuf_add_header(n0, cs->cs_hlen)) { struct pbuf *np; - LWIP_ASSERT("vj_uncompress_tcp: cs->cs_hlen <= PBUF_POOL_BUFSIZE", cs->cs_hlen <= PBUF_POOL_BUFSIZE); - np = pbuf_alloc(PBUF_RAW, cs->cs_hlen, PBUF_POOL); + PPP_ASSERT("vj_uncompress_tcp: cs->cs_hlen <= PBUF_POOL_BUFSIZE", cs->cs_hlen <= PBUF_POOL_BUFSIZE); + np = ppp_memory_buffer_allocate(pcb->netif->memory_manager, cs->cs_hlen, PPP_BUF_POOL); + //np = pbuf_alloc(PBUF_RAW, cs->cs_hlen, PBUF_POOL); if(!np) { PPPDEBUG(LOG_WARNING, ("vj_uncompress_tcp: prepend failed\n")); goto bad; @@ -670,7 +673,7 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) pbuf_cat(np, n0); n0 = np; } - LWIP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen); + PPP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen); MEMCPY(n0->payload, &cs->cs_ip, cs->cs_hlen); *nb = n0;