PPPoE application with W5500
Dependencies: W5500Interface mbed pppoe
- How to connect PPPoE with WIZ550 ioShield and mbed platform (Korean version)
- How to connect ioShield to mbed platform(ST nucleo) of ST Microelectronics via SPI (Korean version)
- 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/
pppoe/PPPoE.h@4:c56129381640, 2014-10-16 (annotated)
- Committer:
- hjjeon
- Date:
- Thu Oct 16 07:45:37 2014 +0000
- Revision:
- 4:c56129381640
- Parent:
- 1:8ef7820bf777
Change default debugging message level at pppoe.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hjjeon | 1:8ef7820bf777 | 1 | #include <stdio.h> |
hjjeon | 1:8ef7820bf777 | 2 | #include <string.h> |
hjjeon | 1:8ef7820bf777 | 3 | #include <stdint.h> |
hjjeon | 1:8ef7820bf777 | 4 | #include "W5500.h" |
hjjeon | 1:8ef7820bf777 | 5 | #include "Socket.h" |
hjjeon | 1:8ef7820bf777 | 6 | #include "md5.h" |
hjjeon | 1:8ef7820bf777 | 7 | |
hjjeon | 1:8ef7820bf777 | 8 | |
hjjeon | 1:8ef7820bf777 | 9 | |
hjjeon | 1:8ef7820bf777 | 10 | |
hjjeon | 1:8ef7820bf777 | 11 | |
hjjeon | 1:8ef7820bf777 | 12 | |
hjjeon | 1:8ef7820bf777 | 13 | #define __DEF_PPP_DBG__ // debug message for [Phase] and [Network Init] |
hjjeon | 4:c56129381640 | 14 | //#define __DEF_PPP_DBG1__ // debug message for checking 'Txbuf overflow' and etc. |
hjjeon | 1:8ef7820bf777 | 15 | //#define __DEF_PPP_DBG2__ // debug received and send packet. |
hjjeon | 1:8ef7820bf777 | 16 | |
hjjeon | 1:8ef7820bf777 | 17 | |
hjjeon | 1:8ef7820bf777 | 18 | |
hjjeon | 1:8ef7820bf777 | 19 | //PPPoE retry count value |
hjjeon | 1:8ef7820bf777 | 20 | //#define PPP_MAX_RETRYRECV_COUNT 50 |
hjjeon | 1:8ef7820bf777 | 21 | #define PPP_MAX_RETRYSEND_COUNT 5 |
hjjeon | 1:8ef7820bf777 | 22 | #define PPP_MAX_RETRYRECV_COUNT 32 |
hjjeon | 1:8ef7820bf777 | 23 | #define PPP_MAX_RETRY_COUNT 5 |
hjjeon | 1:8ef7820bf777 | 24 | // PPPoE EtherType definition |
hjjeon | 1:8ef7820bf777 | 25 | #define PPPoE_DISCOVERY 0x8863 |
hjjeon | 1:8ef7820bf777 | 26 | #define PPPoE_SESSION 0x8864 |
hjjeon | 1:8ef7820bf777 | 27 | |
hjjeon | 1:8ef7820bf777 | 28 | // PPPoE Frame field definition |
hjjeon | 1:8ef7820bf777 | 29 | #define PPPoE_VER_TYPE 0x11 |
hjjeon | 1:8ef7820bf777 | 30 | |
hjjeon | 1:8ef7820bf777 | 31 | // PPPoE Code definition |
hjjeon | 1:8ef7820bf777 | 32 | #define PPPoE_PADI 0x09 |
hjjeon | 1:8ef7820bf777 | 33 | #define PPPoE_PADO 0x07 |
hjjeon | 1:8ef7820bf777 | 34 | #define PPPoE_PADR 0x19 |
hjjeon | 1:8ef7820bf777 | 35 | #define PPPoE_PADS 0x65 |
hjjeon | 1:8ef7820bf777 | 36 | #define PPPoE_PADT 0xa7 |
hjjeon | 1:8ef7820bf777 | 37 | #define PPPoE_SESSIONDATA 0x00 |
hjjeon | 1:8ef7820bf777 | 38 | |
hjjeon | 1:8ef7820bf777 | 39 | // PPPoE Discovery Tag type definition |
hjjeon | 1:8ef7820bf777 | 40 | #define PPPoED_END_OF_LIST 0x0000 |
hjjeon | 1:8ef7820bf777 | 41 | #define PPPoED_SERVICE_NAME 0x0101 |
hjjeon | 1:8ef7820bf777 | 42 | #define PPPoED_AC_NAME 0x0102 |
hjjeon | 1:8ef7820bf777 | 43 | #define PPPoED_HOST_UNIQ 0x0103 |
hjjeon | 1:8ef7820bf777 | 44 | #define PPPoED_AC_COOKIE 0x0104 |
hjjeon | 1:8ef7820bf777 | 45 | #define PPPoED_VENDER_SPECIFIC 0x0105 |
hjjeon | 1:8ef7820bf777 | 46 | |
hjjeon | 1:8ef7820bf777 | 47 | // PPPoE Protocol definition |
hjjeon | 1:8ef7820bf777 | 48 | #define PPPoE_LCP 0xC021 |
hjjeon | 1:8ef7820bf777 | 49 | #define PPPoE_PAP 0xC023 |
hjjeon | 1:8ef7820bf777 | 50 | #define PPPoE_CHAP 0xC223 |
hjjeon | 1:8ef7820bf777 | 51 | #define PPPoE_IPCP 0x8021 |
hjjeon | 1:8ef7820bf777 | 52 | |
hjjeon | 1:8ef7820bf777 | 53 | // PPPoE Protocol Code definition |
hjjeon | 1:8ef7820bf777 | 54 | // LCP using 0x01 ~ 0x0b |
hjjeon | 1:8ef7820bf777 | 55 | // PAP using 0x01 ~ 0x03 |
hjjeon | 1:8ef7820bf777 | 56 | // IPCP using 0x01 ~ 0x07 |
hjjeon | 1:8ef7820bf777 | 57 | #define PPP_CONFIG_REQ 0x01 |
hjjeon | 1:8ef7820bf777 | 58 | #define PPP_CONFIG_ACK 0x02 |
hjjeon | 1:8ef7820bf777 | 59 | #define PPP_CONFIG_NAK 0x03 |
hjjeon | 1:8ef7820bf777 | 60 | #define PPP_CONFIG_REJ 0x04 |
hjjeon | 1:8ef7820bf777 | 61 | #define PPP_TERM_REQ 0x05 |
hjjeon | 1:8ef7820bf777 | 62 | #define PPP_TERM_ACK 0x06 |
hjjeon | 1:8ef7820bf777 | 63 | #define PPP_CODE_REJ 0x07 |
hjjeon | 1:8ef7820bf777 | 64 | #define PPP_PROT_REJ 0x08 |
hjjeon | 1:8ef7820bf777 | 65 | #define PPP_ECHO_REQ 0x09 |
hjjeon | 1:8ef7820bf777 | 66 | #define PPP_ECHO_REP 0x0a |
hjjeon | 1:8ef7820bf777 | 67 | #define PPP_DIS_REQ 0x0b |
hjjeon | 1:8ef7820bf777 | 68 | |
hjjeon | 1:8ef7820bf777 | 69 | // PPPoE LCP Type definition |
hjjeon | 1:8ef7820bf777 | 70 | #define LCP_MRU 0x01 |
hjjeon | 1:8ef7820bf777 | 71 | #define LCP_AUTH 0x03 |
hjjeon | 1:8ef7820bf777 | 72 | #define LCP_MAGICNUM 0x05 |
hjjeon | 1:8ef7820bf777 | 73 | #define LCP_PROTOCOMP 0x07 |
hjjeon | 1:8ef7820bf777 | 74 | #define LCP_ADDRCOMP 0x08 |
hjjeon | 1:8ef7820bf777 | 75 | |
hjjeon | 1:8ef7820bf777 | 76 | // PPPoE CHAP Algorithm |
hjjeon | 1:8ef7820bf777 | 77 | #define MD5 0x05 |
hjjeon | 1:8ef7820bf777 | 78 | #define MS_CHAP 0x80 |
hjjeon | 1:8ef7820bf777 | 79 | #define MS_CHAP_V2 0x81 |
hjjeon | 1:8ef7820bf777 | 80 | |
hjjeon | 1:8ef7820bf777 | 81 | // PPPoE stage control flags |
hjjeon | 1:8ef7820bf777 | 82 | #define FLAG_DISCOVERY_RCV_PADO 0x0001 |
hjjeon | 1:8ef7820bf777 | 83 | #define FLAG_DISCOVERY_RCV_PADS 0x0002 |
hjjeon | 1:8ef7820bf777 | 84 | #define FLAG_LCP_CR_RCV 0x0004 |
hjjeon | 1:8ef7820bf777 | 85 | #define FLAG_LCP_CR_SNT 0x0008 |
hjjeon | 1:8ef7820bf777 | 86 | #define FLAG_PAP_ACK_RCV 0x0010 |
hjjeon | 1:8ef7820bf777 | 87 | #define FLAG_CHAP_SUC_RCV 0x0020 |
hjjeon | 1:8ef7820bf777 | 88 | #define FLAG_IPCP_CR_SNT 0x0040 |
hjjeon | 1:8ef7820bf777 | 89 | #define FLAG_IPCP_CR_RCV 0x0080 |
hjjeon | 1:8ef7820bf777 | 90 | #define FLAG_IPCP_NAK_RCV 0x0100 |
hjjeon | 1:8ef7820bf777 | 91 | #define FLAG_TERMINATION_ACK_RCV 0x0200 |
hjjeon | 1:8ef7820bf777 | 92 | #define FLAG_TERMINATION_REQ_RCV 0x0400 |
hjjeon | 1:8ef7820bf777 | 93 | #define FLAG_PADO_SERVICENAME 0x0800 |
hjjeon | 1:8ef7820bf777 | 94 | |
hjjeon | 1:8ef7820bf777 | 95 | /* |
hjjeon | 1:8ef7820bf777 | 96 | // PPPoE Field value definition |
hjjeon | 1:8ef7820bf777 | 97 | // -> not used. |
hjjeon | 1:8ef7820bf777 | 98 | #define PPPoE_SESSION_ID 0x0000 |
hjjeon | 1:8ef7820bf777 | 99 | #define LCP_MAGICNUM_VAL 0x00112299 |
hjjeon | 1:8ef7820bf777 | 100 | */ |
hjjeon | 1:8ef7820bf777 | 101 | |
hjjeon | 1:8ef7820bf777 | 102 | // Logical variable definition |
hjjeon | 1:8ef7820bf777 | 103 | #define PPP_SUCCESS 1 |
hjjeon | 1:8ef7820bf777 | 104 | //#define PPP_FAIL 0 |
hjjeon | 1:8ef7820bf777 | 105 | #define PPP_RETRY 2 |
hjjeon | 1:8ef7820bf777 | 106 | |
hjjeon | 1:8ef7820bf777 | 107 | #define OPTMSG_LEN 80 |
hjjeon | 1:8ef7820bf777 | 108 | #define CV_HV_LEN 16 |
hjjeon | 1:8ef7820bf777 | 109 | |
hjjeon | 1:8ef7820bf777 | 110 | |
hjjeon | 1:8ef7820bf777 | 111 | #define PPPoE_FAILED 0 |
hjjeon | 1:8ef7820bf777 | 112 | |
hjjeon | 1:8ef7820bf777 | 113 | |
hjjeon | 1:8ef7820bf777 | 114 | #define PPP_FRAME_SIZE 128 |
hjjeon | 1:8ef7820bf777 | 115 | #define PPP_RXFRAME_SIZE 1514 |
hjjeon | 1:8ef7820bf777 | 116 | |
hjjeon | 1:8ef7820bf777 | 117 | |
hjjeon | 1:8ef7820bf777 | 118 | |
hjjeon | 1:8ef7820bf777 | 119 | class PPPOEClient |
hjjeon | 1:8ef7820bf777 | 120 | { |
hjjeon | 1:8ef7820bf777 | 121 | public: |
hjjeon | 1:8ef7820bf777 | 122 | PPPOEClient(); |
hjjeon | 1:8ef7820bf777 | 123 | void set_pppinfo(uint8_t * nas_mac, uint8_t * ppp_ip, uint16_t nas_sessionid); |
hjjeon | 1:8ef7820bf777 | 124 | void ppp_send(void); |
hjjeon | 1:8ef7820bf777 | 125 | void ppp_recv( uint16_t received_len ); |
hjjeon | 1:8ef7820bf777 | 126 | void do_discovery(void); |
hjjeon | 1:8ef7820bf777 | 127 | void do_lcp(void); |
hjjeon | 1:8ef7820bf777 | 128 | void do_lcp_echo(void); |
hjjeon | 1:8ef7820bf777 | 129 | uint8_t do_lcp_terminate(void); |
hjjeon | 1:8ef7820bf777 | 130 | void do_pap(void); |
hjjeon | 1:8ef7820bf777 | 131 | void do_ipcp(void); |
hjjeon | 1:8ef7820bf777 | 132 | uint8_t ppp_start(uint8_t * pppoe_buf); |
hjjeon | 1:8ef7820bf777 | 133 | //void delay_ms(uint32_t time); |
hjjeon | 1:8ef7820bf777 | 134 | |
hjjeon | 1:8ef7820bf777 | 135 | |
hjjeon | 1:8ef7820bf777 | 136 | |
hjjeon | 1:8ef7820bf777 | 137 | private: |
hjjeon | 1:8ef7820bf777 | 138 | WIZnet_Chip* eth; |
hjjeon | 1:8ef7820bf777 | 139 | |
hjjeon | 1:8ef7820bf777 | 140 | }; |
hjjeon | 1:8ef7820bf777 | 141 | |
hjjeon | 1:8ef7820bf777 | 142 | // PPPoE message |
hjjeon | 1:8ef7820bf777 | 143 | typedef struct _PPPMSG |
hjjeon | 1:8ef7820bf777 | 144 | { |
hjjeon | 1:8ef7820bf777 | 145 | uint8_t dst_mac[6]; |
hjjeon | 1:8ef7820bf777 | 146 | uint8_t src_mac[6]; |
hjjeon | 1:8ef7820bf777 | 147 | uint16_t ether_type; // 0x8863 : PPPoE Discovery, 0x8864 : PPPoE Session |
hjjeon | 1:8ef7820bf777 | 148 | uint8_t version_type; // 4-bit 'version' = 0001, 4-bit 'type' = 0001 default |
hjjeon | 1:8ef7820bf777 | 149 | uint8_t frame_code; |
hjjeon | 1:8ef7820bf777 | 150 | uint16_t session_id; |
hjjeon | 1:8ef7820bf777 | 151 | uint16_t len; |
hjjeon | 1:8ef7820bf777 | 152 | }PPPMSG; |
hjjeon | 1:8ef7820bf777 | 153 | |
hjjeon | 1:8ef7820bf777 | 154 | // PPPoE Protocol |
hjjeon | 1:8ef7820bf777 | 155 | typedef struct _PROTOCOL |
hjjeon | 1:8ef7820bf777 | 156 | { |
hjjeon | 1:8ef7820bf777 | 157 | uint16_t protocol; |
hjjeon | 1:8ef7820bf777 | 158 | uint8_t pcode; |
hjjeon | 1:8ef7820bf777 | 159 | uint8_t id; |
hjjeon | 1:8ef7820bf777 | 160 | uint16_t len; |
hjjeon | 1:8ef7820bf777 | 161 | uint8_t opt[OPTMSG_LEN]; |
hjjeon | 1:8ef7820bf777 | 162 | }PROTOCOL; |
hjjeon | 1:8ef7820bf777 | 163 | |
hjjeon | 1:8ef7820bf777 | 164 | // PPPoE Start function |
hjjeon | 1:8ef7820bf777 | 165 | uint8_t ppp_start(uint8_t * pppoe_buf); |
hjjeon | 1:8ef7820bf777 | 166 | //PPPoE termination function |
hjjeon | 1:8ef7820bf777 | 167 | uint8_t do_lcp_terminate(void); |