initial commit
This commit is contained in:
77
lib/amb1_sdk/common/example/pppoe/example_pppoe.c
Normal file
77
lib/amb1_sdk/common/example/pppoe/example_pppoe.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <platform_opts.h>
|
||||
|
||||
#if CONFIG_EXAMPLE_PPPOE
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <lwip_netconf.h>
|
||||
#include <../netif/ppp/ppp_impl.h>
|
||||
#include <netif/ppp_oe.h>
|
||||
|
||||
#define PPPOE_USER "user"
|
||||
#define PPPOE_PASSWD "passwd"
|
||||
|
||||
extern struct netif xnetif[];
|
||||
|
||||
void pppLinkStatusCallback(void *ctx, int errCode, void *arg)
|
||||
{
|
||||
switch(errCode) {
|
||||
case PPPERR_NONE: {
|
||||
struct ppp_addrs *ppp_addrs = arg;
|
||||
printf("pppLinkStatusCallback: PPPERR_NONE\n");
|
||||
printf(" our_ipaddr=%s\n", ip_ntoa(&ppp_addrs->our_ipaddr));
|
||||
printf(" his_ipaddr=%s\n", ip_ntoa(&ppp_addrs->his_ipaddr));
|
||||
printf(" netmask =%s\n", ip_ntoa(&ppp_addrs->netmask));
|
||||
printf(" dns1 =%s\n", ip_ntoa(&ppp_addrs->dns1));
|
||||
printf(" dns2 =%s\n", ip_ntoa(&ppp_addrs->dns2));
|
||||
dns_setserver(0, &ppp_addrs->dns1);
|
||||
dns_setserver(1, &ppp_addrs->dns2);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("pppLinkStatusCallback: errCode(%d)\n", errCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void example_pppoe_thread(void *param)
|
||||
{
|
||||
int ppp_desc = -1;
|
||||
|
||||
// Delay to wait for IP by DHCP
|
||||
vTaskDelay(10000);
|
||||
printf("\nExample: PPPOE\n");
|
||||
|
||||
xnetif[0].flags &= ~(NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP); /* no ARP */
|
||||
xnetif[0].flags |= NETIF_FLAG_ETHERNET; /* pure ethernet */
|
||||
|
||||
pppInit();
|
||||
pppSetAuth(PPPAUTHTYPE_ANY, PPPOE_USER, PPPOE_PASSWD);
|
||||
ppp_desc = pppOverEthernetOpen(&xnetif[0], NULL, NULL, pppLinkStatusCallback, NULL);
|
||||
|
||||
if(ppp_desc >= 0) {
|
||||
while(1) {
|
||||
int if_up = 0;
|
||||
pppIOCtl(ppp_desc, PPPCTLG_UPSTATUS, &if_up);
|
||||
if(if_up)
|
||||
break;
|
||||
else
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
|
||||
printf("Close PPPOE after 10 seconds\n");
|
||||
vTaskDelay(10000);
|
||||
pppClose(ppp_desc);
|
||||
}
|
||||
|
||||
exit:
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_pppoe(void)
|
||||
{
|
||||
if(xTaskCreate(example_pppoe_thread, ((const char*)"example_pppoe_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_EXAMPLE_PPPOE */
|
||||
6
lib/amb1_sdk/common/example/pppoe/example_pppoe.h
Normal file
6
lib/amb1_sdk/common/example/pppoe/example_pppoe.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef EXAMPLE_PPPOE_H
|
||||
#define EXAMPLE_PPPOE_H
|
||||
|
||||
void example_pppoe(void);
|
||||
|
||||
#endif /* EXAMPLE_PPPOE_H */
|
||||
21
lib/amb1_sdk/common/example/pppoe/readme.txt
Normal file
21
lib/amb1_sdk/common/example/pppoe/readme.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
LWIP PPPOE EXAMPLE
|
||||
|
||||
Description:
|
||||
Example for lwip pppoe connection.
|
||||
|
||||
Configuration:
|
||||
[lwipopts.h]
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPPOE_SUPPORT 1
|
||||
#define PPPOS_SUPPORT 0
|
||||
#define PAP_SUPPORT 1
|
||||
#define CHAP_SUPPORT 1
|
||||
#define MD5_SUPPORT 1
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_PPPOE 1
|
||||
|
||||
Execution:
|
||||
Can make automatical Wi-Fi connection when booting by using wlan fast connect example.
|
||||
A PPPOE example thread will be started automatically when booting.
|
||||
|
||||
Setup PPPOE_USER and PPPOE_PASSWD in example_pppoe.c for authentication. PPP addresses will be shown after PPP is connected
|
||||
Reference in New Issue
Block a user