PPPoE application with W5500

Dependencies:   W5500Interface mbed pppoe

- How to connect PPPoE with WIZ550 ioShield and mbed platform (Korean version)

http://hjjeon0608.wordpress.com/2014/09/25/wiz550io-ioshield-a%EC%99%80-mbed-%EB%B3%B4%EB%93%9C%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%98%EC%97%AC-pppoe-%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0/

- How to connect ioShield to mbed platform(ST nucleo) of ST Microelectronics via SPI (Korean version)

http://hjjeon0608.wordpress.com/2014/09/25/wiz550-ioshield-a-%EC%99%80-mbed-%ED%94%8C%EB%9E%AB%ED%8F%BC-st-nucleo-f030r8-%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0/

- Example PPPoE server(RB750) setting (Korean version)

http://hjjeon0608.wordpress.com/2014/10/28/rb750pppoe-server-setting%ED%95%98%EA%B8%B0/

- W5500(PPPoE client) setting (Korean version)

http://hjjeon0608.wordpress.com/2014/10/29/temp/

- PPPoE library

http://developer.mbed.org/teams/EthernetInterfaceW5500-makers/code/pppoe/

Committer:
hjjeon
Date:
Wed Oct 15 06:27:12 2014 +0000
Revision:
1:8ef7820bf777
Child:
3:39ed2b6d91b0
PPPoE application with W5500

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hjjeon 1:8ef7820bf777 1 #include "mbed.h"
hjjeon 1:8ef7820bf777 2 #include "EthernetInterface.h"
hjjeon 1:8ef7820bf777 3 #include <stdio.h>
hjjeon 1:8ef7820bf777 4 #include <string.h>
hjjeon 1:8ef7820bf777 5 #include "PPPoE.h"
hjjeon 1:8ef7820bf777 6
hjjeon 1:8ef7820bf777 7
hjjeon 1:8ef7820bf777 8 /////////////////////////////////////////
hjjeon 1:8ef7820bf777 9 // SOCKET NUMBER DEFINION for Examples //
hjjeon 1:8ef7820bf777 10 /////////////////////////////////////////
hjjeon 1:8ef7820bf777 11 #define SOCK_TCPS 1
hjjeon 1:8ef7820bf777 12 #define SOCK_UDPS 2
hjjeon 1:8ef7820bf777 13
hjjeon 1:8ef7820bf777 14
hjjeon 1:8ef7820bf777 15
hjjeon 1:8ef7820bf777 16 ////////////////////////////////////////////////
hjjeon 1:8ef7820bf777 17 // Shared Buffer Definition for LOOPBACK TEST //
hjjeon 1:8ef7820bf777 18 ////////////////////////////////////////////////
hjjeon 1:8ef7820bf777 19 #define DATA_BUF_SIZE 2048
hjjeon 1:8ef7820bf777 20 uint8_t gDATABUF[DATA_BUF_SIZE];
hjjeon 1:8ef7820bf777 21
hjjeon 1:8ef7820bf777 22
hjjeon 1:8ef7820bf777 23 ///////////////////////////////////
hjjeon 1:8ef7820bf777 24 // Default Network Configuration //
hjjeon 1:8ef7820bf777 25 ///////////////////////////////////
hjjeon 1:8ef7820bf777 26 /*
hjjeon 1:8ef7820bf777 27 wiz_NetInfo gWIZNETINFO = { .mac = {0x00, 0x08, 0xdc,0x00, 0xab, 0xcd},
hjjeon 1:8ef7820bf777 28 .ip = {192, 168, 200, 123},
hjjeon 1:8ef7820bf777 29 .sn = {255,255,255,0},
hjjeon 1:8ef7820bf777 30 .gw = {192, 168, 200, 1},
hjjeon 1:8ef7820bf777 31 .dns = {0,0,0,0},
hjjeon 1:8ef7820bf777 32 .dhcp = NETINFO_STATIC };
hjjeon 1:8ef7820bf777 33 */
hjjeon 1:8ef7820bf777 34
hjjeon 1:8ef7820bf777 35 ///////////////////////////////////////
hjjeon 1:8ef7820bf777 36 // ID and Password for PAP for PPPoE //
hjjeon 1:8ef7820bf777 37 ///////////////////////////////////////
hjjeon 1:8ef7820bf777 38 //TODO : fill these variables before start ppp_init
hjjeon 1:8ef7820bf777 39 uint8_t pppoe_id[] = "wiznet";
hjjeon 1:8ef7820bf777 40 uint8_t pppoe_id_len = 6;
hjjeon 1:8ef7820bf777 41 uint8_t pppoe_pw[] = "wiz1206";
hjjeon 1:8ef7820bf777 42 uint8_t pppoe_pw_len = 7;
hjjeon 1:8ef7820bf777 43 uint8_t pppoe_ip[4] = {0,};
hjjeon 1:8ef7820bf777 44 uint8_t pppoe_pdns[4] = {0,};
hjjeon 1:8ef7820bf777 45 uint8_t pppoe_sdns[4] = {0,};
hjjeon 1:8ef7820bf777 46 uint16_t pppoe_retry_count = 0;
hjjeon 1:8ef7820bf777 47
hjjeon 1:8ef7820bf777 48
hjjeon 1:8ef7820bf777 49
hjjeon 1:8ef7820bf777 50 int main() {
hjjeon 1:8ef7820bf777 51 // EthernetInterface eth;
hjjeon 1:8ef7820bf777 52 // change for W5500 interface.
hjjeon 1:8ef7820bf777 53 #if defined(TARGET_LPC1114)
hjjeon 1:8ef7820bf777 54 SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
hjjeon 1:8ef7820bf777 55 EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset
hjjeon 1:8ef7820bf777 56
hjjeon 1:8ef7820bf777 57 #elif defined(TARGET_LPC1768)
hjjeon 1:8ef7820bf777 58 SPI spi(p11, p12, p13); // mosi, miso, sclk
hjjeon 1:8ef7820bf777 59 EthernetInterface eth(&spi, p14, p15); // spi, cs, reset
hjjeon 1:8ef7820bf777 60 #elif defined(TARGET_LPC11U68)
hjjeon 1:8ef7820bf777 61 SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk
hjjeon 1:8ef7820bf777 62 EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io
hjjeon 1:8ef7820bf777 63 spi.format(8,0); // 8bit, mode 0
hjjeon 1:8ef7820bf777 64 spi.frequency(7000000); // 7MHz
hjjeon 1:8ef7820bf777 65 wait(1); // 1 second for stable state
hjjeon 1:8ef7820bf777 66 #elif defined(TARGET_KL25Z)
hjjeon 1:8ef7820bf777 67 Serial pc(USBTX, USBRX);
hjjeon 1:8ef7820bf777 68 pc.baud(115200);
hjjeon 1:8ef7820bf777 69 printf("spi init\r\n");
hjjeon 1:8ef7820bf777 70 SPI spi(D11, D12, D13); // mosi, miso, sclk
hjjeon 1:8ef7820bf777 71 wait(1); // 1 second for stable state
hjjeon 1:8ef7820bf777 72 EthernetInterface eth(&spi, D10, D9);//scs(D10), nRESET(PTA20)
hjjeon 1:8ef7820bf777 73 printf("App Start\r\n");
hjjeon 1:8ef7820bf777 74 wait(1); // 1 second for stable state
hjjeon 1:8ef7820bf777 75 wait(1); // 1 second for stable state
hjjeon 1:8ef7820bf777 76 #elif defined (TARGET_NUCLEO_F030R8)
hjjeon 1:8ef7820bf777 77 Serial pc(USBTX, USBRX);
hjjeon 1:8ef7820bf777 78 pc.baud(115200);
hjjeon 1:8ef7820bf777 79 SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk
hjjeon 1:8ef7820bf777 80 EthernetInterface eth(&spi, PB_6, PA_9);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io
hjjeon 1:8ef7820bf777 81 spi.format(8,0); // 8bit, mode 0
hjjeon 1:8ef7820bf777 82 spi.frequency(7000000); // 7MHz
hjjeon 1:8ef7820bf777 83 wait(1); // 1 second for stable state
hjjeon 1:8ef7820bf777 84 #elif defined (TARGET_NUCLEO_F334R8)
hjjeon 1:8ef7820bf777 85 Serial pc(USBTX, USBRX);
hjjeon 1:8ef7820bf777 86 pc.baud(115200);
hjjeon 1:8ef7820bf777 87 SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk
hjjeon 1:8ef7820bf777 88 EthernetInterface eth(&spi, PB_6, PA_9);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io
hjjeon 1:8ef7820bf777 89 spi.format(8,0); // 8bit, mode 0
hjjeon 1:8ef7820bf777 90 spi.frequency(7000000); // 7MHz
hjjeon 1:8ef7820bf777 91 wait(1); // 1 second for stable state
hjjeon 1:8ef7820bf777 92 #endif
hjjeon 1:8ef7820bf777 93
hjjeon 1:8ef7820bf777 94
hjjeon 1:8ef7820bf777 95 int8_t tmp = 0;
hjjeon 1:8ef7820bf777 96 uint8_t mac_addr[6] = {0x00, 0x08, 0xdc,0x00, 0xab, 0xcd};
hjjeon 1:8ef7820bf777 97 int32_t ret;
hjjeon 1:8ef7820bf777 98 uint8_t str[15];
hjjeon 1:8ef7820bf777 99
hjjeon 1:8ef7820bf777 100 printf("platform init done\r\n");
hjjeon 1:8ef7820bf777 101
hjjeon 1:8ef7820bf777 102
hjjeon 1:8ef7820bf777 103
hjjeon 1:8ef7820bf777 104 /* PHY link status check */
hjjeon 1:8ef7820bf777 105
hjjeon 1:8ef7820bf777 106 do
hjjeon 1:8ef7820bf777 107 {
hjjeon 1:8ef7820bf777 108 if(eth.getPHYCFGR() & PHYCFGR_LNK_ON)
hjjeon 1:8ef7820bf777 109 tmp = PHY_LINK_ON;
hjjeon 1:8ef7820bf777 110 else
hjjeon 1:8ef7820bf777 111 tmp = PHY_LINK_OFF;
hjjeon 1:8ef7820bf777 112
hjjeon 1:8ef7820bf777 113 if(tmp == -1)
hjjeon 1:8ef7820bf777 114 printf("Unknown PHY Link stauts.\r\n");
hjjeon 1:8ef7820bf777 115 }while(tmp == PHY_LINK_OFF);
hjjeon 1:8ef7820bf777 116
hjjeon 1:8ef7820bf777 117
hjjeon 1:8ef7820bf777 118 /* Network initialization */
hjjeon 1:8ef7820bf777 119 eth.init((uint8_t *)mac_addr, "192.168.200.123", "255.255.255.0", "192.168.200.1");
hjjeon 1:8ef7820bf777 120
hjjeon 1:8ef7820bf777 121 printf("\r\n====== MACRAW:PPPoE Start ======\r\n");
hjjeon 1:8ef7820bf777 122
hjjeon 1:8ef7820bf777 123 /*
hjjeon 1:8ef7820bf777 124 md5_init(&context);
hjjeon 1:8ef7820bf777 125 md5_update(&context, str, str_len);
hjjeon 1:8ef7820bf777 126 md5_final(digest, &context);
hjjeon 1:8ef7820bf777 127
hjjeon 1:8ef7820bf777 128 */
hjjeon 1:8ef7820bf777 129 PPPOEClient pppoe;
hjjeon 1:8ef7820bf777 130
hjjeon 1:8ef7820bf777 131 while(1)
hjjeon 1:8ef7820bf777 132 {
hjjeon 1:8ef7820bf777 133 ret = pppoe.ppp_start(gDATABUF);//ppp start function
hjjeon 1:8ef7820bf777 134 if(ret == PPP_SUCCESS || pppoe_retry_count > PPP_MAX_RETRY_COUNT) break; // PPPoE Connected or connect failed by over retry count
hjjeon 1:8ef7820bf777 135
hjjeon 1:8ef7820bf777 136 }
hjjeon 1:8ef7820bf777 137
hjjeon 1:8ef7820bf777 138
hjjeon 1:8ef7820bf777 139
hjjeon 1:8ef7820bf777 140 if(ret == PPP_SUCCESS)//1 : success
hjjeon 1:8ef7820bf777 141 {
hjjeon 1:8ef7820bf777 142
hjjeon 1:8ef7820bf777 143 printf("\r\n<<<< PPPoE Success >>>>\r\n");
hjjeon 1:8ef7820bf777 144 printf("Assigned IP address : %.3u.%.3u.%.3u.%.3u\r\n", pppoe_ip[0], pppoe_ip[1], pppoe_ip[2], pppoe_ip[3]);
hjjeon 1:8ef7820bf777 145
hjjeon 1:8ef7820bf777 146 printf( "\r\n==================================================\r\n");
hjjeon 1:8ef7820bf777 147 printf( " AFTER PPPoE, Net Configuration Information \r\n");
hjjeon 1:8ef7820bf777 148 printf( "==================================================\r\n");
hjjeon 1:8ef7820bf777 149
hjjeon 1:8ef7820bf777 150
hjjeon 1:8ef7820bf777 151 eth.getSHAR(str);
hjjeon 1:8ef7820bf777 152 printf( "MAC address : %x:%x:%x:%x:%x:%x\r\n", str[0], str[1], str[2], str[3], str[4], str[5] );
hjjeon 1:8ef7820bf777 153 eth.getSUBR(str);
hjjeon 1:8ef7820bf777 154 printf( "SUBNET MASK : %.3u.%.3u.%.3u.%.3u\r\n", str[0], str[1], str[2], str[3] );
hjjeon 1:8ef7820bf777 155 eth.getGAR(str);
hjjeon 1:8ef7820bf777 156 printf( "G/W IP ADDRESS : %.3u.%.3u.%.3u.%.3u\r\n",str[0], str[1], str[2], str[3]);
hjjeon 1:8ef7820bf777 157 eth.getSIPR(str);
hjjeon 1:8ef7820bf777 158 printf( "SOURCE IP ADDRESS : %.3u.%.3u.%.3u.%.3u\r\n\r\n", str[0], str[1], str[2], str[3]);
hjjeon 1:8ef7820bf777 159
hjjeon 1:8ef7820bf777 160
hjjeon 1:8ef7820bf777 161 }
hjjeon 1:8ef7820bf777 162 else//failed
hjjeon 1:8ef7820bf777 163 {
hjjeon 1:8ef7820bf777 164 printf("\r\n<<<< PPPoE Failed >>>>\r\n");
hjjeon 1:8ef7820bf777 165 eth.init((uint8_t *)mac_addr, "192.168.200.123", "255.255.255.0", "192.168.200.1");
hjjeon 1:8ef7820bf777 166 }
hjjeon 1:8ef7820bf777 167
hjjeon 1:8ef7820bf777 168
hjjeon 1:8ef7820bf777 169
hjjeon 1:8ef7820bf777 170 /*******************************/
hjjeon 1:8ef7820bf777 171 /* WIZnet W5500 Code Examples */
hjjeon 1:8ef7820bf777 172 /* TCPS/UDPS Loopback test */
hjjeon 1:8ef7820bf777 173 /*******************************/
hjjeon 1:8ef7820bf777 174 /* Main loop */
hjjeon 1:8ef7820bf777 175 /*
hjjeon 1:8ef7820bf777 176 while(1)
hjjeon 1:8ef7820bf777 177 {
hjjeon 1:8ef7820bf777 178 // Loopback Test
hjjeon 1:8ef7820bf777 179 // TCP server loopback test
hjjeon 1:8ef7820bf777 180 if( (ret = loopback_tcps(SOCK_TCPS, gDATABUF, 5000)) < 0) {
hjjeon 1:8ef7820bf777 181 printf("SOCKET ERROR : %ld\r\n", ret);
hjjeon 1:8ef7820bf777 182 }
hjjeon 1:8ef7820bf777 183
hjjeon 1:8ef7820bf777 184 // UDP server loopback test
hjjeon 1:8ef7820bf777 185 if( (ret = loopback_udps(SOCK_UDPS, gDATABUF, 3000)) < 0) {
hjjeon 1:8ef7820bf777 186 printf("SOCKET ERROR : %ld\r\n", ret);
hjjeon 1:8ef7820bf777 187 }
hjjeon 1:8ef7820bf777 188 } // end of Main loop
hjjeon 1:8ef7820bf777 189 */
hjjeon 1:8ef7820bf777 190 } // end of main()
hjjeon 1:8ef7820bf777 191
hjjeon 1:8ef7820bf777 192
hjjeon 1:8ef7820bf777 193