mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #10974 from mikaleppanen/nano_ppp
Created PPP interface and PPP service classes to netsocketpull/11283/head
commit
399b517a47
|
@ -16,6 +16,9 @@
|
|||
^features/nanostack/sal-stack-nanostack
|
||||
^features/nanostack/targets
|
||||
^features/netsocket/emac-drivers
|
||||
^features/netsocket/ppp/include
|
||||
^features/netsocket/ppp/polarssl
|
||||
^features/netsocket/ppp/source
|
||||
^features/storage/filesystem/fat/ChaN
|
||||
^features/storage/filesystem/littlefs/littlefs/
|
||||
^features/unsupported/
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
#include "lwip/dns.h"
|
||||
#include "lwip/udp.h"
|
||||
|
||||
#include "ppp_lwip.h"
|
||||
|
||||
#include "LWIPStack.h"
|
||||
|
||||
LWIP::Interface *LWIP::Interface::list;
|
||||
|
@ -352,7 +350,7 @@ char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
|
|||
LWIP::Interface::Interface() :
|
||||
hw(NULL), has_addr_state(0),
|
||||
connected(NSAPI_STATUS_DISCONNECTED),
|
||||
dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false)
|
||||
dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp_enabled(false)
|
||||
{
|
||||
memset(&netif, 0, sizeof netif);
|
||||
|
||||
|
@ -395,7 +393,7 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN
|
|||
}
|
||||
interface->emac = &emac;
|
||||
interface->memory_manager = &memory_manager;
|
||||
interface->ppp = false;
|
||||
interface->ppp_enabled = false;
|
||||
|
||||
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
|
||||
netif->interface.hwaddr[0] = MBED_MAC_ADDR_0;
|
||||
|
@ -452,7 +450,7 @@ nsapi_error_t LWIP::add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetwo
|
|||
}
|
||||
interface->l3ip = &l3ip;
|
||||
interface->memory_manager = &memory_manager;
|
||||
interface->ppp = false;
|
||||
interface->ppp_enabled = false;
|
||||
|
||||
|
||||
|
||||
|
@ -462,7 +460,7 @@ nsapi_error_t LWIP::add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetwo
|
|||
#if LWIP_IPV4
|
||||
0, 0, 0,
|
||||
#endif
|
||||
interface, &LWIP::Interface::l3ip_if_init, tcpip_input)) {
|
||||
interface, &LWIP::Interface::l3ip_if_init, ip_input)) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -521,21 +519,27 @@ nsapi_error_t LWIP::remove_l3ip_interface(OnboardNetworkStack::Interface **inter
|
|||
|
||||
#endif //LWIP_L3IP
|
||||
}
|
||||
/* Internal API to preserve existing PPP functionality - revise to better match mbed_ipstak_add_ethernet_interface later */
|
||||
nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out)
|
||||
|
||||
|
||||
nsapi_error_t LWIP::add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out)
|
||||
{
|
||||
#if LWIP_PPP_API
|
||||
#if PPP_SUPPORT
|
||||
Interface *interface = new (std::nothrow) Interface();
|
||||
if (!interface) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
interface->hw = hw;
|
||||
interface->ppp = true;
|
||||
interface->ppp = &ppp;
|
||||
interface->memory_manager = &memory_manager;
|
||||
interface->ppp_enabled = true;
|
||||
|
||||
nsapi_error_t ret = ppp_lwip_if_init(hw, &interface->netif, stack);
|
||||
if (ret != NSAPI_ERROR_OK) {
|
||||
free(interface);
|
||||
return ret;
|
||||
// interface->netif.hwaddr_len = 0; should we set?
|
||||
|
||||
if (!netif_add(&interface->netif,
|
||||
#if LWIP_IPV4
|
||||
0, 0, 0,
|
||||
#endif
|
||||
interface, &LWIP::Interface::ppp_if_init, tcpip_input)) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (default_if) {
|
||||
|
@ -548,11 +552,62 @@ nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, nsapi_ip_stack
|
|||
|
||||
*interface_out = interface;
|
||||
|
||||
//lwip_add_random_seed(seed); to do?
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
|
||||
#else
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
|
||||
#endif //PPP_SUPPORT
|
||||
}
|
||||
|
||||
nsapi_error_t LWIP::remove_ppp_interface(OnboardNetworkStack::Interface **interface_out)
|
||||
{
|
||||
#if PPP_SUPPORT
|
||||
if ((interface_out != NULL) && (*interface_out != NULL)) {
|
||||
|
||||
Interface *lwip = static_cast<Interface *>(*interface_out);
|
||||
Interface *node = lwip->list;
|
||||
|
||||
if (lwip->list != NULL) {
|
||||
if (lwip->list == lwip) {
|
||||
// Power down PPP service
|
||||
lwip->ppp->power_down();
|
||||
if (netif_is_link_up(&lwip->netif)) {
|
||||
// Wait PPP service to report link down
|
||||
osSemaphoreAcquire(lwip->unlinked, osWaitForever);
|
||||
}
|
||||
netif_remove(&node->netif);
|
||||
lwip->list = lwip->list->next;
|
||||
delete node;
|
||||
} else {
|
||||
while (node->next != NULL && node->next != lwip) {
|
||||
node = node->next;
|
||||
}
|
||||
if (node->next != NULL && node->next == lwip) {
|
||||
Interface *remove = node->next;
|
||||
// Power down PPP service
|
||||
remove->ppp->power_down();
|
||||
if (netif_is_link_up(&lwip->netif)) {
|
||||
// Wait PPP service to report link down
|
||||
osSemaphoreAcquire(lwip->unlinked, osWaitForever);
|
||||
}
|
||||
netif_remove(&remove->netif);
|
||||
node->next = node->next->next;
|
||||
delete remove;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
#else
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
#endif //LWIP_PPP_API
|
||||
|
||||
#endif //PPP_SUPPORT
|
||||
}
|
||||
|
||||
void LWIP::set_default_interface(OnboardNetworkStack::Interface *interface)
|
||||
{
|
||||
if (interface) {
|
||||
|
@ -609,7 +664,7 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
|
|||
|
||||
#if LWIP_IPV4
|
||||
if (stack != IPV6_STACK) {
|
||||
if (!dhcp && !ppp) {
|
||||
if (!dhcp && !ppp_enabled) {
|
||||
ip4_addr_t ip_addr;
|
||||
ip4_addr_t netmask_addr;
|
||||
ip4_addr_t gw_addr;
|
||||
|
@ -629,23 +684,10 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
|
|||
client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_CONNECTING);
|
||||
}
|
||||
|
||||
if (ppp) {
|
||||
err_t err = ppp_lwip_connect(hw);
|
||||
if (err) {
|
||||
connected = NSAPI_STATUS_DISCONNECTED;
|
||||
if (client_callback) {
|
||||
client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
|
||||
}
|
||||
return err_remap(err);
|
||||
}
|
||||
}
|
||||
|
||||
if (!netif_is_link_up(&netif)) {
|
||||
if (blocking) {
|
||||
if (osSemaphoreAcquire(linked, LINK_TIMEOUT * 1000) != osOK) {
|
||||
if (ppp) {
|
||||
(void) ppp_lwip_disconnect(hw);
|
||||
}
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
}
|
||||
|
@ -665,9 +707,6 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
|
|||
// If doesn't have address
|
||||
if (!LWIP::get_ip_addr(true, &netif)) {
|
||||
if (osSemaphoreAcquire(has_any_addr, DHCP_TIMEOUT * 1000) != osOK) {
|
||||
if (ppp) {
|
||||
(void) ppp_lwip_disconnect(hw);
|
||||
}
|
||||
return NSAPI_ERROR_DHCP_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -713,21 +752,7 @@ nsapi_error_t LWIP::Interface::bringdown()
|
|||
}
|
||||
#endif
|
||||
|
||||
if (ppp) {
|
||||
/* this is a blocking call, returns when PPP is properly closed */
|
||||
err_t err = ppp_lwip_disconnect(hw);
|
||||
if (err) {
|
||||
return err_remap(err);
|
||||
}
|
||||
MBED_ASSERT(!netif_is_link_up(&netif));
|
||||
/*if (netif_is_link_up(&netif)) {
|
||||
if (sys_arch_sem_wait(&unlinked, 15000) == SYS_ARCH_TIMEOUT) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
netif_set_down(&netif);
|
||||
}
|
||||
netif_set_down(&netif);
|
||||
|
||||
#if LWIP_IPV6
|
||||
mbed_lwip_clear_ipv6_addresses(&netif);
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* 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 "lwip/tcpip.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/ethip6.h"
|
||||
#include "netsocket/nsapi_types.h"
|
||||
#include "netsocket/PPP.h"
|
||||
#include "LWIPStack.h"
|
||||
#include "lwip_tools.h"
|
||||
|
||||
#if PPP_SUPPORT
|
||||
|
||||
#if PPP_IPV4_SUPPORT && LWIP_IPV4
|
||||
err_t LWIP::Interface::ppp4_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
|
||||
{
|
||||
/* Increase reference counter since lwip stores handle to pbuf and frees
|
||||
it after output */
|
||||
pbuf_ref(p);
|
||||
|
||||
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
|
||||
bool ret = mbed_if->ppp->link_out(p, IPV4_STACK);
|
||||
return ret ? ERR_OK : ERR_IF;
|
||||
}
|
||||
#endif
|
||||
#if PPP_IPV6_SUPPORT && LWIP_IPV6
|
||||
err_t LWIP::Interface::ppp6_output(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr)
|
||||
{
|
||||
/* Increase reference counter since lwip stores handle to pbuf and frees
|
||||
it after output */
|
||||
pbuf_ref(p);
|
||||
|
||||
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
|
||||
bool ret = mbed_if->ppp->link_out(p, IPV6_STACK);
|
||||
return ret ? ERR_OK : ERR_IF;
|
||||
}
|
||||
#endif
|
||||
void LWIP::Interface::ppp_input(net_stack_mem_buf_t *buf)
|
||||
{
|
||||
struct pbuf *p = static_cast<struct pbuf *>(buf);
|
||||
|
||||
/* pass all packets to IP stack input */
|
||||
if (netif.input(p, &netif) != ERR_OK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Emac LWIP: IP input error\n"));
|
||||
|
||||
pbuf_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
void LWIP::Interface::ppp_state_change(bool up)
|
||||
{
|
||||
if (up) {
|
||||
#if PPP_IPV6_SUPPORT && LWIP_IPV6
|
||||
const nsapi_addr_t *ipv6_addr = LWIP::Interface::ppp->get_ip_address(NSAPI_IPv6);
|
||||
|
||||
ip_addr_t ip_addr;
|
||||
if (ipv6_addr && convert_mbed_addr_to_lwip(&ip_addr, ipv6_addr)) {
|
||||
netif_ip6_addr_set(&netif, 0, ip_2_ip6(&ip_addr));
|
||||
netif_ip6_addr_set_state(&netif, 0, IP6_ADDR_PREFERRED);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PPP_IPV4_SUPPORT && LWIP_IPV4
|
||||
const nsapi_addr_t *ipv4_addr = LWIP::Interface::ppp->get_ip_address(NSAPI_IPv4);
|
||||
if (ipv4_addr) {
|
||||
ip_addr_t ip_addr;
|
||||
ip_addr_t netmask;
|
||||
ip_addr_t gateway;
|
||||
|
||||
int conv_ip = 0;
|
||||
if (convert_mbed_addr_to_lwip(&ip_addr, ipv4_addr)) {
|
||||
conv_ip++;
|
||||
}
|
||||
|
||||
const nsapi_addr_t *ipv4_netmask = LWIP::Interface::ppp->get_netmask();
|
||||
if (ipv4_netmask && convert_mbed_addr_to_lwip(&netmask, ipv4_netmask)) {
|
||||
conv_ip++;
|
||||
}
|
||||
|
||||
const nsapi_addr_t *ipv4_gateway = LWIP::Interface::ppp->get_gateway();
|
||||
if (ipv4_gateway && convert_mbed_addr_to_lwip(&gateway, ipv4_gateway)) {
|
||||
conv_ip++;
|
||||
}
|
||||
|
||||
if (conv_ip == 3) {
|
||||
netif_set_addr(&netif, ip_2_ip4(&ip_addr), ip_2_ip4(&netmask), ip_2_ip4(&gateway));
|
||||
}
|
||||
|
||||
unsigned char dns_index = 0;
|
||||
// If default interface set default DNS addresses, otherwise interface specific
|
||||
struct netif *dns_netif = &netif;
|
||||
if (netif_check_default(&netif)) {
|
||||
dns_netif = NULL;
|
||||
}
|
||||
for (unsigned char index = 0; index < 2; index++) {
|
||||
ip_addr_t dns_server;
|
||||
const nsapi_addr_t *ipv4_dns_server = LWIP::Interface::ppp->get_dns_server(index);
|
||||
if (ipv4_dns_server && convert_mbed_addr_to_lwip(&dns_server, ipv4_dns_server)) {
|
||||
dns_setserver(dns_index++, &dns_server, dns_netif);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Read negotiated MTU
|
||||
uint32_t mtu = LWIP::Interface::ppp->get_mtu_size();
|
||||
netif.mtu = mtu;
|
||||
#if PPP_IPV6_SUPPORT && LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES
|
||||
netif.mtu6 = mtu;
|
||||
#endif
|
||||
tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, &netif, 1);
|
||||
} else {
|
||||
tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, &netif, 1);
|
||||
}
|
||||
}
|
||||
|
||||
err_t LWIP::Interface::ppp_if_init(struct netif *netif)
|
||||
{
|
||||
int err = ERR_OK;
|
||||
LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
|
||||
|
||||
mbed_if->ppp->set_memory_manager(*mbed_if->memory_manager);
|
||||
mbed_if->ppp->set_link_input_cb(mbed::callback(mbed_if, &LWIP::Interface::ppp_input));
|
||||
mbed_if->ppp->set_link_state_cb(mbed::callback(mbed_if, &LWIP::Interface::ppp_state_change));
|
||||
|
||||
/* Interface capabilities */
|
||||
netif->flags = NETIF_FLAG_BROADCAST;
|
||||
|
||||
if (!mbed_if->ppp->power_up()) {
|
||||
err = ERR_IF;
|
||||
}
|
||||
|
||||
netif->mtu = mbed_if->ppp->get_mtu_size();
|
||||
mbed_if->ppp->get_ifname(netif->name, NSAPI_INTERFACE_PREFIX_SIZE);
|
||||
|
||||
#if PPP_IPV4_SUPPORT && LWIP_IPV4
|
||||
netif->output = &LWIP::Interface::ppp4_output;
|
||||
#endif /* PPP_IPV4_SUPPORT */
|
||||
#if PPP_IPV6_SUPPORT && LWIP_IPV6
|
||||
netif->output_ip6 = &LWIP::Interface::ppp6_output;
|
||||
#endif
|
||||
netif->linkoutput = NULL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -39,6 +39,7 @@
|
|||
#include "lwip-sys/arch/sys_arch.h"
|
||||
|
||||
#include "LWIPStack.h"
|
||||
#include "lwip_tools.h"
|
||||
|
||||
#ifndef LWIP_SOCKET_MAX_MEMBERSHIPS
|
||||
#define LWIP_SOCKET_MAX_MEMBERSHIPS 4
|
||||
|
@ -69,89 +70,6 @@ void LWIP::socket_callback(struct netconn *nc, enum netconn_evt eh, u16_t len)
|
|||
lwip.adaptation.unlock();
|
||||
}
|
||||
|
||||
#if !LWIP_IPV4 || !LWIP_IPV6
|
||||
static bool all_zeros(const uint8_t *p, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (p[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool convert_lwip_addr_to_mbed(nsapi_addr_t *out, const ip_addr_t *in)
|
||||
{
|
||||
#if LWIP_IPV6
|
||||
if (IP_IS_V6(in)) {
|
||||
out->version = NSAPI_IPv6;
|
||||
SMEMCPY(out->bytes, ip_2_ip6(in), sizeof(ip6_addr_t));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV4
|
||||
if (IP_IS_V4(in)) {
|
||||
out->version = NSAPI_IPv4;
|
||||
SMEMCPY(out->bytes, ip_2_ip4(in), sizeof(ip4_addr_t));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV6 && LWIP_IPV4
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool convert_mbed_addr_to_lwip(ip_addr_t *out, const nsapi_addr_t *in)
|
||||
{
|
||||
#if LWIP_IPV6
|
||||
if (in->version == NSAPI_IPv6) {
|
||||
IP_SET_TYPE(out, IPADDR_TYPE_V6);
|
||||
SMEMCPY(ip_2_ip6(out), in->bytes, sizeof(ip6_addr_t));
|
||||
return true;
|
||||
}
|
||||
#if !LWIP_IPV4
|
||||
/* For bind() and other purposes, need to accept "null" of other type */
|
||||
/* (People use IPv4 0.0.0.0 as a general null) */
|
||||
if (in->version == NSAPI_UNSPEC ||
|
||||
(in->version == NSAPI_IPv4 && all_zeros(in->bytes, 4))) {
|
||||
ip_addr_set_zero_ip6(out);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LWIP_IPV4
|
||||
if (in->version == NSAPI_IPv4) {
|
||||
IP_SET_TYPE(out, IPADDR_TYPE_V4);
|
||||
SMEMCPY(ip_2_ip4(out), in->bytes, sizeof(ip4_addr_t));
|
||||
return true;
|
||||
}
|
||||
#if !LWIP_IPV6
|
||||
/* For symmetry with above, accept IPv6 :: as a general null */
|
||||
if (in->version == NSAPI_UNSPEC ||
|
||||
(in->version == NSAPI_IPv6 && all_zeros(in->bytes, 16))) {
|
||||
ip_addr_set_zero_ip4(out);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
if (in->version == NSAPI_UNSPEC) {
|
||||
#if IP_VERSION_PREF == PREF_IPV4
|
||||
ip_addr_set_zero_ip4(out);
|
||||
#else
|
||||
ip_addr_set_zero_ip6(out);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LWIP::tcpip_init_irq(void *eh)
|
||||
{
|
||||
static_cast<rtos::Semaphore *>(eh)->release();
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "netsocket/nsapi_types.h"
|
||||
#include "netsocket/EMAC.h"
|
||||
#include "netsocket/L3IP.h"
|
||||
#include "netsocket/PPP.h"
|
||||
#include "netsocket/OnboardNetworkStack.h"
|
||||
#include "LWIPMemoryManager.h"
|
||||
|
||||
|
@ -168,6 +169,18 @@ public:
|
|||
static err_t l3ip_if_init(struct netif *netif);
|
||||
#endif
|
||||
|
||||
#if PPP_SUPPORT
|
||||
#if PPP_IPV4_SUPPORT && LWIP_IPV4
|
||||
static err_t ppp4_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr);
|
||||
#endif
|
||||
#if PPP_IPV6_SUPPORT && LWIP_IPV6
|
||||
static err_t ppp6_output(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
|
||||
#endif
|
||||
void ppp_input(net_stack_mem_buf_t *buf);
|
||||
void ppp_state_change(bool up);
|
||||
static err_t ppp_if_init(struct netif *netif);
|
||||
#endif
|
||||
|
||||
union {
|
||||
#if LWIP_ETHERNET
|
||||
EMAC *emac; /**< HW specific emac implementation */
|
||||
|
@ -175,7 +188,9 @@ public:
|
|||
#if LWIP_L3IP
|
||||
L3IP *l3ip; /**< L3IP implementation */
|
||||
#endif
|
||||
|
||||
#if PPP_SUPPORT
|
||||
PPP *ppp; /**< PPP implementation */
|
||||
#endif
|
||||
void *hw; /**< alternative implementation pointer - used for PPP */
|
||||
};
|
||||
|
||||
|
@ -202,7 +217,7 @@ public:
|
|||
bool dhcp_started;
|
||||
bool dhcp_has_to_be_set;
|
||||
bool blocking;
|
||||
bool ppp;
|
||||
bool ppp_enabled;
|
||||
mbed::Callback<void(nsapi_event_t, intptr_t)> client_callback;
|
||||
struct netif netif;
|
||||
static Interface *list;
|
||||
|
@ -251,7 +266,7 @@ public:
|
|||
* @param[out] interface_out set to interface handle that must be passed to subsequent mbed_stack calls
|
||||
* @return NSAPI_ERROR_OK on success, or error code
|
||||
*/
|
||||
nsapi_error_t _add_ppp_interface(void *pcb, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out);
|
||||
virtual nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out);
|
||||
|
||||
/** Remove a network interface from IP stack
|
||||
*
|
||||
|
@ -261,6 +276,14 @@ public:
|
|||
*/
|
||||
virtual nsapi_error_t remove_l3ip_interface(OnboardNetworkStack::Interface **interface_out);
|
||||
|
||||
/** Remove a network interface from IP stack
|
||||
*
|
||||
* Removes PPP objects,network interface from stack list, and shutdown device driver.
|
||||
* @param[out] interface_out pointer to stack interface object controlling the PPP
|
||||
* @return NSAPI_ERROR_OK on success, or error code
|
||||
*/
|
||||
virtual nsapi_error_t remove_ppp_interface(OnboardNetworkStack::Interface **interface_out);
|
||||
|
||||
/** Get a domain name server from a list of servers to query
|
||||
*
|
||||
* Returns a DNS server address for a index. If returns error no more
|
||||
|
|
|
@ -36,10 +36,6 @@
|
|||
#include <stddef.h> /* for size_t */
|
||||
#include "mbed_toolchain.h"
|
||||
|
||||
#if LWIP_USE_EXTERNAL_MBEDTLS
|
||||
#include "mbedtls/md5.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -175,9 +171,6 @@ SET_MEMP_SECTION(memp_memory_TCPIP_MSG_INPKT_base);
|
|||
SET_MEMP_SECTION(memp_memory_SYS_TIMEOUT_base);
|
||||
SET_MEMP_SECTION(memp_memory_TCP_SEG_base);
|
||||
SET_MEMP_SECTION(memp_memory_TCPIP_MSG_API_base);
|
||||
SET_MEMP_SECTION(memp_memory_PPP_PCB_base);
|
||||
SET_MEMP_SECTION(memp_memory_PPPOS_PCB_base);
|
||||
SET_MEMP_SECTION(memp_memory_PPP_PCB_base);
|
||||
#if defined (__ICCARM__)
|
||||
#pragma default_variable_attributes =
|
||||
#endif
|
||||
|
|
|
@ -438,16 +438,6 @@ void sys_init(void) {
|
|||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_NETWORK_STACK, MBED_ERROR_CODE_INITIALIZATION_FAILED), "sys_init error, mutex initialization failed\n");
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
* Routine: sys_jiffies
|
||||
*---------------------------------------------------------------------------*
|
||||
* Description:
|
||||
* Used by PPP as a timestamp-ish value
|
||||
*---------------------------------------------------------------------------*/
|
||||
u32_t sys_jiffies(void) {
|
||||
return osKernelGetTickCount();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
* Routine: sys_arch_protect
|
||||
*---------------------------------------------------------------------------*
|
||||
|
|
|
@ -75,22 +75,34 @@
|
|||
#include "lwip/sys.h"
|
||||
#include <string.h>
|
||||
|
||||
/* pull in md5 of ppp? */
|
||||
#if !PPP_SUPPORT
|
||||
#undef PPP_SUPPORT
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_FAKED_ON 1
|
||||
#endif
|
||||
#if !LWIP_USE_EXTERNAL_MBEDTLS
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#include "netif/ppp/ppp.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "polarssl/md5.h"
|
||||
|
||||
#if PPP_FAKED_ON && !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS
|
||||
#undef LWIP_INCLUDED_POLARSSL_MD5
|
||||
#define LWIP_INCLUDED_POLARSSL_MD5 1
|
||||
#include "netif/ppp/polarssl/lwip_md5.c"
|
||||
#endif
|
||||
#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)
|
||||
|
||||
#endif /* !LWIP_USE_EXTERNAL_MBEDTLS */
|
||||
|
||||
/*
|
||||
* Map hashes and ciphers functions to mbed TLS
|
||||
*/
|
||||
#if LWIP_USE_EXTERNAL_MBEDTLS
|
||||
|
||||
#include "mbedtls/md5.h"
|
||||
|
||||
#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
|
||||
|
||||
#endif /* LWIP_USE_EXTERNAL_MBEDTLS */
|
||||
|
||||
static u8_t input[64];
|
||||
static u32_t base_time;
|
||||
|
@ -127,7 +139,7 @@ u32_t
|
|||
lwip_hook_tcp_isn(const void *local_ip_ptr, u16_t local_port,
|
||||
const void *remote_ip_ptr, u16_t remote_port)
|
||||
{
|
||||
lwip_md5_context ctx;
|
||||
MD5_context ctx;
|
||||
u8_t output[16];
|
||||
u32_t isn;
|
||||
const ip_addr_t *local_ip = local_ip_ptr;
|
||||
|
@ -176,13 +188,12 @@ lwip_hook_tcp_isn(const void *local_ip_ptr, u16_t local_port,
|
|||
input[35] = remote_port & 0xff;
|
||||
|
||||
/* The secret and padding are already filled in. */
|
||||
|
||||
/* Generate the hash, using MD5. */
|
||||
lwip_md5_init(&ctx);
|
||||
lwip_md5_starts(&ctx);
|
||||
lwip_md5_update(&ctx, input, sizeof(input));
|
||||
lwip_md5_finish(&ctx, output);
|
||||
lwip_md5_free(&ctx);
|
||||
MD5_init(&ctx);
|
||||
MD5_starts(&ctx);
|
||||
MD5_update(&ctx, input, sizeof(input));
|
||||
MD5_finish(&ctx, output);
|
||||
MD5_free(&ctx);
|
||||
|
||||
/* Arbitrarily take the first 32 bits from the generated hash. */
|
||||
MEMCPY(&isn, output, sizeof(isn));
|
||||
|
|
|
@ -58,9 +58,6 @@
|
|||
#include "lwip/mld6.h"
|
||||
#include "lwip/api.h"
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
|
||||
#ifndef LWIP_SKIP_PACKING_CHECK
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
|
@ -175,12 +172,6 @@ PACK_STRUCT_END
|
|||
#if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1))
|
||||
#error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_PPP_API && (NO_SYS==1))
|
||||
#error "If you want to use PPP API, you have to define NO_SYS=0 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_PPP_API && (PPP_SUPPORT==0))
|
||||
#error "If you want to use PPP API, you have to enable PPP_SUPPORT in your lwipopts.h"
|
||||
#endif
|
||||
#if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP)
|
||||
#error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h"
|
||||
#endif
|
||||
|
@ -208,20 +199,8 @@ PACK_STRUCT_END
|
|||
#if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT)))
|
||||
#error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST"
|
||||
#endif
|
||||
#if PPP_SUPPORT && !PPPOS_SUPPORT && !PPPOE_SUPPORT && !PPPOL2TP_SUPPORT
|
||||
#error "PPP_SUPPORT needs at least one of PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on"
|
||||
#endif
|
||||
#if PPP_SUPPORT && !PPP_IPV4_SUPPORT && !PPP_IPV6_SUPPORT
|
||||
#error "PPP_SUPPORT needs PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on"
|
||||
#endif
|
||||
#if PPP_SUPPORT && PPP_IPV4_SUPPORT && !LWIP_IPV4
|
||||
#error "PPP_IPV4_SUPPORT needs LWIP_IPV4 turned on"
|
||||
#endif
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT && !LWIP_IPV6
|
||||
#error "PPP_IPV6_SUPPORT needs LWIP_IPV6 turned on"
|
||||
#endif
|
||||
#if !LWIP_ETHERNET && (LWIP_ARP || PPPOE_SUPPORT)
|
||||
#error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT"
|
||||
#if !LWIP_ETHERNET && LWIP_ARP
|
||||
#error "LWIP_ETHERNET needs to be turned on for LWIP_ARP"
|
||||
#endif
|
||||
#if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING
|
||||
#error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too"
|
||||
|
@ -370,9 +349,6 @@ lwip_init(void)
|
|||
#if LWIP_DNS
|
||||
dns_init();
|
||||
#endif /* LWIP_DNS */
|
||||
#if PPP_SUPPORT
|
||||
ppp_init();
|
||||
#endif
|
||||
|
||||
#if LWIP_TIMERS
|
||||
sys_timeouts_init();
|
||||
|
|
|
@ -68,7 +68,6 @@
|
|||
#include "lwip/igmp.h"
|
||||
#include "lwip/timeouts.h"
|
||||
/* needed by default MEMP_NUM_SYS_TIMEOUT */
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/priv/nd6_priv.h"
|
||||
|
|
|
@ -83,8 +83,7 @@
|
|||
#if LWIP_CHECKSUM_ON_COPY
|
||||
#include "lwip/inet_chksum.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "string.h"
|
||||
|
||||
#define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
|
||||
/* Since the pool is created in memp, PBUF_POOL_BUFSIZE will be automatically
|
||||
|
|
|
@ -505,7 +505,7 @@
|
|||
* The number of sys timeouts used by the core stack (not apps)
|
||||
* The default number of timeouts is calculated here for all enabled modules.
|
||||
*/
|
||||
#define LWIP_NUM_SYS_TIMEOUT_INTERNAL (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_NUM_TIMEOUTS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD)))
|
||||
#define LWIP_NUM_SYS_TIMEOUT_INTERNAL (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD)))
|
||||
|
||||
/**
|
||||
* MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts.
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
|
||||
*
|
||||
* Extracted from chap_ms.c by James Carlson.
|
||||
*
|
||||
* Copyright (c) 1995 Eric Rosenquist. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.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
|
||||
|
||||
/*
|
||||
* Map hashes and ciphers functions to PolarSSL
|
||||
*/
|
||||
#if !LWIP_USE_EXTERNAL_MBEDTLS
|
||||
|
||||
#include "netif/ppp/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)
|
||||
|
||||
#include "netif/ppp/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)
|
||||
|
||||
#include "netif/ppp/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)
|
||||
|
||||
#include "netif/ppp/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)
|
||||
|
||||
#include "netif/ppp/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)
|
||||
|
||||
#endif /* !LWIP_USE_EXTERNAL_MBEDTLS */
|
||||
|
||||
/*
|
||||
* Map hashes and ciphers functions to mbed TLS
|
||||
*/
|
||||
#if LWIP_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
|
||||
|
||||
#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 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 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 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
|
||||
|
||||
#endif /* LWIP_USE_EXTERNAL_MBEDTLS */
|
||||
|
||||
void pppcrypt_56_to_64_bit_key(u_char *key, u_char *des_key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PPPCRYPT_H */
|
||||
|
||||
#endif /* PPP_SUPPORT */
|
|
@ -51,11 +51,6 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPPOE_SUPPORT
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
#ifdef LWIP_HOOK_FILENAME
|
||||
#include LWIP_HOOK_FILENAME
|
||||
#endif
|
||||
|
|
|
@ -23,9 +23,14 @@
|
|||
#include "lwip/api.h"
|
||||
|
||||
#include "LWIPStack.h"
|
||||
#include "lwip_tools.h"
|
||||
|
||||
#include "netsocket/nsapi_types.h"
|
||||
|
||||
#if !LWIP_IPV4 || !LWIP_IPV6
|
||||
static bool all_zeros(const uint8_t *p, int len);
|
||||
#endif
|
||||
|
||||
/* LWIP error remapping */
|
||||
nsapi_error_t LWIP::err_remap(err_t err)
|
||||
{
|
||||
|
@ -192,3 +197,86 @@ void LWIP::arena_dealloc(struct mbed_lwip_socket *s)
|
|||
free(s->multicast_memberships);
|
||||
s->multicast_memberships = NULL;
|
||||
}
|
||||
|
||||
bool convert_lwip_addr_to_mbed(nsapi_addr_t *out, const ip_addr_t *in)
|
||||
{
|
||||
#if LWIP_IPV6
|
||||
if (IP_IS_V6(in)) {
|
||||
out->version = NSAPI_IPv6;
|
||||
SMEMCPY(out->bytes, ip_2_ip6(in), sizeof(ip6_addr_t));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV4
|
||||
if (IP_IS_V4(in)) {
|
||||
out->version = NSAPI_IPv4;
|
||||
SMEMCPY(out->bytes, ip_2_ip4(in), sizeof(ip4_addr_t));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV6 && LWIP_IPV4
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool convert_mbed_addr_to_lwip(ip_addr_t *out, const nsapi_addr_t *in)
|
||||
{
|
||||
#if LWIP_IPV6
|
||||
if (in->version == NSAPI_IPv6) {
|
||||
IP_SET_TYPE(out, IPADDR_TYPE_V6);
|
||||
SMEMCPY(ip_2_ip6(out), in->bytes, sizeof(ip6_addr_t));
|
||||
return true;
|
||||
}
|
||||
#if !LWIP_IPV4
|
||||
/* For bind() and other purposes, need to accept "null" of other type */
|
||||
/* (People use IPv4 0.0.0.0 as a general null) */
|
||||
if (in->version == NSAPI_UNSPEC ||
|
||||
(in->version == NSAPI_IPv4 && all_zeros(in->bytes, 4))) {
|
||||
ip_addr_set_zero_ip6(out);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LWIP_IPV4
|
||||
if (in->version == NSAPI_IPv4) {
|
||||
IP_SET_TYPE(out, IPADDR_TYPE_V4);
|
||||
SMEMCPY(ip_2_ip4(out), in->bytes, sizeof(ip4_addr_t));
|
||||
return true;
|
||||
}
|
||||
#if !LWIP_IPV6
|
||||
/* For symmetry with above, accept IPv6 :: as a general null */
|
||||
if (in->version == NSAPI_UNSPEC ||
|
||||
(in->version == NSAPI_IPv6 && all_zeros(in->bytes, 16))) {
|
||||
ip_addr_set_zero_ip4(out);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
if (in->version == NSAPI_UNSPEC) {
|
||||
#if IP_VERSION_PREF == PREF_IPV4
|
||||
ip_addr_set_zero_ip4(out);
|
||||
#else
|
||||
ip_addr_set_zero_ip6(out);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !LWIP_IPV4 || !LWIP_IPV6
|
||||
static bool all_zeros(const uint8_t *p, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (p[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef LWIPTOOLS_H_
|
||||
#define LWIPTOOLS_H_
|
||||
|
||||
bool convert_lwip_addr_to_mbed(nsapi_addr_t *out, const ip_addr_t *in);
|
||||
bool convert_mbed_addr_to_lwip(ip_addr_t *out, const nsapi_addr_t *in);
|
||||
|
||||
#endif /* LWIPTOOLS_H_ */
|
|
@ -119,17 +119,10 @@
|
|||
#define MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE 512
|
||||
#endif
|
||||
|
||||
// Thread stack size for private PPP thread
|
||||
#ifndef MBED_CONF_LWIP_PPP_THREAD_STACKSIZE
|
||||
#define MBED_CONF_LWIP_PPP_THREAD_STACKSIZE 768
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#define PPP_THREAD_STACK_SIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_PPP_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#define PPP_THREAD_STACK_SIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_PPP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
@ -313,11 +306,6 @@
|
|||
#define DNS_DEBUG LWIP_DBG_OFF
|
||||
#define IP6_DEBUG LWIP_DBG_OFF
|
||||
|
||||
#if MBED_CONF_LWIP_ENABLE_PPP_TRACE
|
||||
#define PPP_DEBUG LWIP_DBG_ON
|
||||
#else
|
||||
#define PPP_DEBUG LWIP_DBG_OFF
|
||||
#endif //MBED_CONF_LWIP_ENABLE_PPP_TRACE
|
||||
#define ETHARP_DEBUG LWIP_DBG_OFF
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
|
@ -358,33 +346,40 @@
|
|||
#define INTERFACE_NAME_MAX_SIZE NSAPI_INTERFACE_NAME_MAX_SIZE
|
||||
// Note generic macro name used rather than MBED_CONF_LWIP_PPP_ENABLED
|
||||
// to allow users like PPPCellularInterface to detect that nsapi_ppp.h is available.
|
||||
#if NSAPI_PPP_AVAILABLE
|
||||
#define PPP_SUPPORT 1
|
||||
#if MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Disable DAD for PPP
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
|
||||
// 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
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#define CHAP_SUPPORT 1
|
||||
#define PPP_INPROC_IRQ_SAFE 1
|
||||
// Save RAM
|
||||
#define PAP_SUPPORT 0
|
||||
#define VJ_SUPPORT 0
|
||||
#define PRINTPKT_SUPPORT 0
|
||||
|
||||
// Broadcast
|
||||
#define IP_SOF_BROADCAST 0
|
||||
#define IP_SOF_BROADCAST_RECV 0
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#define MAXNAMELEN 64 /* max length of hostname or name for auth */
|
||||
#define MAXSECRETLEN 64
|
||||
#endif // NSAPI_PPP_AVAILABLE
|
||||
#endif
|
||||
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
#define LWIP_CHECKSUM_ON_COPY 0
|
||||
|
||||
|
@ -399,8 +394,9 @@
|
|||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#include "mbedtls/md5.h"
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#endif /* LWIPOPTS_H_ */
|
||||
|
|
|
@ -34,26 +34,23 @@
|
|||
"value": false
|
||||
},
|
||||
"ppp-enabled": {
|
||||
"help": "Enable support for PPP interfaces",
|
||||
"value": false,
|
||||
"macro_name": "NSAPI_PPP_AVAILABLE"
|
||||
"help": "Enable support for PPP interfaces (obsolete: use netsocket/ppp configuration instead)",
|
||||
"value": false
|
||||
},
|
||||
"ppp-ipv4-enabled": {
|
||||
"help": "Enable support for ipv4 PPP interface",
|
||||
"value": true,
|
||||
"macro_name": "NSAPI_PPP_IPV4_AVAILABLE"
|
||||
"help": "Enable support for ipv4 PPP interface (obsolete: use netsocket/ppp configuration instead)",
|
||||
"value": false
|
||||
},
|
||||
"ppp-ipv6-enabled": {
|
||||
"help": "Enable support for ipv6 PPP interface",
|
||||
"value": false,
|
||||
"macro_name": "NSAPI_PPP_IPV6_AVAILABLE"
|
||||
"help": "Enable support for ipv6 PPP interface (obsolete: use netsocket/ppp configuration instead)",
|
||||
"value": false
|
||||
},
|
||||
"use-mbed-trace": {
|
||||
"help": "Use mbed trace for debug, rather than printf",
|
||||
"value": false
|
||||
},
|
||||
"enable-ppp-trace": {
|
||||
"help": "Enable trace support for PPP interfaces",
|
||||
"help": "Enable trace support for PPP interfaces (obsolete: use netsocket/ppp configuration instead)",
|
||||
"value": false
|
||||
},
|
||||
"socket-max": {
|
||||
|
@ -129,7 +126,7 @@
|
|||
"value": 512
|
||||
},
|
||||
"ppp-thread-stacksize": {
|
||||
"help": "Thread stack size for PPP",
|
||||
"help": "Thread stack size for PPP (obsolete: use netsocket/ppp configuration instead)",
|
||||
"value": 768
|
||||
}
|
||||
},
|
||||
|
@ -171,7 +168,6 @@
|
|||
"RZ_A1_EMAC": {
|
||||
"tcpip-thread-stacksize": 1328,
|
||||
"default-thread-stacksize": 640,
|
||||
"ppp-thread-stacksize": 896,
|
||||
"memp-num-tcp-seg": 32,
|
||||
"tcp-mss": 1440,
|
||||
"tcp-snd-buf": "(8 * TCP_MSS)",
|
||||
|
@ -182,7 +178,6 @@
|
|||
"CYW943012P6EVB_01": {
|
||||
"tcpip-thread-stacksize": 8192,
|
||||
"default-thread-stacksize": 640,
|
||||
"ppp-thread-stacksize": 896,
|
||||
"memp-num-tcp-seg": 24,
|
||||
"tcp-socket-max": 10,
|
||||
"udp-socket-max":10,
|
||||
|
@ -196,7 +191,6 @@
|
|||
"CY8CPROTO_062_4343W": {
|
||||
"tcpip-thread-stacksize": 8192,
|
||||
"default-thread-stacksize": 640,
|
||||
"ppp-thread-stacksize": 896,
|
||||
"memp-num-tcp-seg": 24,
|
||||
"tcp-socket-max": 10,
|
||||
"udp-socket-max":10,
|
||||
|
@ -210,7 +204,6 @@
|
|||
"CY8CKIT_062_WIFI_BT": {
|
||||
"tcpip-thread-stacksize": 8192,
|
||||
"default-thread-stacksize": 640,
|
||||
"ppp-thread-stacksize": 896,
|
||||
"memp-num-tcp-seg": 48,
|
||||
"tcp-socket-max": 10,
|
||||
"udp-socket-max":10,
|
||||
|
@ -224,7 +217,6 @@
|
|||
"CY8CKIT_062S2_43012": {
|
||||
"tcpip-thread-stacksize": 8192,
|
||||
"default-thread-stacksize": 640,
|
||||
"ppp-thread-stacksize": 896,
|
||||
"memp-num-tcp-seg": 24,
|
||||
"tcp-socket-max": 10,
|
||||
"udp-socket-max":10,
|
||||
|
|
|
@ -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 <errno.h>
|
||||
#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 "netif/ppp/pppapi.h"
|
||||
}
|
||||
|
||||
#include "nsapi_ppp.h"
|
||||
#include "ppp_lwip.h"
|
||||
#include "LWIPStack.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
using rtos::Thread;
|
||||
using events::EventQueue;
|
||||
|
||||
#if LWIP_PPP_API
|
||||
|
||||
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 LWIP::Interface *my_interface;
|
||||
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 sys_sem_t ppp_close_sem;
|
||||
static Callback<void(nsapi_event_t, intptr_t)> 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, PPP_THREAD_STACK_SIZE, NULL, "ppp_lwip");
|
||||
|
||||
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;
|
||||
sys_sem_signal(&ppp_close_sem);
|
||||
}
|
||||
|
||||
/* 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_lwip_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_lwip_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 */
|
||||
sys_arch_sem_wait(&ppp_close_sem, 0);
|
||||
}
|
||||
ppp_active = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" nsapi_error_t ppp_lwip_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;
|
||||
}
|
||||
|
||||
sys_sem_new(&ppp_close_sem, 0);
|
||||
}
|
||||
|
||||
#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<void(nsapi_event_t, intptr_t)> 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) {
|
||||
LWIP &lwip = LWIP::get_instance();
|
||||
retcode = lwip._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_lwip_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 &LWIP::get_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 /* LWIP_PPP_API */
|
||||
|
||||
} // namespace mbed
|
|
@ -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 "netif/ppp/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_lwip_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_lwip_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_lwip_disconnect(void *pcb);
|
||||
#else
|
||||
/**
|
||||
* Stubs in case LWIP PPP is not enabled
|
||||
*/
|
||||
#define ppp_lwip_if_init(pcb, netif, stack) NSAPI_ERROR_UNSUPPORTED
|
||||
#define ppp_lwip_connect(pcb) ERR_IF
|
||||
#define ppp_lwip_disconnect(pcb) ERR_IF
|
||||
#endif //LWIP_PPP_API
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PPP_LWIP_H_ */
|
|
@ -34,7 +34,10 @@ public:
|
|||
|
||||
void get_mac_address(uint8_t *buf) const
|
||||
{
|
||||
interface_phy.get_mac_address(buf);
|
||||
NanostackMACPhy *phy = interface_phy.nanostack_mac_phy();
|
||||
if (phy) {
|
||||
phy->get_mac_address(buf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2019 ARM Limited. All rights reserved.
|
||||
* 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 NANOSTACKPPPINTERFACE_H
|
||||
#define NANOSTACKPPPINTERFACE_H
|
||||
|
||||
#include "MeshInterfaceNanostack.h"
|
||||
#include "PPPInterface.h"
|
||||
#include "NanostackPPPPhy.h"
|
||||
|
||||
class Nanostack::PPPInterface : public Nanostack::Interface {
|
||||
public:
|
||||
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
|
||||
const char *netmask, const char *gw,
|
||||
nsapi_ip_stack_t stack = DEFAULT_STACK,
|
||||
bool blocking = true);
|
||||
virtual nsapi_error_t bringdown();
|
||||
|
||||
typedef mbed::Callback<void (uint8_t up, int8_t device_id)> link_state_cb_t;
|
||||
virtual void set_link_state_changed_callback(link_state_cb_t link_state_cb);
|
||||
|
||||
private:
|
||||
friend class Nanostack;
|
||||
PPPInterface(NanostackPhy &phy) : Interface(phy), link_state_up(false), enet_tasklet_connected(false) {}
|
||||
nsapi_error_t initialize();
|
||||
void link_state_changed(bool up);
|
||||
nsapi_error_t connect_enet_tasklet();
|
||||
link_state_cb_t link_state_cb;
|
||||
bool link_state_up;
|
||||
bool enet_tasklet_connected;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,386 @@
|
|||
/*
|
||||
* 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 "NanostackPPPInterface.h"
|
||||
#include "NanostackPPPPhy.h"
|
||||
#include "PPP.h"
|
||||
#include "nsdynmemLIB.h"
|
||||
#include "arm_hal_phy.h"
|
||||
#include "mbed_interface.h"
|
||||
#include "mesh_system.h"
|
||||
#include "callback_handler.h"
|
||||
#include "enet_tasklet.h"
|
||||
#include "ip6string.h"
|
||||
|
||||
class PPPPhy : public NanostackPPPPhy {
|
||||
public:
|
||||
PPPPhy(NanostackMemoryManager &mem, PPP &m);
|
||||
virtual int8_t phy_register();
|
||||
|
||||
virtual void phy_power_on();
|
||||
virtual void phy_power_off();
|
||||
|
||||
virtual void get_iid64(uint8_t *iid64);
|
||||
virtual uint16_t get_mtu();
|
||||
|
||||
virtual void set_link_state_change_cb(link_state_change_cb_t cb);
|
||||
|
||||
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);
|
||||
|
||||
void ppp_phy_rx(net_stack_mem_buf_t *mem);
|
||||
void link_state_cb(bool up);
|
||||
|
||||
private:
|
||||
NanostackMemoryManager &memory_manager;
|
||||
PPP &ppp;
|
||||
uint8_t iid64[8];
|
||||
link_state_change_cb_t link_state_change_cb;
|
||||
bool active;
|
||||
bool powered_up;
|
||||
int8_t device_id;
|
||||
phy_device_driver_s phy;
|
||||
};
|
||||
|
||||
nsapi_error_t Nanostack::PPPInterface::initialize()
|
||||
{
|
||||
nanostack_lock();
|
||||
|
||||
if (register_phy() < 0) {
|
||||
nanostack_unlock();
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
nanostack_unlock();
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t Nanostack::PPPInterface::bringup(bool dhcp, const char *ip,
|
||||
const char *netmask, const char *gw,
|
||||
nsapi_ip_stack_t stack, bool blocking)
|
||||
{
|
||||
if (stack == IPV4_STACK) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
_blocking = blocking;
|
||||
|
||||
if (link_state_up) {
|
||||
connect_enet_tasklet();
|
||||
}
|
||||
|
||||
if (blocking) {
|
||||
uint8_t retries = 10;
|
||||
while (_connect_status != NSAPI_STATUS_GLOBAL_UP) {
|
||||
int32_t count = connect_semaphore.try_acquire_for(3000);
|
||||
if (count <= 0 && retries-- == 0) {
|
||||
return NSAPI_ERROR_DHCP_FAILURE; // sort of...
|
||||
}
|
||||
// Not up until global up
|
||||
if (_connect_status == NSAPI_STATUS_LOCAL_UP) {
|
||||
_connect_status = NSAPI_STATUS_CONNECTING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t Nanostack::PPPInterface::connect_enet_tasklet()
|
||||
{
|
||||
if (enet_tasklet_connected) {
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
enet_tasklet_connected = true;
|
||||
|
||||
nanostack_lock();
|
||||
|
||||
if (interface_id < 0) {
|
||||
enet_tasklet_init();
|
||||
__mesh_handler_set_callback(this);
|
||||
interface_id = enet_tasklet_ppp_network_init(_device_id);
|
||||
}
|
||||
int8_t status = -1;
|
||||
if (interface_id >= 0) {
|
||||
status = enet_tasklet_connect(&__mesh_handler_c_callback, interface_id);
|
||||
}
|
||||
|
||||
nanostack_unlock();
|
||||
|
||||
if (status == -1) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
} else if (status == -2) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
} else if (status == -3) {
|
||||
return NSAPI_ERROR_ALREADY;
|
||||
} else if (status != 0) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t Nanostack::PPPInterface::bringdown()
|
||||
{
|
||||
nanostack_lock();
|
||||
int8_t status = enet_tasklet_disconnect(true);
|
||||
enet_tasklet_connected = false;
|
||||
nanostack_unlock();
|
||||
|
||||
if (status == -1) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
} else if (status == -2) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
} else if (status == -3) {
|
||||
return NSAPI_ERROR_ALREADY;
|
||||
} else if (status != 0) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (_blocking) {
|
||||
int32_t count = disconnect_semaphore.try_acquire_for(30000);
|
||||
|
||||
if (count <= 0) {
|
||||
return NSAPI_ERROR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
void Nanostack::PPPInterface::link_state_changed(bool up)
|
||||
{
|
||||
link_state_up = up;
|
||||
|
||||
// If application callback is set
|
||||
if (link_state_cb) {
|
||||
link_state_cb(up, _device_id);
|
||||
} else {
|
||||
if (up) {
|
||||
connect_enet_tasklet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Nanostack::PPPInterface::set_link_state_changed_callback(link_state_cb_t new_link_state_cb)
|
||||
{
|
||||
link_state_cb = new_link_state_cb;
|
||||
}
|
||||
|
||||
// GAH! no handles on the callback. Force a single interface
|
||||
static PPPPhy *single_phy;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static int8_t ppp_phy_interface_state_control(phy_interface_state_e, uint8_t)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int8_t ppp_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
|
||||
{
|
||||
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
|
||||
}
|
||||
|
||||
PPPPhy::PPPPhy(NanostackMemoryManager &mem, PPP &m) : memory_manager(mem), ppp(m), link_state_change_cb(NULL), active(false), powered_up(false), device_id(-1)
|
||||
{
|
||||
}
|
||||
|
||||
void PPPPhy::ppp_phy_rx(net_stack_mem_buf_t *mem)
|
||||
{
|
||||
if (!active) {
|
||||
memory_manager.free(mem);
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t *ptr = NULL;
|
||||
uint8_t *tmpbuf = NULL;
|
||||
uint32_t total_len;
|
||||
|
||||
if (memory_manager.get_next(mem) == NULL) {
|
||||
// Easy contiguous case
|
||||
ptr = static_cast<const uint8_t *>(memory_manager.get_ptr(mem));
|
||||
total_len = memory_manager.get_len(mem);
|
||||
} else {
|
||||
// Nanostack can't accept chunked data - make temporary contiguous copy
|
||||
total_len = memory_manager.get_total_len(mem);
|
||||
ptr = tmpbuf = static_cast<uint8_t *>(ns_dyn_mem_temporary_alloc(total_len));
|
||||
if (tmpbuf) {
|
||||
memory_manager.copy_from_buf(tmpbuf, total_len, mem);
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr && phy.phy_rx_cb) {
|
||||
phy.phy_rx_cb(ptr, total_len, 0xff, 0, device_id);
|
||||
}
|
||||
ns_dyn_mem_free(tmpbuf);
|
||||
memory_manager.free(mem);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
int8_t PPPPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
|
||||
{
|
||||
if (!active) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
net_stack_mem_buf_t *mem = memory_manager.alloc_pool(data_len, 0);
|
||||
if (!mem) {
|
||||
return -1;
|
||||
}
|
||||
memory_manager.copy_to_buf(mem, data_ptr, data_len);
|
||||
|
||||
// They take ownership - their responsibility to free
|
||||
ppp.link_out(mem, IPV6_STACK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int8_t PPPPhy::phy_register()
|
||||
{
|
||||
active = true;
|
||||
|
||||
if (device_id < 0) {
|
||||
phy.PHY_MAC = iid64;
|
||||
phy.address_write = NULL;
|
||||
phy.driver_description = const_cast<char *>("PPP");
|
||||
phy.link_type = PHY_LINK_PPP;
|
||||
phy.phy_MTU = 0;
|
||||
phy.phy_header_length = 0;
|
||||
phy.phy_tail_length = 0;
|
||||
phy.state_control = ppp_phy_interface_state_control;
|
||||
phy.tx = ppp_phy_tx;
|
||||
phy.phy_rx_cb = NULL;
|
||||
phy.phy_tx_done_cb = NULL;
|
||||
|
||||
ppp.set_memory_manager(memory_manager);
|
||||
ppp.set_link_input_cb(mbed::callback(this, &PPPPhy::ppp_phy_rx));
|
||||
if (link_state_change_cb) {
|
||||
ppp.set_link_state_cb(mbed::callback(this, &PPPPhy::link_state_cb));
|
||||
}
|
||||
|
||||
device_id = arm_net_phy_register(&phy);
|
||||
|
||||
if (device_id < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return device_id;
|
||||
}
|
||||
|
||||
void PPPPhy::phy_power_on()
|
||||
{
|
||||
if (!powered_up) {
|
||||
if (!ppp.power_up()) {
|
||||
return;
|
||||
}
|
||||
phy.phy_MTU = get_mtu();
|
||||
powered_up = true;
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
|
||||
void PPPPhy::phy_power_off()
|
||||
{
|
||||
if (powered_up) {
|
||||
ppp.power_down();
|
||||
powered_up = false;
|
||||
}
|
||||
active = false;
|
||||
}
|
||||
|
||||
void PPPPhy::set_link_state_change_cb(link_state_change_cb_t cb)
|
||||
{
|
||||
link_state_change_cb = cb;
|
||||
}
|
||||
|
||||
void PPPPhy::link_state_cb(bool up)
|
||||
{
|
||||
// Read negotiated parameters from PPP
|
||||
if (up) {
|
||||
get_iid64(iid64);
|
||||
}
|
||||
|
||||
// Call upper level callback if set
|
||||
if (link_state_change_cb) {
|
||||
link_state_change_cb(up);
|
||||
}
|
||||
}
|
||||
|
||||
void PPPPhy::get_iid64(uint8_t *iid64)
|
||||
{
|
||||
if (!iid64) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Read link local IPv6 address
|
||||
const nsapi_addr_t *ipv6_ll_addr = ppp.get_ip_address(NSAPI_IPv6);
|
||||
if (ipv6_ll_addr) {
|
||||
memcpy(iid64, &ipv6_ll_addr->bytes[8], 8);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t PPPPhy::get_mtu()
|
||||
{
|
||||
return ppp.get_mtu_size();
|
||||
}
|
||||
|
||||
nsapi_error_t Nanostack::add_ppp_interface(PPP &ppp, bool default_if, Nanostack::PPPInterface **interface_out)
|
||||
{
|
||||
if (!single_phy) {
|
||||
single_phy = new (std::nothrow) PPPPhy(this->memory_manager, ppp);
|
||||
if (!single_phy) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
static Nanostack::PPPInterface *interface = NULL;
|
||||
|
||||
if (interface == NULL) {
|
||||
interface = new (std::nothrow) Nanostack::PPPInterface(*single_phy);
|
||||
if (!interface) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
|
||||
single_phy->set_link_state_change_cb(mbed::callback(interface, &Nanostack::PPPInterface::link_state_changed));
|
||||
}
|
||||
|
||||
interface->initialize();
|
||||
|
||||
single_phy->phy_power_on();
|
||||
|
||||
*interface_out = interface;
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t Nanostack::add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out)
|
||||
{
|
||||
Nanostack::PPPInterface *interface;
|
||||
nsapi_error_t err = add_ppp_interface(ppp, default_if, &interface);
|
||||
*interface_out = interface;
|
||||
return err;
|
||||
}
|
||||
|
||||
nsapi_error_t Nanostack::remove_ppp_interface(OnboardNetworkStack::Interface **interface_out)
|
||||
{
|
||||
single_phy->phy_power_off();
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "WisunInterface.h"
|
||||
#include "NanostackRfPhy.h"
|
||||
#include "include/wisun_tasklet.h"
|
||||
#include "callback_handler.h"
|
||||
#include "NanostackLockGuard.h"
|
||||
|
|
|
@ -335,6 +335,41 @@ int8_t enet_tasklet_network_init(int8_t device_id)
|
|||
return tasklet_data_ptr->network_interface_id;
|
||||
}
|
||||
|
||||
/* For now, to enable to compile without Nanostack interface changes, enables Nanostack PPP
|
||||
interface only if default stack is Nanostack and interface cellular. After Nanostack
|
||||
with updated interface call arm_nwk_interface_ppp_init() is integrated to mbed-os, this
|
||||
flagging can be removed.
|
||||
*/
|
||||
#define NANOSTACK 0x11991199
|
||||
#define CELLULAR 0x22992299
|
||||
#if MBED_CONF_NSAPI_DEFAULT_STACK == NANOSTACK && MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == CELLULAR
|
||||
#define ENABLE_NANOSTACK_PPP
|
||||
#endif
|
||||
#undef NANOSTACK
|
||||
#undef CELLULAR
|
||||
|
||||
int8_t enet_tasklet_ppp_network_init(int8_t device_id)
|
||||
{
|
||||
#ifdef ENABLE_NANOSTACK_PPP
|
||||
if (tasklet_data_ptr->network_interface_id != -1) {
|
||||
tr_debug("Interface already at active state\n");
|
||||
return tasklet_data_ptr->network_interface_id;
|
||||
}
|
||||
if (!eth_mac_api) {
|
||||
eth_mac_api = ethernet_mac_create(device_id);
|
||||
}
|
||||
|
||||
tasklet_data_ptr->network_interface_id = arm_nwk_interface_ppp_init(eth_mac_api, "ppp0");
|
||||
|
||||
tr_debug("interface ID: %d", tasklet_data_ptr->network_interface_id);
|
||||
arm_nwk_interface_configure_ipv6_bootstrap_set(
|
||||
tasklet_data_ptr->network_interface_id, NET_IPV6_BOOTSTRAP_AUTONOMOUS, NULL);
|
||||
return tasklet_data_ptr->network_interface_id;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void enet_tasklet_link_state_changed(bool up)
|
||||
{
|
||||
if (up) {
|
||||
|
|
|
@ -36,6 +36,14 @@ void enet_tasklet_init(void);
|
|||
*/
|
||||
int8_t enet_tasklet_network_init(int8_t device_id);
|
||||
|
||||
/*
|
||||
* \brief Create PPP network interface.
|
||||
*
|
||||
* \param device_id Registered physical device.
|
||||
* \return interface ID used to communication with this interface.
|
||||
*/
|
||||
int8_t enet_tasklet_ppp_network_init(int8_t device_id);
|
||||
|
||||
/*
|
||||
* \brief Connect to Ethernet network.
|
||||
*
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
class LoWPANNDInterface;
|
||||
class ThreadInterface;
|
||||
class WisunInterface;
|
||||
class PPPInterface;
|
||||
|
||||
/* Implement OnboardNetworkStack method */
|
||||
virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out);
|
||||
|
@ -44,6 +45,13 @@ public:
|
|||
/* Local variant with stronger typing and manual address specification */
|
||||
nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, Nanostack::EthernetInterface **interface_out, const uint8_t *mac_addr = NULL);
|
||||
|
||||
virtual nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out);
|
||||
|
||||
/* Local variant with stronger typing and manual address specification */
|
||||
nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, Nanostack::PPPInterface **interface_out);
|
||||
|
||||
nsapi_error_t remove_ppp_interface(OnboardNetworkStack::Interface **interface_out);
|
||||
|
||||
protected:
|
||||
|
||||
Nanostack();
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
#ifndef NANOSTACK_ETHERNET_PHY_H_
|
||||
#define NANOSTACK_ETHERNET_PHY_H_
|
||||
|
||||
#include "NanostackPhy.h"
|
||||
#include "NanostackMACPhy.h"
|
||||
|
||||
/** Ethernet PHY driver class for Nanostack */
|
||||
class NanostackEthernetPhy : public NanostackPhy {
|
||||
class NanostackEthernetPhy : public NanostackMACPhy {
|
||||
};
|
||||
|
||||
#endif /* NANOSTACK_INTERFACE_H_ */
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "LoWPANNDInterface.h"
|
||||
#include "ThreadInterface.h"
|
||||
#include "NanostackEthernetInterface.h"
|
||||
#include "NanostackPPPInterface.h"
|
||||
#include "MeshInterfaceNanostack.h"
|
||||
#include "WisunInterface.h"
|
||||
#endif /* NANOSTACK_INTERFACE_H_ */
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2019, Arm Limited and affiliates.
|
||||
* 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 NANOSTACK_MACPHY_H_
|
||||
#define NANOSTACK_MACPHY_H_
|
||||
|
||||
#include "NanostackPhy.h"
|
||||
|
||||
/** MAC PHY driver class for Nanostack */
|
||||
class NanostackMACPhy : public NanostackPhy {
|
||||
public:
|
||||
/** Read the mac address of this physical interface
|
||||
*
|
||||
* Note - some devices do not have a mac address
|
||||
* in hardware.
|
||||
*
|
||||
* @param mac mac address
|
||||
*/
|
||||
virtual void get_mac_address(uint8_t *mac) = 0;
|
||||
|
||||
/** Set the mac address of this physical interface
|
||||
*
|
||||
* @param mac mac address
|
||||
*/
|
||||
virtual void set_mac_address(uint8_t *mac) = 0;
|
||||
|
||||
/** Provide access to the NanostackMACPhy
|
||||
*
|
||||
* @return NanostackMACPhy
|
||||
*/
|
||||
virtual NanostackMACPhy *nanostack_mac_phy()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* NANOSTACK_MACPHY_H_ */
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2019, Arm Limited and affiliates.
|
||||
* 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 NANOSTACK_PPP_PHY_H_
|
||||
#define NANOSTACK_PPP_PHY_H_
|
||||
|
||||
#include "NanostackPhy.h"
|
||||
/** PPP PHY driver class for Nanostack */
|
||||
class NanostackPPPPhy : public NanostackPhy {
|
||||
public:
|
||||
/** Link state callback function prototype
|
||||
*
|
||||
* @param up link up
|
||||
*/
|
||||
typedef mbed::Callback<void (bool up)> link_state_change_cb_t;
|
||||
|
||||
/** Set link state callback of this physical interface
|
||||
*
|
||||
* @param cb callback
|
||||
*/
|
||||
virtual void set_link_state_change_cb(link_state_change_cb_t cb) = 0;
|
||||
|
||||
/** Read the iid64 address of this physical interface
|
||||
*
|
||||
* @param iid64 iid64 address
|
||||
*/
|
||||
virtual void get_iid64(uint8_t *iid64) = 0;
|
||||
|
||||
/** Read the mtu of this physical interface
|
||||
*
|
||||
* @return mtu
|
||||
*/
|
||||
virtual uint16_t get_mtu() = 0;
|
||||
|
||||
/** Provide access to the NanostackMACPhy
|
||||
*
|
||||
* @return NanostackPPPPhy
|
||||
*/
|
||||
virtual NanostackPPPPhy *nanostack_ppp_phy()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* NANOSTACK_PPP_PHY_H_ */
|
|
@ -18,6 +18,9 @@
|
|||
#ifndef NANOSTACK_PHY_H_
|
||||
#define NANOSTACK_PHY_H_
|
||||
|
||||
class NanostackMACPhy;
|
||||
class NanostackPPPPhy;
|
||||
|
||||
/** PHY driver class for Nanostack */
|
||||
class NanostackPhy {
|
||||
public:
|
||||
|
@ -29,17 +32,25 @@ public:
|
|||
*/
|
||||
virtual int8_t phy_register() = 0;
|
||||
|
||||
/** Read the mac address of this physical interface
|
||||
/** Return pointer to a NanostackMACPhy.
|
||||
*
|
||||
* Note - some devices do not have a mac address
|
||||
* in hardware.
|
||||
* @return Pointer to requested phy type or NULL if this
|
||||
* class doesn't implement the phy.
|
||||
*/
|
||||
virtual void get_mac_address(uint8_t *mac) = 0;
|
||||
virtual NanostackMACPhy *nanostack_mac_phy()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Set the mac address of this physical interface
|
||||
/** Return pointer to a NanostackPPPPhy.
|
||||
*
|
||||
* @return Pointer to requested phy type or NULL if this
|
||||
* class doesn't implement the phy.
|
||||
*/
|
||||
virtual void set_mac_address(uint8_t *mac) = 0;
|
||||
virtual NanostackPPPPhy *nanostack_ppp_phy()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
NanostackPhy() {}
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
#ifndef NANOSTACK_RF_PHY_H_
|
||||
#define NANOSTACK_RF_PHY_H_
|
||||
|
||||
#include "NanostackPhy.h"
|
||||
#include "NanostackMACPhy.h"
|
||||
|
||||
/** Radio PHY driver class for Nanostack */
|
||||
class NanostackRfPhy : public NanostackPhy {
|
||||
class NanostackRfPhy : public NanostackMACPhy {
|
||||
public:
|
||||
|
||||
/** Return the default on-board NanostackRfPhy
|
||||
|
|
|
@ -95,6 +95,7 @@ typedef enum phy_link_type_e {
|
|||
PHY_LINK_15_4_SUBGHZ_TYPE, /**< Standard 802.15.4 subGHz radio 868 /915MHz. */
|
||||
PHY_LINK_TUN, /**< Tunnel interface for Linux TUN, RF network driver over serial bus or just basic application to application data flow. */
|
||||
PHY_LINK_SLIP, /**< Generic SLIP driver which just forward SLIP payload */
|
||||
PHY_LINK_PPP, /**< PPP interface */
|
||||
} phy_link_type_e;
|
||||
|
||||
/** Data layers */
|
||||
|
|
|
@ -36,6 +36,7 @@ class WiFiInterface;
|
|||
class MeshInterface;
|
||||
class CellularInterface;
|
||||
class EMACInterface;
|
||||
class PPPInterface;
|
||||
|
||||
/** Common interface that is shared between network devices.
|
||||
*
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "NetworkStack.h"
|
||||
#include "EMAC.h"
|
||||
#include "L3IP.h"
|
||||
#include "PPP.h"
|
||||
|
||||
/**
|
||||
* mbed OS API for onboard IP stack abstraction
|
||||
|
@ -165,11 +166,21 @@ public:
|
|||
return NSAPI_ERROR_OK;
|
||||
};
|
||||
|
||||
virtual nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, Interface **interface_out)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
};
|
||||
|
||||
virtual nsapi_error_t remove_l3ip_interface(Interface **interface_out)
|
||||
{
|
||||
return NSAPI_ERROR_OK;
|
||||
};
|
||||
|
||||
virtual nsapi_error_t remove_ppp_interface(Interface **interface_out)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
};
|
||||
|
||||
virtual void set_default_interface(OnboardNetworkStack::Interface *interface)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* 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_H_
|
||||
#define PPP_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "Callback.h"
|
||||
#include "FileHandle.h"
|
||||
#include "NetStackMemoryManager.h"
|
||||
|
||||
class PPP {
|
||||
public:
|
||||
|
||||
/** Return the default on-board PPP
|
||||
*
|
||||
* Returns the default on-board PPP - this will be target-specific, and
|
||||
* may not be available on all targets.
|
||||
*/
|
||||
static PPP &get_default_instance();
|
||||
|
||||
virtual ~PPP() {};
|
||||
|
||||
/**
|
||||
* 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<void (net_stack_mem_buf_t *buf)> 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<void (bool up)> ppp_link_state_change_cb_t;
|
||||
|
||||
/**
|
||||
* Return maximum transmission unit
|
||||
*
|
||||
* @return MTU in bytes
|
||||
*/
|
||||
virtual uint32_t get_mtu_size() = 0;
|
||||
|
||||
/**
|
||||
* Gets memory buffer alignment preference
|
||||
*
|
||||
* Gets preferred memory buffer alignment of the cellular device.
|
||||
* @return Memory alignment requirement in bytes
|
||||
*/
|
||||
virtual uint32_t get_align_preference() const = 0;
|
||||
|
||||
/**
|
||||
* 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 = 0;
|
||||
|
||||
/**
|
||||
* Sends the packet over the link
|
||||
*
|
||||
* That cannot be called from an interrupt context.
|
||||
*
|
||||
* @param buf Packet to be sent
|
||||
* @return True if the packet was sent, false otherwise
|
||||
*/
|
||||
virtual bool link_out(net_stack_mem_buf_t *buf, nsapi_ip_stack_t ip_stack) = 0;
|
||||
|
||||
/**
|
||||
* Initializes the PPP
|
||||
*
|
||||
* @return True on success, False in case of an error.
|
||||
*/
|
||||
virtual bool power_up() = 0;
|
||||
|
||||
/**
|
||||
* Deinitializes the PPP
|
||||
*
|
||||
*/
|
||||
virtual void power_down() = 0;
|
||||
|
||||
/**
|
||||
* 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) = 0;
|
||||
|
||||
/**
|
||||
* 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) = 0;
|
||||
|
||||
/** 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) = 0;
|
||||
|
||||
/** Sets file stream used to communicate with modem
|
||||
*
|
||||
* @param stream Pointer to file handle
|
||||
*/
|
||||
virtual void set_stream(mbed::FileHandle *stream) = 0;
|
||||
|
||||
/** Sets IP protocol versions of IP stack
|
||||
*
|
||||
* @param ip_stack IP protocol version
|
||||
*/
|
||||
virtual void set_ip_stack(nsapi_ip_stack_t ip_stack) = 0;
|
||||
|
||||
/** 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) = 0;
|
||||
|
||||
/** Gets local IP address
|
||||
*
|
||||
* @param version IP address version
|
||||
* @return IP address
|
||||
*/
|
||||
virtual const nsapi_addr_t *get_ip_address(nsapi_version_t version) = 0;
|
||||
|
||||
/** 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() = 0;
|
||||
|
||||
/** Get the local gateway.
|
||||
*
|
||||
* @return Local gateway or null if no network mask has been received.
|
||||
*/
|
||||
virtual const nsapi_addr_t *get_gateway() = 0;
|
||||
|
||||
/** Gets DNS server address
|
||||
*
|
||||
* @param index Server index
|
||||
*/
|
||||
virtual const nsapi_addr_t *get_dns_server(uint8_t index) = 0;
|
||||
};
|
||||
|
||||
#endif /* PPP_H_ */
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* 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 "PPPInterface.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
/* Interface implementation */
|
||||
PPPInterface::PPPInterface(PPP &ppp, OnboardNetworkStack &stack) :
|
||||
_ppp(ppp),
|
||||
_stack(stack),
|
||||
_interface(NULL),
|
||||
_blocking(true),
|
||||
_ip_address(),
|
||||
_netmask(),
|
||||
_gateway(),
|
||||
_stream(NULL),
|
||||
_ip_stack(DEFAULT_STACK),
|
||||
_uname(NULL),
|
||||
_password(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
PPPInterface::~PPPInterface()
|
||||
{
|
||||
_stack.remove_ppp_interface(&_interface);
|
||||
}
|
||||
|
||||
nsapi_error_t PPPInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
|
||||
{
|
||||
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
|
||||
_ip_address[sizeof(_ip_address) - 1] = '\0';
|
||||
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
|
||||
_netmask[sizeof(_netmask) - 1] = '\0';
|
||||
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
|
||||
_gateway[sizeof(_gateway) - 1] = '\0';
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t PPPInterface::connect()
|
||||
{
|
||||
_ppp.set_stream(_stream);
|
||||
_ppp.set_ip_stack(_ip_stack);
|
||||
_ppp.set_credentials(_uname, _password);
|
||||
|
||||
if (!_interface) {
|
||||
nsapi_error_t err = _stack.add_ppp_interface(_ppp, true, &_interface);
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
_interface = NULL;
|
||||
return err;
|
||||
}
|
||||
_interface->attach(_connection_status_cb);
|
||||
}
|
||||
|
||||
return _interface->bringup(false,
|
||||
_ip_address[0] ? _ip_address : 0,
|
||||
_netmask[0] ? _netmask : 0,
|
||||
_gateway[0] ? _gateway : 0,
|
||||
_ip_stack,
|
||||
_blocking);
|
||||
}
|
||||
|
||||
nsapi_error_t PPPInterface::disconnect()
|
||||
{
|
||||
if (_interface) {
|
||||
return _interface->bringdown();
|
||||
}
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
const char *PPPInterface::get_ip_address()
|
||||
{
|
||||
if (_interface && _interface->get_ip_address(_ip_address, sizeof(_ip_address))) {
|
||||
return _ip_address;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *PPPInterface::get_netmask()
|
||||
{
|
||||
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
|
||||
return _netmask;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *PPPInterface::get_gateway()
|
||||
{
|
||||
if (_interface && _interface->get_gateway(_gateway, sizeof(_gateway))) {
|
||||
return _gateway;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *PPPInterface::get_interface_name(char *interface_name)
|
||||
{
|
||||
if (_interface) {
|
||||
return _interface->get_interface_name(interface_name);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PPPInterface::set_as_default()
|
||||
{
|
||||
if (_interface) {
|
||||
_stack.set_default_interface(_interface);
|
||||
}
|
||||
}
|
||||
|
||||
void PPPInterface::set_stream(mbed::FileHandle *stream)
|
||||
{
|
||||
_stream = stream;
|
||||
}
|
||||
|
||||
void PPPInterface::set_ip_stack(nsapi_ip_stack_t ip_stack)
|
||||
{
|
||||
|
||||
_ip_stack = ip_stack;
|
||||
}
|
||||
|
||||
void PPPInterface::set_credentials(const char *uname, const char *password)
|
||||
{
|
||||
_uname = uname;
|
||||
_password = password;
|
||||
}
|
||||
|
||||
NetworkStack *PPPInterface::get_stack()
|
||||
{
|
||||
return &_stack;
|
||||
}
|
||||
|
||||
void PPPInterface::attach(
|
||||
mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
||||
{
|
||||
_connection_status_cb = status_cb;
|
||||
if (_interface) {
|
||||
_interface->attach(status_cb);
|
||||
}
|
||||
}
|
||||
|
||||
nsapi_connection_status_t PPPInterface::get_connection_status() const
|
||||
{
|
||||
if (_interface) {
|
||||
return _interface->get_connection_status();
|
||||
} else {
|
||||
return NSAPI_STATUS_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
nsapi_error_t PPPInterface::set_blocking(bool blocking)
|
||||
{
|
||||
_blocking = blocking;
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* 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_INTERFACE_H
|
||||
#define PPP_INTERFACE_H
|
||||
|
||||
#include "nsapi.h"
|
||||
#include "OnboardNetworkStack.h"
|
||||
#include "NetworkInterface.h"
|
||||
#include "PPP.h"
|
||||
|
||||
|
||||
/** PPPInterface class
|
||||
* Implementation of the NetworkInterface for an PPP-service
|
||||
*
|
||||
* This class provides the necessary glue logic to create a NetworkInterface
|
||||
* based on an PPP and an OnboardNetworkStack.
|
||||
*
|
||||
*/
|
||||
class PPPInterface : public virtual NetworkInterface {
|
||||
public:
|
||||
/** Create an PPP-based network interface.
|
||||
*
|
||||
* The default arguments obtain the default PPP, which will be target-
|
||||
* dependent (and the target may have some JSON option to choose which
|
||||
* is the default, if there are multiple). The default stack is configured
|
||||
* by JSON option nsapi.default-stack.
|
||||
*
|
||||
* Due to inability to return errors from the constructor, no real
|
||||
* work is done until the first call to connect().
|
||||
*
|
||||
* @param ppp Reference to PPP to use
|
||||
* @param stack Reference to onboard-network stack to use
|
||||
*/
|
||||
PPPInterface(PPP &ppp = PPP::get_default_instance(),
|
||||
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
|
||||
virtual ~PPPInterface();
|
||||
|
||||
/** Set a static IP address
|
||||
*
|
||||
* Configures this network interface to use a static IP address.
|
||||
* Implicitly disables DHCP, which can be enabled in set_dhcp.
|
||||
* Requires that the network is disconnected.
|
||||
*
|
||||
* @param ip_address Null-terminated representation of the local IP address
|
||||
* @param netmask Null-terminated representation of the local network mask
|
||||
* @param gateway Null-terminated representation of the local gateway
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
|
||||
|
||||
/** Start the interface
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
virtual nsapi_error_t connect();
|
||||
|
||||
/** Stop the interface
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
virtual nsapi_error_t disconnect();
|
||||
|
||||
/** Get the local IP address
|
||||
*
|
||||
* @return Null-terminated representation of the local IP address
|
||||
* or null if no IP address has been received
|
||||
*/
|
||||
virtual const char *get_ip_address();
|
||||
|
||||
/** Get the local network mask
|
||||
*
|
||||
* @return Null-terminated representation of the local network mask
|
||||
* or null if no network mask has been received
|
||||
*/
|
||||
virtual const char *get_netmask();
|
||||
|
||||
/** Get the local gateways
|
||||
*
|
||||
* @return Null-terminated representation of the local gateway
|
||||
* or null if no network mask has been received
|
||||
*/
|
||||
virtual const char *get_gateway();
|
||||
|
||||
/** Get the network interface name
|
||||
*
|
||||
* @return Null-terminated representation of the network interface name
|
||||
* or null if interface not exists
|
||||
*/
|
||||
virtual char *get_interface_name(char *interface_name);
|
||||
|
||||
/** Set the network interface as default one
|
||||
*/
|
||||
virtual void set_as_default();
|
||||
|
||||
/** Register callback for status reporting
|
||||
*
|
||||
* @param status_cb The callback for status changes
|
||||
*/
|
||||
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
||||
|
||||
/** Get the connection status
|
||||
*
|
||||
* @return The connection status according to nsapi_connection_status_t
|
||||
*/
|
||||
virtual nsapi_connection_status_t get_connection_status() const;
|
||||
|
||||
/** Set blocking status of connect() which by default should be blocking
|
||||
*
|
||||
* @param blocking true if connect is blocking
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual nsapi_error_t set_blocking(bool blocking);
|
||||
|
||||
/** 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);
|
||||
|
||||
/** Provide access to the PPP
|
||||
*
|
||||
* This should be used with care - normally the network stack would
|
||||
* control the PPP, so manipulating the PPP while the stack
|
||||
* is also using it (ie after connect) will likely cause problems.
|
||||
*
|
||||
* @return Reference to the PPP in use
|
||||
*/
|
||||
PPP &getppp() const
|
||||
{
|
||||
return _ppp;
|
||||
}
|
||||
|
||||
virtual PPPInterface *pppInterface()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Provide access to the underlying stack
|
||||
*
|
||||
* @return The underlying network stack
|
||||
*/
|
||||
virtual NetworkStack *get_stack();
|
||||
|
||||
PPP &_ppp;
|
||||
OnboardNetworkStack &_stack;
|
||||
OnboardNetworkStack::Interface *_interface;
|
||||
bool _blocking;
|
||||
char _ip_address[NSAPI_IPv6_SIZE];
|
||||
char _netmask[NSAPI_IPv4_SIZE];
|
||||
char _gateway[NSAPI_IPv4_SIZE];
|
||||
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
|
||||
|
||||
mbed::FileHandle *_stream;
|
||||
nsapi_ip_stack_t _ip_stack;
|
||||
const char *_uname;
|
||||
const char *_password;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -30,8 +30,8 @@
|
|||
* $Id: ccp.h,v 1.12 2004/11/04 10:02:26 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef CCP_H
|
||||
#define CCP_H
|
|
@ -28,8 +28,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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;
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef CHAP_H
|
||||
#define CHAP_H
|
|
@ -30,8 +30,8 @@
|
|||
* $Id: chap_ms.h,v 1.13 2004/11/15 22:13:26 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef CHAPMS_INCLUDE
|
||||
#define CHAPMS_INCLUDE
|
|
@ -20,8 +20,8 @@
|
|||
* $Id: eap.h,v 1.2 2003/06/11 23:56:26 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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
|
|
@ -31,8 +31,8 @@
|
|||
* $Id: ecp.h,v 1.2 2003/01/10 07:12:36 fcusack Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef ECP_H
|
||||
#define ECP_H
|
|
@ -35,8 +35,8 @@
|
|||
* $Id: eui64.h,v 1.6 2002/12/04 23:03:32 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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)
|
||||
|
|
@ -42,8 +42,8 @@
|
|||
* $Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef FSM_H
|
||||
#define FSM_H
|
|
@ -42,8 +42,8 @@
|
|||
* $Id: ipcp.h,v 1.14 2002/12/04 23:03:32 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV4_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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;
|
||||
|
|
@ -138,8 +138,8 @@
|
|||
* $Id: ipv6cp.h,v 1.7 2002/12/04 23:03:32 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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
|
|
@ -42,8 +42,8 @@
|
|||
* $Id: lcp.h,v 1.20 2004/11/14 22:53:42 carlsonj Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef LCP_H
|
||||
#define LCP_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 <glanca@gesn.com>, Global Election Systems Inc.
|
||||
* Extracted from avos.
|
||||
*
|
||||
* /@endcode
|
||||
*****************************************************************************/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef MAGIC_H
|
||||
#define MAGIC_H
|
|
@ -33,13 +33,13 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef MPPE_H
|
||||
#define MPPE_H
|
||||
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "pppcrypt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -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 */
|
|
@ -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 "netif/ppp/ppp_opts.h"
|
||||
#if LWIP_INCLUDED_POLARSSL_ARC4
|
||||
#include "ppp_opts.h"
|
||||
#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 */
|
|
@ -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 "netif/ppp/ppp_opts.h"
|
||||
#if LWIP_INCLUDED_POLARSSL_DES
|
||||
#include "ppp_opts.h"
|
||||
#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 */
|
|
@ -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 "netif/ppp/ppp_opts.h"
|
||||
#if LWIP_INCLUDED_POLARSSL_MD4
|
||||
#include "ppp_opts.h"
|
||||
#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 */
|
|
@ -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 "netif/ppp/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 */
|
|
@ -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 "netif/ppp/ppp_opts.h"
|
||||
#if LWIP_INCLUDED_POLARSSL_SHA1
|
||||
#include "ppp_opts.h"
|
||||
#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 */
|
|
@ -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 <glanca@gesn.com>, Global Election Systems Inc.
|
||||
* Original derived from BSD codes.
|
||||
*
|
||||
* /@endcode
|
||||
*****************************************************************************/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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);
|
||||
|
|
@ -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 <glanca@gesn.com>, 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 "netif/ppp/ppp_opts.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 <string.h>
|
||||
#include <stdlib.h> /* 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 */
|
|
@ -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 */
|
|
@ -25,19 +25,18 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef LWIP_PPPAPI_H
|
||||
#define LWIP_PPPAPI_H
|
||||
#ifndef PPPAPI_H
|
||||
#define PPPAPI_H
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#include "ppp_opts.h"
|
||||
|
||||
#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
|
||||
#if PPP_API
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "netif/ppp/ppp.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include "ppp.h"
|
||||
#if PPPOS_SUPPORT
|
||||
#include "netif/ppp/pppos.h"
|
||||
#include "pppos.h"
|
||||
#endif /* PPPOS_SUPPORT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -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 */
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
|
||||
*
|
||||
* Extracted from chap_ms.c by James Carlson.
|
||||
*
|
||||
* Copyright (c) 1995 Eric Rosenquist. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The name(s) of the authors of this software must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission.
|
||||
*
|
||||
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "ppp_opts.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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Map hashes and ciphers functions to PolarSSL
|
||||
*/
|
||||
#if !PPP_USE_EXTERNAL_MBEDTLS
|
||||
|
||||
#include "polarssl/md4.h"
|
||||
#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 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 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 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 ARC4_context arc4_context
|
||||
#define ARC4_init(context)
|
||||
#define ARC4_setup arc4_setup
|
||||
#define ARC4_crypt arc4_crypt
|
||||
#define ARC4_free(context)
|
||||
|
||||
#endif /* !PPP_USE_EXTERNAL_MBEDTLS */
|
||||
|
||||
/*
|
||||
* Map hashes and ciphers functions to mbed TLS
|
||||
*/
|
||||
#if PPP_USE_EXTERNAL_MBEDTLS
|
||||
|
||||
#include "mbedtls/md5.h"
|
||||
|
||||
#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 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 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 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
|
||||
|
||||
#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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PPPCRYPT_H */
|
||||
|
||||
#endif /* PPP_SUPPORT */
|
|
@ -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 <lancasterg@acm.org>, Global Election Systems Inc.
|
||||
* Original.
|
||||
*
|
||||
* /@endcode
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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 */
|
||||
|
|
@ -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 <marc@mbsi.ca>
|
||||
* Ported to lwIP.
|
||||
*
|
||||
* /@endcode
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
|
@ -67,14 +71,13 @@
|
|||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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);
|
|
@ -31,8 +31,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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 */
|
|
@ -31,14 +31,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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);
|
|
@ -42,8 +42,8 @@
|
|||
* $Id: upap.h,v 1.8 2002/12/04 23:03:33 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && PAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#ifndef UPAP_H
|
||||
#define UPAP_H
|
|
@ -22,15 +22,12 @@
|
|||
* - Initial distribution.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && VJ_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"name": "ppp",
|
||||
"macros": ["NSAPI_PPP_AVAILABLE=(MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED)"],
|
||||
"config": {
|
||||
"enabled": {
|
||||
"help": "Enable support for PPP interfaces",
|
||||
"value": false
|
||||
},
|
||||
"ipv4-enabled": {
|
||||
"help": "Enable support for ipv4 PPP interface",
|
||||
"value": true
|
||||
},
|
||||
"ipv6-enabled": {
|
||||
"help": "Enable support for ipv6 PPP interface",
|
||||
"value": false
|
||||
},
|
||||
"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": 816
|
||||
},
|
||||
"mbed-event-queue": {
|
||||
"help": "Use mbed event queue instead of PPP thread",
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
"target_overrides": {
|
||||
"RZ_A1_EMAC": {
|
||||
"thread-stacksize": 896
|
||||
},
|
||||
"CYW943012P6EVB_01": {
|
||||
"thread-stacksize": 896
|
||||
},
|
||||
"CY8CPROTO_062_4343W": {
|
||||
"thread-stacksize": 896
|
||||
},
|
||||
"CY8CKIT_062_WIFI_BT": {
|
||||
"thread-stacksize": 896
|
||||
},
|
||||
"CY8CKIT_062S2_43012": {
|
||||
"thread-stacksize": 896
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,10 +38,10 @@
|
|||
* http://groups.google.com/group/sci.crypt/msg/10a300c9d21afca0
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_ARC4
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_ARC4
|
||||
|
||||
#include "netif/ppp/polarssl/arc4.h"
|
||||
#include "polarssl/arc4.h"
|
||||
/*
|
||||
* ARC4 key schedule
|
||||
*/
|
||||
|
@ -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 */
|
|
@ -39,10 +39,10 @@
|
|||
* http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_DES
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_DES
|
||||
|
||||
#include "netif/ppp/polarssl/des.h"
|
||||
#include "polarssl/des.h"
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
|
@ -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 */
|
|
@ -39,10 +39,10 @@
|
|||
* http://www.ietf.org/rfc/rfc1320.txt
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD4
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_MD4
|
||||
|
||||
#include "netif/ppp/polarssl/md4.h"
|
||||
#include "polarssl/md4.h"
|
||||
|
||||
#include <string.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 */
|
|
@ -38,12 +38,16 @@
|
|||
* http://www.ietf.org/rfc/rfc1321.txt
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_MD5
|
||||
|
||||
#include "netif/ppp/polarssl/md5.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "polarssl/md5.h"
|
||||
|
||||
/**
|
||||
* 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 */
|
|
@ -38,10 +38,10 @@
|
|||
* http://www.itl.nist.gov/fipspubs/fip180-1.htm
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && LWIP_INCLUDED_POLARSSL_SHA1
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_INCLUDED_POLARSSL_SHA1
|
||||
|
||||
#include "netif/ppp/polarssl/sha1.h"
|
||||
#include "polarssl/sha1.h"
|
||||
|
||||
#include <string.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 */
|
|
@ -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 <errno.h>
|
||||
#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<void(nsapi_event_t, intptr_t)> 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
|
|
@ -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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#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<char *>(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<char *>(buffer));
|
||||
#endif
|
||||
|
||||
pppos_input(static_cast<ppp_pcb *>(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_pcb *>(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<ppp_service *>(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<netif *>(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_pcb *>(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_pcb *>(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_pcb *>(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<netif *>(malloc(sizeof(netif)));
|
||||
if (ppp_service_netif) {
|
||||
memset(ppp_service_netif, 0, sizeof(netif));
|
||||
ppp_service_netif->service_ptr = static_cast<void *>(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<netif *>(ppp_service_netif);
|
||||
|
||||
if (ppp_service_terminating) {
|
||||
memory_manager->free(buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
struct pbuf *p = static_cast<struct pbuf *>(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<netif *>(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<netif *>(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 ------------------------------ */
|
||||
|
|
@ -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 <stdbool.h>
|
||||
#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<void (net_stack_mem_buf_t *buf)> 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<void (bool up)> 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 */
|
|
@ -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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#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<PlatformMutex> 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<ppp_service *>(inp->service_ptr);
|
||||
void *buffer = ppp_memory_buffer_convert_from(p);
|
||||
ppp_service_ptr->link_input(static_cast<net_stack_mem_buf_t *>(buffer));
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void ppp_set_link_up(struct netif *netif)
|
||||
{
|
||||
ppp_service *ppp_service_ptr = static_cast<ppp_service *>(netif->service_ptr);
|
||||
ppp_service_ptr->link_state(true);
|
||||
}
|
||||
|
||||
void ppp_set_link_down(struct netif *netif)
|
||||
{
|
||||
ppp_service *ppp_service_ptr = static_cast<ppp_service *>(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<ppp_service *>(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<NetStackMemoryManager *>(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<uint8_t *>(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<NetStackMemoryManager *>(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<NetStackMemoryManager *>(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<NetStackMemoryManager *>(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<NetStackMemoryManager *>(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<NetStackMemoryManager *>(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<uint8_t *>(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<uint8_t *>(buffer->payload) - static_cast<uint8_t *>(buffer->payload_start);
|
||||
|
||||
if (payload_headroom_len < header_len) {
|
||||
return 1; // failure
|
||||
}
|
||||
|
||||
buffer->payload = static_cast<uint8_t *>(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<ppp_service *>(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<ppp_service *>(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<int>(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<ppp_service *>(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<ppp_sys_timeout_t *>(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<void *>(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
|
|
@ -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 <stdint.h>
|
||||
|
||||
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 <inttypes.h>
|
||||
#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 <ctype.h>
|
||||
#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 */
|
|
@ -68,8 +68,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include <stdio.h>
|
||||
|
@ -89,10 +89,6 @@
|
|||
#include <lastlog.h>
|
||||
#endif
|
||||
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#ifdef HAS_SHADOW
|
||||
#include <shadow.h>
|
||||
#ifndef PW_PPP
|
||||
|
@ -103,28 +99,28 @@
|
|||
#include <time.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/lcp.h"
|
||||
#include "fsm.h"
|
||||
#include "lcp.h"
|
||||
#if CCP_SUPPORT
|
||||
#include "netif/ppp/ccp.h"
|
||||
#include "ccp.h"
|
||||
#endif /* CCP_SUPPORT */
|
||||
#if ECP_SUPPORT
|
||||
#include "netif/ppp/ecp.h"
|
||||
#include "ecp.h"
|
||||
#endif /* ECP_SUPPORT */
|
||||
#include "netif/ppp/ipcp.h"
|
||||
#include "ipcp.h"
|
||||
#if PAP_SUPPORT
|
||||
#include "netif/ppp/upap.h"
|
||||
#include "upap.h"
|
||||
#endif /* PAP_SUPPORT */
|
||||
#if CHAP_SUPPORT
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "chap-new.h"
|
||||
#endif /* CHAP_SUPPORT */
|
||||
#if EAP_SUPPORT
|
||||
#include "netif/ppp/eap.h"
|
||||
#include "eap.h"
|
||||
#endif /* EAP_SUPPORT */
|
||||
#if CBCP_SUPPORT
|
||||
#include "netif/ppp/cbcp.h"
|
||||
#include "cbcp.h"
|
||||
#endif
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
|
@ -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);
|
||||
}
|
|
@ -28,20 +28,20 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ccp.h"
|
||||
#include "fsm.h"
|
||||
#include "ccp.h"
|
||||
|
||||
#if MPPE_SUPPORT
|
||||
#include "netif/ppp/lcp.h" /* lcp_close(), lcp_fsm */
|
||||
#include "netif/ppp/mppe.h" /* mppe_init() */
|
||||
#include "lcp.h" /* lcp_close(), lcp_fsm */
|
||||
#include "mppe.h" /* mppe_init() */
|
||||
#endif /* MPPE_SUPPORT */
|
||||
|
||||
/*
|
||||
|
@ -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) {
|
|
@ -28,20 +28,20 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "netif/ppp/chap-md5.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "chap-new.h"
|
||||
#include "chap-md5.h"
|
||||
#include "magic.h"
|
||||
#include "pppcrypt.h"
|
||||
|
||||
#define MD5_HASH_SIZE 16
|
||||
#define MD5_MIN_CHALLENGE 17
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
@ -28,26 +28,26 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include "session.h"
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "netif/ppp/chap-md5.h"
|
||||
#include "chap-new.h"
|
||||
#include "chap-md5.h"
|
||||
#if MSCHAP_SUPPORT
|
||||
#include "netif/ppp/chap_ms.h"
|
||||
#include "chap_ms.h"
|
||||
#endif
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "magic.h"
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
/* Hook for a plugin to validate CHAP challenge */
|
||||
|
@ -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,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
MEMCPY(p->payload, pcb->chap_server.challenge, pcb->chap_server.challenge_pktlen);
|
||||
|
@ -345,11 +345,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -441,11 +441,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -490,14 +490,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 +605,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);
|
|
@ -74,8 +74,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include <stdio.h>
|
||||
|
@ -87,14 +87,14 @@
|
|||
#include <unistd.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "netif/ppp/chap_ms.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "chap-new.h"
|
||||
#include "chap_ms.h"
|
||||
#include "pppcrypt.h"
|
||||
#include "magic.h"
|
||||
#if MPPE_SUPPORT
|
||||
#include "netif/ppp/mppe.h" /* For mppe_sha1_pad*, mppe_set_key() */
|
||||
#include "mppe.h" /* For mppe_sha1_pad*, mppe_set_key() */
|
||||
#endif /* MPPE_SUPPORT */
|
||||
|
||||
#define SHA1_SIGNATURE_SIZE 20
|
||||
|
@ -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);
|
|
@ -28,8 +28,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && DEMAND_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && DEMAND_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -52,11 +52,11 @@
|
|||
#include <pcap-bpf.h>
|
||||
#endif
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ipcp.h"
|
||||
#include "netif/ppp/lcp.h"
|
||||
#include "fsm.h"
|
||||
#include "ipcp.h"
|
||||
#include "lcp.h"
|
||||
|
||||
char *frame;
|
||||
int framelen;
|
||||
|
@ -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");
|
|
@ -43,13 +43,13 @@
|
|||
* Based on draft-ietf-pppext-eap-srp-03.txt.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/eap.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "ppp_impl.h"
|
||||
#include "eap.h"
|
||||
#include "magic.h"
|
||||
#include "pppcrypt.h"
|
||||
|
||||
#ifdef USE_SRP
|
||||
#include <t_pwd.h>
|
||||
|
@ -251,11 +251,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -282,11 +282,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -683,11 +683,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1018,11 +1018,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1052,11 +1052,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1097,11 +1097,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1139,11 +1139,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1170,11 +1170,11 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1314,7 +1314,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 +1443,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 +1728,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 +1871,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 +2015,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 +2041,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 +2146,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 +2160,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 +2298,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 +2321,7 @@ static int eap_printpkt(const u_char *inp, int inlen, void (*printer) (void *, c
|
|||
GETCHAR(rtype, inp);
|
||||
len--;
|
||||
printer(arg, " <Suggested-type %02X", rtype);
|
||||
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]);
|
||||
printer(arg, ">");
|
||||
break;
|
|
@ -35,11 +35,11 @@
|
|||
* $Id: eui64.c,v 1.6 2002/12/04 23:03:32 paulus Exp $
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/eui64.h"
|
||||
#include "ppp_impl.h"
|
||||
#include "eui64.h"
|
||||
|
||||
/*
|
||||
* eui64_ntoa - Make an ascii representation of an interface identifier
|
|
@ -40,8 +40,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
/*
|
||||
* @todo:
|
||||
|
@ -55,9 +55,9 @@
|
|||
#include <sys/types.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "fsm.h"
|
||||
|
||||
static void fsm_timeout (void *);
|
||||
static void fsm_rconfreq(fsm *f, u_char id, u_char *inp, int len);
|
||||
|
@ -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,24 @@ 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);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_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 +779,16 @@ 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);
|
||||
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
pbuf_free(p);
|
||||
ppp_memory_buffer_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);
|
|
@ -40,8 +40,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV4_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.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 <arpa/inet.h>
|
||||
#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:
|
|
@ -147,8 +147,8 @@
|
|||
* interface up / set address.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
#include <stdio.h>
|
||||
|
@ -162,11 +162,11 @@
|
|||
#include <arpa/inet.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ipcp.h"
|
||||
#include "netif/ppp/ipv6cp.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "ppp_impl.h"
|
||||
#include "fsm.h"
|
||||
#include "ipcp.h"
|
||||
#include "ipv6cp.h"
|
||||
#include "magic.h"
|
||||
|
||||
/* global vars */
|
||||
#if 0 /* UNUSED */
|
||||
|
@ -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);
|
|
@ -40,8 +40,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
/*
|
||||
* @todo:
|
||||
|
@ -53,14 +53,14 @@
|
|||
#include <stdlib.h>
|
||||
#endif /* UNUSED */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/lcp.h"
|
||||
#include "fsm.h"
|
||||
#include "lcp.h"
|
||||
#if CHAP_SUPPORT
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "chap-new.h"
|
||||
#endif /* CHAP_SUPPORT */
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "magic.h"
|
||||
|
||||
/*
|
||||
* When the link comes up we want to be able to wait for a short while,
|
||||
|
@ -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,19 @@ 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);
|
||||
if(NULL == nakp)
|
||||
return 0;
|
||||
if(nakp->tot_len != nakp->len) {
|
||||
pbuf_free(nakp);
|
||||
ppp_memory_buffer_free(nakp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nakoutp = (u_char*)nakp->payload;
|
||||
|
||||
rejp = inp;
|
||||
while (l) {
|
||||
orc = CONFACK; /* Assume success */
|
||||
|
@ -2268,7 +2271,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 +2282,7 @@ endswitch:
|
|||
break;
|
||||
}
|
||||
|
||||
pbuf_free(nakp);
|
||||
ppp_memory_buffer_free(nakp);
|
||||
LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
|
||||
return (rc); /* Return final code */
|
||||
}
|
||||
|
@ -2310,11 +2314,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 +2401,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 +2691,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) {
|
|
@ -72,15 +72,15 @@
|
|||
* Extracted from avos.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "ppp_impl.h"
|
||||
#include "magic.h"
|
||||
|
||||
#if PPP_MD5_RANDM /* Using MD5 for better randomness if enabled */
|
||||
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "pppcrypt.h"
|
||||
|
||||
#define MD5_HASH_SIZE 16
|
||||
static char magic_randpool[MD5_HASH_SIZE]; /* Pool of randomness. */
|
||||
|
@ -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;
|
|
@ -23,18 +23,16 @@
|
|||
* deprecated in 2.6
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "lwip/err.h"
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/ccp.h"
|
||||
#include "netif/ppp/mppe.h"
|
||||
#include "netif/ppp/pppdebug.h"
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "ppp_impl.h"
|
||||
#include "ccp.h"
|
||||
#include "mppe.h"
|
||||
#include "pppdebug.h"
|
||||
#include "pppcrypt.h"
|
||||
|
||||
#define SHA1_SIGNATURE_SIZE 20
|
||||
|
||||
|
@ -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,12 @@ 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);
|
||||
if (!np) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
@ -210,7 +208,7 @@ 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);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -250,7 +248,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 +265,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 +384,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;
|
||||
}
|
|
@ -28,8 +28,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && defined(HAVE_MULTILINK) /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && defined(HAVE_MULTILINK) /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
/* Multilink support
|
||||
*
|
||||
|
@ -49,11 +49,11 @@
|
|||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/lcp.h"
|
||||
#include "netif/ppp/tdb.h"
|
||||
#include "fsm.h"
|
||||
#include "lcp.h"
|
||||
#include "tdb.h"
|
||||
|
||||
bool endpoint_specified; /* user gave explicit endpoint discriminator */
|
||||
char *bundle_id; /* identifier for our bundle */
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
@ -85,54 +85,42 @@
|
|||
* @verbinclude "ppp.txt"
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.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"
|
||||
#include "ppp_impl.h"
|
||||
#include "pppos.h"
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "netif/ppp/pppos.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/lcp.h"
|
||||
#include "netif/ppp/magic.h"
|
||||
#include "fsm.h"
|
||||
#include "lcp.h"
|
||||
#include "magic.h"
|
||||
|
||||
#if PAP_SUPPORT
|
||||
#include "netif/ppp/upap.h"
|
||||
#include "upap.h"
|
||||
#endif /* PAP_SUPPORT */
|
||||
#if CHAP_SUPPORT
|
||||
#include "netif/ppp/chap-new.h"
|
||||
#include "chap-new.h"
|
||||
#endif /* CHAP_SUPPORT */
|
||||
#if EAP_SUPPORT
|
||||
#include "netif/ppp/eap.h"
|
||||
#include "eap.h"
|
||||
#endif /* EAP_SUPPORT */
|
||||
#if CCP_SUPPORT
|
||||
#include "netif/ppp/ccp.h"
|
||||
#include "ccp.h"
|
||||
#endif /* CCP_SUPPORT */
|
||||
#if MPPE_SUPPORT
|
||||
#include "netif/ppp/mppe.h"
|
||||
#include "mppe.h"
|
||||
#endif /* MPPE_SUPPORT */
|
||||
#if ECP_SUPPORT
|
||||
#include "netif/ppp/ecp.h"
|
||||
#include "ecp.h"
|
||||
#endif /* EAP_SUPPORT */
|
||||
#if VJ_SUPPORT
|
||||
#include "netif/ppp/vj.h"
|
||||
#include "vj.h"
|
||||
#endif /* VJ_SUPPORT */
|
||||
#if PPP_IPV4_SUPPORT
|
||||
#include "netif/ppp/ipcp.h"
|
||||
#include "ipcp.h"
|
||||
#endif /* PPP_IPV4_SUPPORT */
|
||||
#if PPP_IPV6_SUPPORT
|
||||
#include "netif/ppp/ipv6cp.h"
|
||||
#include "ipv6cp.h"
|
||||
#endif /* PPP_IPV6_SUPPORT */
|
||||
|
||||
/*************************/
|
||||
|
@ -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,7 @@ 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);
|
||||
}
|
||||
/* mppe_compress() returns a new allocated pbuf, indicate we should free
|
||||
* our duplicated pbuf later */
|
||||
|
@ -598,7 +576,7 @@ err_rte_drop:
|
|||
MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
|
||||
err:
|
||||
if (fpb) {
|
||||
pbuf_free(fpb);
|
||||
ppp_memory_buffer_free(fpb);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
@ -611,19 +589,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 +632,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 +676,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 +744,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 +758,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 +855,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 +874,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 +888,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 +905,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 +952,14 @@ drop:
|
|||
MIB2_STATS_NETIF_INC(pcb->netif, ifindiscards);
|
||||
|
||||
out:
|
||||
pbuf_free(pb);
|
||||
ppp_memory_buffer_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 +1000,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 +1016,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 +1031,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 +1043,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 +1058,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 +1069,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 +1090,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 +1121,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 +1138,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 +1147,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 +1166,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 +1176,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 +1185,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 +1219,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 +1233,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 +1250,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 +1259,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 +1271,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 +1303,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 +1317,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 +1362,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 +1375,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 +1549,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.
|
||||
*/
|
||||
|
||||
/*
|
|
@ -57,15 +57,15 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/fsm.h"
|
||||
#include "netif/ppp/ecp.h"
|
||||
#include "fsm.h"
|
||||
#include "ecp.h"
|
||||
|
||||
#if PPP_OPTIONS
|
||||
static option_t ecp_option_list[] = {
|
|
@ -31,18 +31,17 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#include "ppp_opts.h"
|
||||
|
||||
#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */
|
||||
#if PPP_API
|
||||
|
||||
#include "netif/ppp/pppapi.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#include "netif/ppp/pppol2tp.h"
|
||||
#include "netif/ppp/pppos.h"
|
||||
#include "pppapi.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
|
|
@ -30,12 +30,12 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/ppp_opts.h"
|
||||
#include "ppp_opts.h"
|
||||
#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not necessary */
|
||||
|
||||
#include "netif/ppp/ppp_impl.h"
|
||||
#include "ppp_impl.h"
|
||||
|
||||
#include "netif/ppp/pppcrypt.h"
|
||||
#include "pppcrypt.h"
|
||||
|
||||
|
||||
static u_char pppcrypt_get_7bits(u_char *input, int startBit) {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue