WIZnet PPPoE application library

Dependents:   WIZnet_PPPoE

How to use??

1. Set MAC address, IP address, Subnet mask, gateway address.

2. Run ppp_start function.

End~

Committer:
hjjeon
Date:
Wed Oct 29 06:17:02 2014 +0000
Revision:
0:7a9cde4dbf0b
WIZnet PPPoE application library

Who changed what in which revision?

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