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 <stdint.h>
hjjeon 0:7a9cde4dbf0b 2 #include "PPPoE.h"
hjjeon 0:7a9cde4dbf0b 3
hjjeon 0:7a9cde4dbf0b 4
hjjeon 0:7a9cde4dbf0b 5 // ID and Password for PAP from main.c
hjjeon 0:7a9cde4dbf0b 6 extern uint8_t pppoe_id[];//={};
hjjeon 0:7a9cde4dbf0b 7 extern uint8_t pppoe_id_len;
hjjeon 0:7a9cde4dbf0b 8 extern uint8_t pppoe_ip[];//={};
hjjeon 0:7a9cde4dbf0b 9 extern uint8_t pppoe_pdns[];//={};
hjjeon 0:7a9cde4dbf0b 10 extern uint8_t pppoe_sdns[];//={};
hjjeon 0:7a9cde4dbf0b 11 extern uint8_t pppoe_pw[];//={};
hjjeon 0:7a9cde4dbf0b 12 extern uint8_t pppoe_pw_len;
hjjeon 0:7a9cde4dbf0b 13
hjjeon 0:7a9cde4dbf0b 14
hjjeon 0:7a9cde4dbf0b 15 //IPCP Reject flag
hjjeon 0:7a9cde4dbf0b 16 uint8_t ip_rjt;
hjjeon 0:7a9cde4dbf0b 17 uint8_t pdns_rjt;
hjjeon 0:7a9cde4dbf0b 18 uint8_t sdns_rjt;
hjjeon 0:7a9cde4dbf0b 19
hjjeon 0:7a9cde4dbf0b 20
hjjeon 0:7a9cde4dbf0b 21 // PPPoE Frame structure for send
hjjeon 0:7a9cde4dbf0b 22 PPPMSG PPPMSG_req; // PPPoE frame
hjjeon 0:7a9cde4dbf0b 23 PROTOCOL PPPPROTO; // Tag and Protocol data
hjjeon 0:7a9cde4dbf0b 24
hjjeon 0:7a9cde4dbf0b 25 // TxRx Buffers pointer from main
hjjeon 0:7a9cde4dbf0b 26 uint8_t* buf;
hjjeon 0:7a9cde4dbf0b 27
hjjeon 0:7a9cde4dbf0b 28 // Server MAC and Assigned Session ID and IP address from NAS using PPPoE
hjjeon 0:7a9cde4dbf0b 29 uint8_t NAS_mac[6];
hjjeon 0:7a9cde4dbf0b 30 uint16_t NAS_sessionid = 0;
hjjeon 0:7a9cde4dbf0b 31
hjjeon 0:7a9cde4dbf0b 32 // kind of authentication protocol and algorithm; decided by LCP phase
hjjeon 0:7a9cde4dbf0b 33 // Authentication protocol : PAP - 0xC023, CHAP - 0xC223
hjjeon 0:7a9cde4dbf0b 34 // Algorithm : MD5 - 0x05, MS-CHAP - 0x80, MS-CHAP-V2 - 0x81
hjjeon 0:7a9cde4dbf0b 35 uint16_t auth_protocol;
hjjeon 0:7a9cde4dbf0b 36 uint8_t chap_algorithm;
hjjeon 0:7a9cde4dbf0b 37
hjjeon 0:7a9cde4dbf0b 38 // For MD5 calculation
hjjeon 0:7a9cde4dbf0b 39 MD5_CTX context;
hjjeon 0:7a9cde4dbf0b 40 uint8_t digest[16];
hjjeon 0:7a9cde4dbf0b 41
hjjeon 0:7a9cde4dbf0b 42 // Identifier for PPPoE Protocols (increase per message sending)
hjjeon 0:7a9cde4dbf0b 43 uint8_t protocol_id = 0x01;
hjjeon 0:7a9cde4dbf0b 44
hjjeon 0:7a9cde4dbf0b 45
hjjeon 0:7a9cde4dbf0b 46
hjjeon 0:7a9cde4dbf0b 47 uint16_t pppoe_state = PPPoE_DISCOVERY;
hjjeon 0:7a9cde4dbf0b 48 // PPPoE stage control flags
hjjeon 0:7a9cde4dbf0b 49 uint16_t pppoe_control_flag = 0;
hjjeon 0:7a9cde4dbf0b 50
hjjeon 0:7a9cde4dbf0b 51 //PPPoE retry count and send retry count
hjjeon 0:7a9cde4dbf0b 52 uint8_t pppoe_retry_send_count = 0;
hjjeon 0:7a9cde4dbf0b 53 extern uint16_t pppoe_retry_count;
hjjeon 0:7a9cde4dbf0b 54 uint8_t pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 55
hjjeon 0:7a9cde4dbf0b 56
hjjeon 0:7a9cde4dbf0b 57 // Tmp variable
hjjeon 0:7a9cde4dbf0b 58 uint16_t tmp_protocol;
hjjeon 0:7a9cde4dbf0b 59 uint8_t tmp_pcode;
hjjeon 0:7a9cde4dbf0b 60
hjjeon 0:7a9cde4dbf0b 61 PPPOEClient::PPPOEClient()
hjjeon 0:7a9cde4dbf0b 62 {
hjjeon 0:7a9cde4dbf0b 63 eth = WIZnet_Chip::getInstance();
hjjeon 0:7a9cde4dbf0b 64 }
hjjeon 0:7a9cde4dbf0b 65
hjjeon 0:7a9cde4dbf0b 66
hjjeon 0:7a9cde4dbf0b 67 void PPPOEClient::set_pppinfo(uint8_t * nas_mac, uint8_t * ppp_ip, uint16_t nas_sessionid)
hjjeon 0:7a9cde4dbf0b 68 {
hjjeon 0:7a9cde4dbf0b 69
hjjeon 0:7a9cde4dbf0b 70 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 71 uint8_t str[8];//debug var
hjjeon 0:7a9cde4dbf0b 72 uint16_t psid;
hjjeon 0:7a9cde4dbf0b 73
hjjeon 0:7a9cde4dbf0b 74 printf("set_pppinfo() Start...\r\n");
hjjeon 0:7a9cde4dbf0b 75 #endif
hjjeon 0:7a9cde4dbf0b 76 /* Set PPPoE bit in MR(Common Mode Register) : enable PPPoE */
hjjeon 0:7a9cde4dbf0b 77 eth->setMR(eth->getMR() | MR_PPPOE);
hjjeon 0:7a9cde4dbf0b 78
hjjeon 0:7a9cde4dbf0b 79 // Write PPPoE server's MAC address, Session ID and IP address.
hjjeon 0:7a9cde4dbf0b 80 // must be setted these value.
hjjeon 0:7a9cde4dbf0b 81 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 82 printf("Server's MAC : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\r\n", nas_mac[0], nas_mac[1], nas_mac[2], nas_mac[3], nas_mac[4], nas_mac[5]);
hjjeon 0:7a9cde4dbf0b 83 printf("PPPoE IP : %.3d.%.3d.%.3d.%.3d\r\n", ppp_ip[0], ppp_ip[1], ppp_ip[2], ppp_ip[3]);
hjjeon 0:7a9cde4dbf0b 84 printf("Session ID : 0x%.2x%.2x\r\n", (uint8_t)(nas_sessionid >> 8), (uint8_t)nas_sessionid);
hjjeon 0:7a9cde4dbf0b 85 #endif
hjjeon 0:7a9cde4dbf0b 86
hjjeon 0:7a9cde4dbf0b 87 eth->setPHAR(nas_mac);
hjjeon 0:7a9cde4dbf0b 88 eth->setSIPR(ppp_ip);
hjjeon 0:7a9cde4dbf0b 89 eth->setPSID(nas_sessionid);
hjjeon 0:7a9cde4dbf0b 90
hjjeon 0:7a9cde4dbf0b 91 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 92 eth->getPHAR(str);
hjjeon 0:7a9cde4dbf0b 93 printf( "Read PHAR register : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\r\n", str[0], str[1], str[2], str[3], str[4], str[5]);
hjjeon 0:7a9cde4dbf0b 94 eth->getSIPR(str);
hjjeon 0:7a9cde4dbf0b 95 printf( "Read SIP register : %.3d.%.3d.%.3d.%.3d\r\n", str[0], str[1], str[2], str[3]);
hjjeon 0:7a9cde4dbf0b 96 psid = eth->getPSID();
hjjeon 0:7a9cde4dbf0b 97 printf("Read PSID register : %x\r\n", psid);
hjjeon 0:7a9cde4dbf0b 98 #endif
hjjeon 0:7a9cde4dbf0b 99
hjjeon 0:7a9cde4dbf0b 100 //open socket in pppoe mode
hjjeon 0:7a9cde4dbf0b 101 eth->setPTIMER(0);
hjjeon 0:7a9cde4dbf0b 102
hjjeon 0:7a9cde4dbf0b 103
hjjeon 0:7a9cde4dbf0b 104 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 105 printf("set_pppinfo() End...\r\n");
hjjeon 0:7a9cde4dbf0b 106 #endif
hjjeon 0:7a9cde4dbf0b 107 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 108 printf("pppoe PDNS : %.3d.%.3d.%.3d.%.3d\r\n", pppoe_pdns[0], pppoe_pdns[1], pppoe_pdns[2], pppoe_pdns[3]);
hjjeon 0:7a9cde4dbf0b 109 printf("pppoe SDNS : %.3d.%.3d.%.3d.%.3d\r\n", pppoe_sdns[0], pppoe_sdns[1], pppoe_sdns[2], pppoe_sdns[3]);
hjjeon 0:7a9cde4dbf0b 110 #endif
hjjeon 0:7a9cde4dbf0b 111
hjjeon 0:7a9cde4dbf0b 112 }
hjjeon 0:7a9cde4dbf0b 113
hjjeon 0:7a9cde4dbf0b 114
hjjeon 0:7a9cde4dbf0b 115 void PPPOEClient::ppp_send(void)
hjjeon 0:7a9cde4dbf0b 116 {
hjjeon 0:7a9cde4dbf0b 117 uint8_t *ptr;
hjjeon 0:7a9cde4dbf0b 118 uint8_t sn = 0;
hjjeon 0:7a9cde4dbf0b 119 uint16_t tmp16 = 0;
hjjeon 0:7a9cde4dbf0b 120 uint16_t txbuf_len = 0;
hjjeon 0:7a9cde4dbf0b 121
hjjeon 0:7a9cde4dbf0b 122 txbuf_len = sizeof(PPPMSG_req);
hjjeon 0:7a9cde4dbf0b 123
hjjeon 0:7a9cde4dbf0b 124
hjjeon 0:7a9cde4dbf0b 125
hjjeon 0:7a9cde4dbf0b 126 if(pppoe_state == PPPoE_DISCOVERY)
hjjeon 0:7a9cde4dbf0b 127 ptr = (uint8_t *)&PPPPROTO.opt;
hjjeon 0:7a9cde4dbf0b 128 else
hjjeon 0:7a9cde4dbf0b 129 ptr = (uint8_t *)&PPPPROTO;
hjjeon 0:7a9cde4dbf0b 130
hjjeon 0:7a9cde4dbf0b 131
hjjeon 0:7a9cde4dbf0b 132 // Fill the Tx buffer
hjjeon 0:7a9cde4dbf0b 133 //memcpy(txbuf, (uint8_t *)&PPPMSG_req, txbuf_len);
hjjeon 0:7a9cde4dbf0b 134 memcpy(buf, (uint8_t *)&PPPMSG_req, txbuf_len);
hjjeon 0:7a9cde4dbf0b 135 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 136 tmp16 = 0;
hjjeon 0:7a9cde4dbf0b 137 tmp16 = (PPPMSG_req.len & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 138 tmp16 |= ((PPPMSG_req.len >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 139
hjjeon 0:7a9cde4dbf0b 140 //memcpy(txbuf + txbuf_len, ptr, tmp16);
hjjeon 0:7a9cde4dbf0b 141 memcpy(buf + txbuf_len, ptr, tmp16);
hjjeon 0:7a9cde4dbf0b 142 txbuf_len += tmp16;
hjjeon 0:7a9cde4dbf0b 143
hjjeon 0:7a9cde4dbf0b 144 #ifdef __DEF_PPP_DBG2__
hjjeon 0:7a9cde4dbf0b 145 printf("Send data : ");
hjjeon 0:7a9cde4dbf0b 146 for(i=0; i<txbuf_len; i++)
hjjeon 0:7a9cde4dbf0b 147 {
hjjeon 0:7a9cde4dbf0b 148 if((i % 16) == 0) printf("\r\n");
hjjeon 0:7a9cde4dbf0b 149 printf("%.2x ", buf[i]);
hjjeon 0:7a9cde4dbf0b 150 }
hjjeon 0:7a9cde4dbf0b 151 printf("\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 152 #endif
hjjeon 0:7a9cde4dbf0b 153 // Send MACRAW data
hjjeon 0:7a9cde4dbf0b 154 eth->send(sn, (char*)buf, txbuf_len);
hjjeon 0:7a9cde4dbf0b 155 //setSn_CR(sn, Sn_CR_SEND);
hjjeon 0:7a9cde4dbf0b 156 eth->setSn_CR(sn, Sn_CR_SEND);
hjjeon 0:7a9cde4dbf0b 157 while( eth->getSn_CR(sn) ) ;
hjjeon 0:7a9cde4dbf0b 158 }
hjjeon 0:7a9cde4dbf0b 159
hjjeon 0:7a9cde4dbf0b 160
hjjeon 0:7a9cde4dbf0b 161 void PPPOEClient::ppp_recv( uint16_t received_len )
hjjeon 0:7a9cde4dbf0b 162 {
hjjeon 0:7a9cde4dbf0b 163
hjjeon 0:7a9cde4dbf0b 164 uint16_t i;
hjjeon 0:7a9cde4dbf0b 165 uint8_t sn = 0;
hjjeon 0:7a9cde4dbf0b 166 uint8_t head[2] ={0,};
hjjeon 0:7a9cde4dbf0b 167
hjjeon 0:7a9cde4dbf0b 168 uint16_t ethertype = 0;
hjjeon 0:7a9cde4dbf0b 169 uint8_t pppoecode = 0;
hjjeon 0:7a9cde4dbf0b 170 uint16_t taglen = 0;
hjjeon 0:7a9cde4dbf0b 171 uint16_t tagname;
hjjeon 0:7a9cde4dbf0b 172
hjjeon 0:7a9cde4dbf0b 173 uint8_t get_protocol_id = 0;
hjjeon 0:7a9cde4dbf0b 174 uint16_t t_idx = 0, acknak_idx = 0, rjt_idx = 0;
hjjeon 0:7a9cde4dbf0b 175 uint16_t ppp_tag_len = 0, getlen = 0, opt_len = 0;
hjjeon 0:7a9cde4dbf0b 176 uint8_t acknak_opt[OPTMSG_LEN];
hjjeon 0:7a9cde4dbf0b 177 uint8_t rjt_opt[OPTMSG_LEN];
hjjeon 0:7a9cde4dbf0b 178 uint8_t opt_code;
hjjeon 0:7a9cde4dbf0b 179 uint8_t ppp_code;
hjjeon 0:7a9cde4dbf0b 180
hjjeon 0:7a9cde4dbf0b 181 uint8_t str[OPTMSG_LEN];
hjjeon 0:7a9cde4dbf0b 182 uint16_t str_len = 0;
hjjeon 0:7a9cde4dbf0b 183 uint8_t tmp8 = 0;
hjjeon 0:7a9cde4dbf0b 184 uint8_t mac[6];
hjjeon 0:7a9cde4dbf0b 185
hjjeon 0:7a9cde4dbf0b 186 //reset servicename flag
hjjeon 0:7a9cde4dbf0b 187 pppoe_control_flag = pppoe_control_flag & ~FLAG_PADO_SERVICENAME;
hjjeon 0:7a9cde4dbf0b 188
hjjeon 0:7a9cde4dbf0b 189
hjjeon 0:7a9cde4dbf0b 190 //getSHAR(mac);
hjjeon 0:7a9cde4dbf0b 191 eth->getSHAR(mac);
hjjeon 0:7a9cde4dbf0b 192
hjjeon 0:7a9cde4dbf0b 193 // MACRAW Receive
hjjeon 0:7a9cde4dbf0b 194 //receive header(packet length) of macraw packet
hjjeon 0:7a9cde4dbf0b 195
hjjeon 0:7a9cde4dbf0b 196 eth->recv(sn, (char*) head, 2);
hjjeon 0:7a9cde4dbf0b 197
hjjeon 0:7a9cde4dbf0b 198 eth->setSn_CR(sn,Sn_CR_RECV);
hjjeon 0:7a9cde4dbf0b 199
hjjeon 0:7a9cde4dbf0b 200 while( eth->getSn_CR(sn) ) ;
hjjeon 0:7a9cde4dbf0b 201
hjjeon 0:7a9cde4dbf0b 202 received_len = 0;
hjjeon 0:7a9cde4dbf0b 203 received_len = head[0] << 8;
hjjeon 0:7a9cde4dbf0b 204 received_len = received_len | head[1];
hjjeon 0:7a9cde4dbf0b 205 received_len = received_len - 2;
hjjeon 0:7a9cde4dbf0b 206
hjjeon 0:7a9cde4dbf0b 207
hjjeon 0:7a9cde4dbf0b 208 eth->recv(sn, (char*) buf, received_len);
hjjeon 0:7a9cde4dbf0b 209
hjjeon 0:7a9cde4dbf0b 210 eth->setSn_CR(sn,Sn_CR_RECV);
hjjeon 0:7a9cde4dbf0b 211
hjjeon 0:7a9cde4dbf0b 212 while( eth->getSn_CR(sn) ) ;
hjjeon 0:7a9cde4dbf0b 213
hjjeon 0:7a9cde4dbf0b 214
hjjeon 0:7a9cde4dbf0b 215 // Check the MAC in received packet
hjjeon 0:7a9cde4dbf0b 216 tmp8 = buf[0] - mac[0] + buf[1] - mac[1] + buf[2] - mac[2] + buf[3] - mac[3] + buf[4] - mac[4] + buf[5] - mac[5];
hjjeon 0:7a9cde4dbf0b 217
hjjeon 0:7a9cde4dbf0b 218 if(tmp8==0)
hjjeon 0:7a9cde4dbf0b 219 {
hjjeon 0:7a9cde4dbf0b 220 #ifdef __DEF_PPP_DBG2__
hjjeon 0:7a9cde4dbf0b 221 printf("Received packet :");
hjjeon 0:7a9cde4dbf0b 222 for(i = 0; i < received_len; i++)
hjjeon 0:7a9cde4dbf0b 223 {
hjjeon 0:7a9cde4dbf0b 224 if((i % 16) == 0) printf("\r\n");
hjjeon 0:7a9cde4dbf0b 225 printf("%.2x ", buf[i]);
hjjeon 0:7a9cde4dbf0b 226 }
hjjeon 0:7a9cde4dbf0b 227 printf("\r\n");
hjjeon 0:7a9cde4dbf0b 228 #endif
hjjeon 0:7a9cde4dbf0b 229 ethertype = buf[12];
hjjeon 0:7a9cde4dbf0b 230 ethertype = (ethertype << 8) + buf[13];
hjjeon 0:7a9cde4dbf0b 231
hjjeon 0:7a9cde4dbf0b 232 pppoecode = buf[15];
hjjeon 0:7a9cde4dbf0b 233
hjjeon 0:7a9cde4dbf0b 234 taglen = buf[18];
hjjeon 0:7a9cde4dbf0b 235 taglen = (taglen << 8) + buf[19];
hjjeon 0:7a9cde4dbf0b 236 ppp_code = buf[22];
hjjeon 0:7a9cde4dbf0b 237
hjjeon 0:7a9cde4dbf0b 238 //Check the Ether-Type and Code in received packet
hjjeon 0:7a9cde4dbf0b 239 t_idx = 20;
hjjeon 0:7a9cde4dbf0b 240 switch (ethertype)
hjjeon 0:7a9cde4dbf0b 241 {
hjjeon 0:7a9cde4dbf0b 242 case PPPoE_DISCOVERY :
hjjeon 0:7a9cde4dbf0b 243 if (pppoecode == PPPoE_PADO)
hjjeon 0:7a9cde4dbf0b 244 {
hjjeon 0:7a9cde4dbf0b 245 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 246 printf("PPPoE Discovery: PADO received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 247 #endif
hjjeon 0:7a9cde4dbf0b 248 for(i = 0; i < 6; i++) NAS_mac[i] = buf[6+i];
hjjeon 0:7a9cde4dbf0b 249 // PPPoE Frame
hjjeon 0:7a9cde4dbf0b 250 while(taglen)
hjjeon 0:7a9cde4dbf0b 251 {
hjjeon 0:7a9cde4dbf0b 252 tagname = buf[t_idx];
hjjeon 0:7a9cde4dbf0b 253 tagname = (tagname << 8) + buf[t_idx+1];
hjjeon 0:7a9cde4dbf0b 254
hjjeon 0:7a9cde4dbf0b 255 ppp_tag_len = buf[t_idx+2];
hjjeon 0:7a9cde4dbf0b 256 ppp_tag_len = (ppp_tag_len << 8) + buf[t_idx+3];
hjjeon 0:7a9cde4dbf0b 257
hjjeon 0:7a9cde4dbf0b 258 // Check option field overflow
hjjeon 0:7a9cde4dbf0b 259 // (OPTMSG_LEN defined maximum option field length.)
hjjeon 0:7a9cde4dbf0b 260 if((acknak_idx + (ppp_tag_len+4)) > OPTMSG_LEN)
hjjeon 0:7a9cde4dbf0b 261 {
hjjeon 0:7a9cde4dbf0b 262 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 263 printf("PPPoE Protocol option field overflow occuerd!\r\n");
hjjeon 0:7a9cde4dbf0b 264 #endif
hjjeon 0:7a9cde4dbf0b 265 break;
hjjeon 0:7a9cde4dbf0b 266 }
hjjeon 0:7a9cde4dbf0b 267 else
hjjeon 0:7a9cde4dbf0b 268 {
hjjeon 0:7a9cde4dbf0b 269 switch(tagname)
hjjeon 0:7a9cde4dbf0b 270 {
hjjeon 0:7a9cde4dbf0b 271 case PPPoED_SERVICE_NAME :
hjjeon 0:7a9cde4dbf0b 272 if ((pppoe_control_flag & FLAG_PADO_SERVICENAME) == 0)
hjjeon 0:7a9cde4dbf0b 273 {
hjjeon 0:7a9cde4dbf0b 274 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], ppp_tag_len+4);
hjjeon 0:7a9cde4dbf0b 275 acknak_idx += (ppp_tag_len+4);
hjjeon 0:7a9cde4dbf0b 276 pppoe_control_flag = pppoe_control_flag | FLAG_PADO_SERVICENAME;
hjjeon 0:7a9cde4dbf0b 277 }
hjjeon 0:7a9cde4dbf0b 278 break;
hjjeon 0:7a9cde4dbf0b 279 case PPPoED_HOST_UNIQ :
hjjeon 0:7a9cde4dbf0b 280 case PPPoED_AC_COOKIE :
hjjeon 0:7a9cde4dbf0b 281 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], ppp_tag_len+4);
hjjeon 0:7a9cde4dbf0b 282 acknak_idx += (ppp_tag_len+4);
hjjeon 0:7a9cde4dbf0b 283 break;
hjjeon 0:7a9cde4dbf0b 284 default :
hjjeon 0:7a9cde4dbf0b 285 //case PPPoED_AC_NAME :
hjjeon 0:7a9cde4dbf0b 286 break;
hjjeon 0:7a9cde4dbf0b 287 }
hjjeon 0:7a9cde4dbf0b 288 }
hjjeon 0:7a9cde4dbf0b 289 t_idx += (ppp_tag_len+4);
hjjeon 0:7a9cde4dbf0b 290 taglen -= (ppp_tag_len+4);
hjjeon 0:7a9cde4dbf0b 291 }
hjjeon 0:7a9cde4dbf0b 292
hjjeon 0:7a9cde4dbf0b 293 memcpy(&PPPPROTO.opt[0], &acknak_opt[0], acknak_idx);
hjjeon 0:7a9cde4dbf0b 294
hjjeon 0:7a9cde4dbf0b 295 for(i = 0; i < 6; i++)
hjjeon 0:7a9cde4dbf0b 296 {
hjjeon 0:7a9cde4dbf0b 297 PPPMSG_req.dst_mac[i] = NAS_mac[i]; // NAS MAC address
hjjeon 0:7a9cde4dbf0b 298 }
hjjeon 0:7a9cde4dbf0b 299 PPPMSG_req.frame_code = PPPoE_PADR;
hjjeon 0:7a9cde4dbf0b 300 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 301 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 302 PPPMSG_req.len = (acknak_idx & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 303 PPPMSG_req.len |= ((acknak_idx >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 304
hjjeon 0:7a9cde4dbf0b 305 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 306 printf("PPPoE Discovery : PADR send\r\n");
hjjeon 0:7a9cde4dbf0b 307 #endif
hjjeon 0:7a9cde4dbf0b 308 ppp_send();
hjjeon 0:7a9cde4dbf0b 309 pppoe_control_flag = pppoe_control_flag | FLAG_DISCOVERY_RCV_PADO;
hjjeon 0:7a9cde4dbf0b 310
hjjeon 0:7a9cde4dbf0b 311
hjjeon 0:7a9cde4dbf0b 312 }
hjjeon 0:7a9cde4dbf0b 313 else if(pppoecode == PPPoE_PADS)
hjjeon 0:7a9cde4dbf0b 314 {
hjjeon 0:7a9cde4dbf0b 315 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 316 printf("PPPoE Discovery: PADS received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 317 #endif
hjjeon 0:7a9cde4dbf0b 318 pppoe_control_flag = pppoe_control_flag | FLAG_DISCOVERY_RCV_PADS;
hjjeon 0:7a9cde4dbf0b 319
hjjeon 0:7a9cde4dbf0b 320 NAS_sessionid = buf[16];
hjjeon 0:7a9cde4dbf0b 321 NAS_sessionid = (NAS_sessionid << 8) + buf[17];
hjjeon 0:7a9cde4dbf0b 322 }
hjjeon 0:7a9cde4dbf0b 323 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 324 else printf("Not necessary packet received\r\n");
hjjeon 0:7a9cde4dbf0b 325 #endif
hjjeon 0:7a9cde4dbf0b 326 break;
hjjeon 0:7a9cde4dbf0b 327 case PPPoE_SESSION :
hjjeon 0:7a9cde4dbf0b 328
hjjeon 0:7a9cde4dbf0b 329 // Process LCP
hjjeon 0:7a9cde4dbf0b 330 if ((buf[20] == 0xc0) && (buf[21] == 0x21))
hjjeon 0:7a9cde4dbf0b 331 {
hjjeon 0:7a9cde4dbf0b 332 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 333 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 334 PPPPROTO.protocol = (PPPoE_LCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 335 PPPPROTO.protocol |= ((PPPoE_LCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 336
hjjeon 0:7a9cde4dbf0b 337 switch (ppp_code)
hjjeon 0:7a9cde4dbf0b 338 {
hjjeon 0:7a9cde4dbf0b 339 // when lcp_cr_rcv flag set && lcp_cr_sent flag set, goto PAP or CHAP
hjjeon 0:7a9cde4dbf0b 340 case PPP_CONFIG_REQ : //Configuration Request receive, and then ack or reject send
hjjeon 0:7a9cde4dbf0b 341 // when ack sent, lcp_cr_rcv flag set
hjjeon 0:7a9cde4dbf0b 342 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 343 printf("PPPoE Session LCP: Configure-Request received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 344 #endif
hjjeon 0:7a9cde4dbf0b 345 get_protocol_id = buf[23];
hjjeon 0:7a9cde4dbf0b 346 getlen = buf[24];
hjjeon 0:7a9cde4dbf0b 347 getlen = (getlen<<8) + buf[25];
hjjeon 0:7a9cde4dbf0b 348
hjjeon 0:7a9cde4dbf0b 349 getlen -= 4;
hjjeon 0:7a9cde4dbf0b 350 t_idx = 26;
hjjeon 0:7a9cde4dbf0b 351 while (getlen)
hjjeon 0:7a9cde4dbf0b 352 {
hjjeon 0:7a9cde4dbf0b 353 opt_code = buf[t_idx];
hjjeon 0:7a9cde4dbf0b 354 opt_len = buf[t_idx+1];
hjjeon 0:7a9cde4dbf0b 355 // Check option field overflow
hjjeon 0:7a9cde4dbf0b 356 // (OPTMSG_LEN defined maximum option field length.)
hjjeon 0:7a9cde4dbf0b 357 if((acknak_idx + opt_len) > OPTMSG_LEN || (rjt_idx + opt_len) > OPTMSG_LEN)
hjjeon 0:7a9cde4dbf0b 358 {
hjjeon 0:7a9cde4dbf0b 359 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 360 printf("PPPoE Protocol option field overflow occuerd!\r\n");
hjjeon 0:7a9cde4dbf0b 361 #endif
hjjeon 0:7a9cde4dbf0b 362 break;
hjjeon 0:7a9cde4dbf0b 363 }
hjjeon 0:7a9cde4dbf0b 364 else
hjjeon 0:7a9cde4dbf0b 365 {
hjjeon 0:7a9cde4dbf0b 366 switch (opt_code)
hjjeon 0:7a9cde4dbf0b 367 {
hjjeon 0:7a9cde4dbf0b 368 case LCP_AUTH : // Authentication-Protocol
hjjeon 0:7a9cde4dbf0b 369 auth_protocol = buf[t_idx+2];
hjjeon 0:7a9cde4dbf0b 370 auth_protocol = (auth_protocol << 8) + buf[t_idx+3];
hjjeon 0:7a9cde4dbf0b 371 chap_algorithm = buf[t_idx+4];
hjjeon 0:7a9cde4dbf0b 372 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 373 acknak_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 374 break;
hjjeon 0:7a9cde4dbf0b 375 case LCP_MRU : // MRU (Maximum-Receive-Unit)
hjjeon 0:7a9cde4dbf0b 376 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 377 acknak_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 378 break;
hjjeon 0:7a9cde4dbf0b 379 case LCP_MAGICNUM : // Magic-Number
hjjeon 0:7a9cde4dbf0b 380 // opt_code : 0x01, 0x03, 0x05 shared process part
hjjeon 0:7a9cde4dbf0b 381 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 382 acknak_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 383
hjjeon 0:7a9cde4dbf0b 384 break;
hjjeon 0:7a9cde4dbf0b 385 default :
hjjeon 0:7a9cde4dbf0b 386 memcpy(&rjt_opt[rjt_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 387 rjt_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 388 break;
hjjeon 0:7a9cde4dbf0b 389 }
hjjeon 0:7a9cde4dbf0b 390 }
hjjeon 0:7a9cde4dbf0b 391 t_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 392 getlen -= opt_len;
hjjeon 0:7a9cde4dbf0b 393 }
hjjeon 0:7a9cde4dbf0b 394
hjjeon 0:7a9cde4dbf0b 395
hjjeon 0:7a9cde4dbf0b 396
hjjeon 0:7a9cde4dbf0b 397 if (rjt_idx)
hjjeon 0:7a9cde4dbf0b 398 {
hjjeon 0:7a9cde4dbf0b 399 // reject send, then wait cr
hjjeon 0:7a9cde4dbf0b 400 PPPPROTO.pcode = PPP_CONFIG_REJ; // Reject
hjjeon 0:7a9cde4dbf0b 401 memcpy(&PPPPROTO.opt[0], &rjt_opt[0], rjt_idx);
hjjeon 0:7a9cde4dbf0b 402 PPPPROTO.id = get_protocol_id;
hjjeon 0:7a9cde4dbf0b 403
hjjeon 0:7a9cde4dbf0b 404 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 405 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 406 PPPPROTO.len = ((rjt_idx+4) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 407 PPPPROTO.len |= (((rjt_idx+4) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 408
hjjeon 0:7a9cde4dbf0b 409 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 410 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 411 PPPMSG_req.len = ((rjt_idx+6) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 412 PPPMSG_req.len |= (((rjt_idx+6) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 413
hjjeon 0:7a9cde4dbf0b 414 ppp_send();
hjjeon 0:7a9cde4dbf0b 415 }
hjjeon 0:7a9cde4dbf0b 416 else
hjjeon 0:7a9cde4dbf0b 417 {
hjjeon 0:7a9cde4dbf0b 418 // ack send, lcp_cr_rcv flag set
hjjeon 0:7a9cde4dbf0b 419 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 420 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 421 PPPPROTO.protocol = (PPPoE_LCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 422 PPPPROTO.protocol |= ((PPPoE_LCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 423
hjjeon 0:7a9cde4dbf0b 424 PPPPROTO.pcode = PPP_CONFIG_ACK; // ack
hjjeon 0:7a9cde4dbf0b 425 memcpy(&PPPPROTO.opt[0], &acknak_opt[0], acknak_idx);
hjjeon 0:7a9cde4dbf0b 426 PPPPROTO.id = get_protocol_id;
hjjeon 0:7a9cde4dbf0b 427 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 428 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 429 PPPPROTO.len = ((acknak_idx+4) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 430 PPPPROTO.len |= (((acknak_idx+4) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 431
hjjeon 0:7a9cde4dbf0b 432 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 433 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 434 PPPMSG_req.len = ((acknak_idx+6) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 435 PPPMSG_req.len |= (((acknak_idx+6) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 436 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 437 printf("LCP Configuration Ack send\r\n");
hjjeon 0:7a9cde4dbf0b 438 #endif
hjjeon 0:7a9cde4dbf0b 439 ppp_send();//ack send
hjjeon 0:7a9cde4dbf0b 440 pppoe_control_flag = pppoe_control_flag | FLAG_LCP_CR_RCV;
hjjeon 0:7a9cde4dbf0b 441
hjjeon 0:7a9cde4dbf0b 442 }
hjjeon 0:7a9cde4dbf0b 443 break;
hjjeon 0:7a9cde4dbf0b 444
hjjeon 0:7a9cde4dbf0b 445
hjjeon 0:7a9cde4dbf0b 446 case PPP_CONFIG_ACK : //ack, then lcp_cr_sent flag set
hjjeon 0:7a9cde4dbf0b 447 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 448 printf("PPPoE Session LCP: Configuration Ack received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 449 #endif
hjjeon 0:7a9cde4dbf0b 450 pppoe_control_flag = pppoe_control_flag | FLAG_LCP_CR_SNT;
hjjeon 0:7a9cde4dbf0b 451 break;
hjjeon 0:7a9cde4dbf0b 452
hjjeon 0:7a9cde4dbf0b 453
hjjeon 0:7a9cde4dbf0b 454 case PPP_TERM_ACK :
hjjeon 0:7a9cde4dbf0b 455 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 456 printf("Termination Ack received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 457 #endif
hjjeon 0:7a9cde4dbf0b 458 pppoe_control_flag = pppoe_control_flag | FLAG_TERMINATION_ACK_RCV;
hjjeon 0:7a9cde4dbf0b 459
hjjeon 0:7a9cde4dbf0b 460 break;
hjjeon 0:7a9cde4dbf0b 461
hjjeon 0:7a9cde4dbf0b 462
hjjeon 0:7a9cde4dbf0b 463 case PPP_TERM_REQ:
hjjeon 0:7a9cde4dbf0b 464 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 465 printf("Termination request received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 466 #endif
hjjeon 0:7a9cde4dbf0b 467
hjjeon 0:7a9cde4dbf0b 468 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 469 PPPMSG_req.ether_type = 0;
hjjeon 0:7a9cde4dbf0b 470 PPPMSG_req.ether_type = (PPPoE_SESSION & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 471 PPPMSG_req.ether_type |= ((PPPoE_SESSION >> 8) & 0xFF);// session
hjjeon 0:7a9cde4dbf0b 472
hjjeon 0:7a9cde4dbf0b 473 PPPMSG_req.frame_code = 0x00; // session data
hjjeon 0:7a9cde4dbf0b 474 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 475 PPPMSG_req.session_id = 0;
hjjeon 0:7a9cde4dbf0b 476 PPPMSG_req.session_id = (NAS_sessionid & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 477 PPPMSG_req.session_id |= ((NAS_sessionid >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 478
hjjeon 0:7a9cde4dbf0b 479 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 480 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 481 PPPPROTO.protocol = (PPPoE_LCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 482 PPPPROTO.protocol |= ((PPPoE_LCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 483
hjjeon 0:7a9cde4dbf0b 484 PPPPROTO.pcode = PPP_TERM_ACK; // Terminate-ack
hjjeon 0:7a9cde4dbf0b 485
hjjeon 0:7a9cde4dbf0b 486 PPPPROTO.opt[0] = 0x00; // Magic number
hjjeon 0:7a9cde4dbf0b 487 PPPPROTO.opt[1] = 0x01;
hjjeon 0:7a9cde4dbf0b 488 PPPPROTO.opt[2] = 0x02;
hjjeon 0:7a9cde4dbf0b 489 PPPPROTO.opt[3] = 0x03;
hjjeon 0:7a9cde4dbf0b 490
hjjeon 0:7a9cde4dbf0b 491 PPPPROTO.id = protocol_id++;
hjjeon 0:7a9cde4dbf0b 492 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 493 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 494 PPPPROTO.len = (8 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 495 PPPPROTO.len |= ((8 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 496
hjjeon 0:7a9cde4dbf0b 497 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 498 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 499 PPPMSG_req.len = (10 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 500 PPPMSG_req.len |= ((10 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 501
hjjeon 0:7a9cde4dbf0b 502 pppoe_control_flag = pppoe_control_flag | FLAG_TERMINATION_REQ_RCV;
hjjeon 0:7a9cde4dbf0b 503
hjjeon 0:7a9cde4dbf0b 504 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 505 printf("Termination ack send\r\n");
hjjeon 0:7a9cde4dbf0b 506 #endif
hjjeon 0:7a9cde4dbf0b 507 ppp_send();
hjjeon 0:7a9cde4dbf0b 508
hjjeon 0:7a9cde4dbf0b 509 break;
hjjeon 0:7a9cde4dbf0b 510
hjjeon 0:7a9cde4dbf0b 511
hjjeon 0:7a9cde4dbf0b 512 /*
hjjeon 0:7a9cde4dbf0b 513 * Notice : This part is not implemented.
hjjeon 0:7a9cde4dbf0b 514 * If necessary, please implement more for reply for request from NAS.
hjjeon 0:7a9cde4dbf0b 515 *
hjjeon 0:7a9cde4dbf0b 516 case 0x04 : //reject
hjjeon 0:7a9cde4dbf0b 517 break;
hjjeon 0:7a9cde4dbf0b 518
hjjeon 0:7a9cde4dbf0b 519 case 0x09 : // Echo-Response
hjjeon 0:7a9cde4dbf0b 520 // Backup
hjjeon 0:7a9cde4dbf0b 521 tmp_protocol = PPPPROTO.protocol;
hjjeon 0:7a9cde4dbf0b 522 tmp_pcode = PPPPROTO.pcode;
hjjeon 0:7a9cde4dbf0b 523
hjjeon 0:7a9cde4dbf0b 524 PPPPROTO.protocol = PPPoE_LCP;
hjjeon 0:7a9cde4dbf0b 525 PPPPROTO.pcode = PPP_ECHO_REP;
hjjeon 0:7a9cde4dbf0b 526
hjjeon 0:7a9cde4dbf0b 527 PPPPROTO.id = buf[23];
hjjeon 0:7a9cde4dbf0b 528
hjjeon 0:7a9cde4dbf0b 529 PPPPROTO.len = buf[24];
hjjeon 0:7a9cde4dbf0b 530 PPPPROTO.len = (PPPPROTO.len << 8) + buf[25];
hjjeon 0:7a9cde4dbf0b 531
hjjeon 0:7a9cde4dbf0b 532 memcpy(&PPPPROTO.opt[0], &buf[26], PPPPROTO.len-4);
hjjeon 0:7a9cde4dbf0b 533 ppp_send();
hjjeon 0:7a9cde4dbf0b 534
hjjeon 0:7a9cde4dbf0b 535 // Recover
hjjeon 0:7a9cde4dbf0b 536 PPPPROTO.protocol = tmp_protocol;
hjjeon 0:7a9cde4dbf0b 537 PPPPROTO.pcode = tmp_pcode;
hjjeon 0:7a9cde4dbf0b 538 break;
hjjeon 0:7a9cde4dbf0b 539 */
hjjeon 0:7a9cde4dbf0b 540
hjjeon 0:7a9cde4dbf0b 541 default:
hjjeon 0:7a9cde4dbf0b 542 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 543 printf("Not necessary packet received\r\n");
hjjeon 0:7a9cde4dbf0b 544 #endif
hjjeon 0:7a9cde4dbf0b 545 break;
hjjeon 0:7a9cde4dbf0b 546 }
hjjeon 0:7a9cde4dbf0b 547 }
hjjeon 0:7a9cde4dbf0b 548 // Process PAP
hjjeon 0:7a9cde4dbf0b 549 else if ((buf[20] == 0xc0) && (buf[21] == 0x23))
hjjeon 0:7a9cde4dbf0b 550 {
hjjeon 0:7a9cde4dbf0b 551 if(ppp_code == PPP_CONFIG_ACK) // PPP_CONFIG_ACK = 0x02
hjjeon 0:7a9cde4dbf0b 552 {
hjjeon 0:7a9cde4dbf0b 553 pppoe_control_flag = pppoe_control_flag | FLAG_PAP_ACK_RCV;// receice ack
hjjeon 0:7a9cde4dbf0b 554
hjjeon 0:7a9cde4dbf0b 555 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 556 printf("PPPoE Session PAP: Authentication ACK received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 557 #endif
hjjeon 0:7a9cde4dbf0b 558 }
hjjeon 0:7a9cde4dbf0b 559 else if(ppp_code == PPP_TERM_ACK)
hjjeon 0:7a9cde4dbf0b 560 {
hjjeon 0:7a9cde4dbf0b 561 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 562 printf("Termination Ack received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 563 #endif
hjjeon 0:7a9cde4dbf0b 564 pppoe_control_flag = pppoe_control_flag | FLAG_TERMINATION_ACK_RCV;
hjjeon 0:7a9cde4dbf0b 565 }
hjjeon 0:7a9cde4dbf0b 566 }
hjjeon 0:7a9cde4dbf0b 567 // Process CHAP
hjjeon 0:7a9cde4dbf0b 568
hjjeon 0:7a9cde4dbf0b 569 else if ((buf[20] == 0xc2) && (buf[21] == 0x23))
hjjeon 0:7a9cde4dbf0b 570 {
hjjeon 0:7a9cde4dbf0b 571 switch(chap_algorithm)
hjjeon 0:7a9cde4dbf0b 572 {
hjjeon 0:7a9cde4dbf0b 573 case MD5 : // 0x05, MD5
hjjeon 0:7a9cde4dbf0b 574
hjjeon 0:7a9cde4dbf0b 575 get_protocol_id = buf[23];
hjjeon 0:7a9cde4dbf0b 576 // length of [code ~ packet end]
hjjeon 0:7a9cde4dbf0b 577 getlen = buf[24];
hjjeon 0:7a9cde4dbf0b 578 getlen = (getlen<<8) + buf[25];
hjjeon 0:7a9cde4dbf0b 579 // so, 'CHAP data' length is getlen - length of [code(1), ID(1), Length(2)].
hjjeon 0:7a9cde4dbf0b 580 getlen -= 4; //PPP CHAP total(getlen) - 4(header) = data length(value size(1) + value + name )
hjjeon 0:7a9cde4dbf0b 581 t_idx = 26;
hjjeon 0:7a9cde4dbf0b 582
hjjeon 0:7a9cde4dbf0b 583 switch(ppp_code)
hjjeon 0:7a9cde4dbf0b 584 {
hjjeon 0:7a9cde4dbf0b 585 case 0x01 :
hjjeon 0:7a9cde4dbf0b 586 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 587 printf("PPPoE Session CHAP: CHAP Challenge received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 588 #endif
hjjeon 0:7a9cde4dbf0b 589 // Challenge, parse the packet and return 'Response' to NAS
hjjeon 0:7a9cde4dbf0b 590 //-- MD5 calc input consist of ID(1), password(pwlen) and Challenge value(16).
hjjeon 0:7a9cde4dbf0b 591
hjjeon 0:7a9cde4dbf0b 592 //-- buf[t_idx] => CV(challenge value) size, buf[t_idx+1] => start byte of CV
hjjeon 0:7a9cde4dbf0b 593
hjjeon 0:7a9cde4dbf0b 594 memcpy(&str[str_len], &get_protocol_id, 1); // ID(value)
hjjeon 0:7a9cde4dbf0b 595 str_len += 1;
hjjeon 0:7a9cde4dbf0b 596 memcpy(&str[str_len], &pppoe_pw[0], pppoe_pw_len); // user password
hjjeon 0:7a9cde4dbf0b 597 str_len += pppoe_pw_len;
hjjeon 0:7a9cde4dbf0b 598 memcpy(&str[str_len], &buf[t_idx+1], buf[t_idx]); // CV(value)
hjjeon 0:7a9cde4dbf0b 599 str_len += buf[t_idx];
hjjeon 0:7a9cde4dbf0b 600
hjjeon 0:7a9cde4dbf0b 601 /*
hjjeon 0:7a9cde4dbf0b 602 memcpy(&str[str_len], &buf[t_idx+1], buf[t_idx]); // CV(value)
hjjeon 0:7a9cde4dbf0b 603 str_len += buf[t_idx];
hjjeon 0:7a9cde4dbf0b 604 memcpy(&str[str_len], &pppoe_pw, pppoe_pw_len); // user password
hjjeon 0:7a9cde4dbf0b 605 str_len += pppoe_pw_len;
hjjeon 0:7a9cde4dbf0b 606 memcpy(&str[str_len], &pppoe_id, pppoe_id_len); // user id
hjjeon 0:7a9cde4dbf0b 607 str_len += pppoe_id_len;
hjjeon 0:7a9cde4dbf0b 608 */
hjjeon 0:7a9cde4dbf0b 609
hjjeon 0:7a9cde4dbf0b 610 /*
hjjeon 0:7a9cde4dbf0b 611 MD5Init(&context);
hjjeon 0:7a9cde4dbf0b 612 MD5Update(&context, str, str_len);
hjjeon 0:7a9cde4dbf0b 613 MD5Final(digest, &context);
hjjeon 0:7a9cde4dbf0b 614 */
hjjeon 0:7a9cde4dbf0b 615
hjjeon 0:7a9cde4dbf0b 616
hjjeon 0:7a9cde4dbf0b 617 MD5Init(&context);
hjjeon 0:7a9cde4dbf0b 618 MD5Update(&context, &get_protocol_id, 1);
hjjeon 0:7a9cde4dbf0b 619 MD5Update(&context, pppoe_pw, pppoe_pw_len);
hjjeon 0:7a9cde4dbf0b 620 MD5Update(&context, (unsigned char *)(&buf[t_idx+1]), 16);
hjjeon 0:7a9cde4dbf0b 621 MD5Final(digest, &context);
hjjeon 0:7a9cde4dbf0b 622
hjjeon 0:7a9cde4dbf0b 623 // making response msg
hjjeon 0:7a9cde4dbf0b 624 acknak_opt[acknak_idx++] = CV_HV_LEN; // fixed value, 16
hjjeon 0:7a9cde4dbf0b 625 memcpy(&acknak_opt[acknak_idx], &digest, CV_HV_LEN);
hjjeon 0:7a9cde4dbf0b 626 acknak_idx += CV_HV_LEN;
hjjeon 0:7a9cde4dbf0b 627
hjjeon 0:7a9cde4dbf0b 628
hjjeon 0:7a9cde4dbf0b 629 memcpy(&acknak_opt[acknak_idx], &pppoe_id, pppoe_id_len); // Name: User ID
hjjeon 0:7a9cde4dbf0b 630 acknak_idx += pppoe_id_len;
hjjeon 0:7a9cde4dbf0b 631
hjjeon 0:7a9cde4dbf0b 632
hjjeon 0:7a9cde4dbf0b 633 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 634 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 635 PPPPROTO.protocol = (PPPoE_CHAP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 636 PPPPROTO.protocol |= ((PPPoE_CHAP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 637
hjjeon 0:7a9cde4dbf0b 638 PPPPROTO.pcode = 0x02; // response
hjjeon 0:7a9cde4dbf0b 639 PPPPROTO.id = get_protocol_id;
hjjeon 0:7a9cde4dbf0b 640 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 641 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 642 PPPPROTO.len = ((acknak_idx + 4) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 643 PPPPROTO.len |= (((acknak_idx + 4) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 644
hjjeon 0:7a9cde4dbf0b 645 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 646 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 647 PPPMSG_req.len = ((acknak_idx + 6) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 648 PPPMSG_req.len |= (((acknak_idx + 6) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 649
hjjeon 0:7a9cde4dbf0b 650
hjjeon 0:7a9cde4dbf0b 651 memcpy(&PPPPROTO.opt[0], &acknak_opt[0], acknak_idx);
hjjeon 0:7a9cde4dbf0b 652 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 653 printf("CHAP response MSG send \r\n\r\n");
hjjeon 0:7a9cde4dbf0b 654 #endif
hjjeon 0:7a9cde4dbf0b 655 ppp_send();
hjjeon 0:7a9cde4dbf0b 656 break;
hjjeon 0:7a9cde4dbf0b 657
hjjeon 0:7a9cde4dbf0b 658
hjjeon 0:7a9cde4dbf0b 659 case 0x03 : // PPP_SUCCESS
hjjeon 0:7a9cde4dbf0b 660 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 661 printf("PPPoE Session CHAP: CHAP Succeed packet received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 662 #endif
hjjeon 0:7a9cde4dbf0b 663 pppoe_control_flag = pppoe_control_flag | FLAG_CHAP_SUC_RCV;
hjjeon 0:7a9cde4dbf0b 664
hjjeon 0:7a9cde4dbf0b 665 break;
hjjeon 0:7a9cde4dbf0b 666
hjjeon 0:7a9cde4dbf0b 667
hjjeon 0:7a9cde4dbf0b 668 case 0x04 : // PPP_FAIL
hjjeon 0:7a9cde4dbf0b 669 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 670 printf("PPPoE Session CHAP: CHAP failure packet received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 671 #endif
hjjeon 0:7a9cde4dbf0b 672
hjjeon 0:7a9cde4dbf0b 673 break;
hjjeon 0:7a9cde4dbf0b 674
hjjeon 0:7a9cde4dbf0b 675 default :
hjjeon 0:7a9cde4dbf0b 676 break;
hjjeon 0:7a9cde4dbf0b 677 }
hjjeon 0:7a9cde4dbf0b 678 break;
hjjeon 0:7a9cde4dbf0b 679 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 680 case MS_CHAP : // 0x80, MS-CHAP
hjjeon 0:7a9cde4dbf0b 681 case MS_CHAP_V2 : // 0x81, MS-CHAP-V2
hjjeon 0:7a9cde4dbf0b 682 printf("This CHAP Algorithm is not supported : ");
hjjeon 0:7a9cde4dbf0b 683 if(chap_algorithm == MS_CHAP) printf("MS-CHAP\r\n");
hjjeon 0:7a9cde4dbf0b 684 else printf("MS-CHAP-V2\r\n");
hjjeon 0:7a9cde4dbf0b 685 break;
hjjeon 0:7a9cde4dbf0b 686 #endif
hjjeon 0:7a9cde4dbf0b 687 default :
hjjeon 0:7a9cde4dbf0b 688 break;
hjjeon 0:7a9cde4dbf0b 689 }
hjjeon 0:7a9cde4dbf0b 690 }
hjjeon 0:7a9cde4dbf0b 691 // Process IPCP
hjjeon 0:7a9cde4dbf0b 692 else if ((buf[20] == 0x80) && (buf[21] == 0x21))
hjjeon 0:7a9cde4dbf0b 693 {
hjjeon 0:7a9cde4dbf0b 694 switch(ppp_code)
hjjeon 0:7a9cde4dbf0b 695 {
hjjeon 0:7a9cde4dbf0b 696 case PPP_CONFIG_REQ : // cr, send ack
hjjeon 0:7a9cde4dbf0b 697 case PPP_CONFIG_NAK : // nak, save ip addr and send config requset
hjjeon 0:7a9cde4dbf0b 698
hjjeon 0:7a9cde4dbf0b 699 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 700 if(ppp_code == 0x01) printf("PPPoE Session IPCP: Configure-Request received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 701 else if (ppp_code == 0x03) printf("PPPoE Session IPCP: Configure-Nak received\r\n\r\n");
hjjeon 0:7a9cde4dbf0b 702 #endif
hjjeon 0:7a9cde4dbf0b 703 get_protocol_id = buf[23];
hjjeon 0:7a9cde4dbf0b 704 getlen = buf[24];
hjjeon 0:7a9cde4dbf0b 705 getlen = (getlen<<8) + buf[25];
hjjeon 0:7a9cde4dbf0b 706
hjjeon 0:7a9cde4dbf0b 707 getlen -= 4;
hjjeon 0:7a9cde4dbf0b 708 t_idx = 26;
hjjeon 0:7a9cde4dbf0b 709
hjjeon 0:7a9cde4dbf0b 710 while (getlen)
hjjeon 0:7a9cde4dbf0b 711 {
hjjeon 0:7a9cde4dbf0b 712 opt_code = buf[t_idx];
hjjeon 0:7a9cde4dbf0b 713 opt_len = buf[t_idx+1];
hjjeon 0:7a9cde4dbf0b 714
hjjeon 0:7a9cde4dbf0b 715 // Check option field overflow
hjjeon 0:7a9cde4dbf0b 716 // (OPTMSG_LEN defined maximum option field length.)
hjjeon 0:7a9cde4dbf0b 717 if((acknak_idx + opt_len) > OPTMSG_LEN || (rjt_idx + opt_len) > OPTMSG_LEN)
hjjeon 0:7a9cde4dbf0b 718 {
hjjeon 0:7a9cde4dbf0b 719 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 720 printf("PPPoE Protocol option field overflow occuerd!\r\n");
hjjeon 0:7a9cde4dbf0b 721 #endif
hjjeon 0:7a9cde4dbf0b 722 break;
hjjeon 0:7a9cde4dbf0b 723 }
hjjeon 0:7a9cde4dbf0b 724 else
hjjeon 0:7a9cde4dbf0b 725 {
hjjeon 0:7a9cde4dbf0b 726 switch (opt_code)
hjjeon 0:7a9cde4dbf0b 727 {
hjjeon 0:7a9cde4dbf0b 728 //case 0x02 : // type : ip compression protocol
hjjeon 0:7a9cde4dbf0b 729 case 0x03 : // type : ip address
hjjeon 0:7a9cde4dbf0b 730 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 731 memcpy(&pppoe_ip, &buf[t_idx+2], opt_len-2);
hjjeon 0:7a9cde4dbf0b 732
hjjeon 0:7a9cde4dbf0b 733 acknak_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 734 break;
hjjeon 0:7a9cde4dbf0b 735 case 0x81 : //PDNS
hjjeon 0:7a9cde4dbf0b 736 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 737 memcpy(&pppoe_pdns, &buf[t_idx+2], opt_len-2);
hjjeon 0:7a9cde4dbf0b 738
hjjeon 0:7a9cde4dbf0b 739 acknak_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 740 break;
hjjeon 0:7a9cde4dbf0b 741 case 0x83 : //SDNS
hjjeon 0:7a9cde4dbf0b 742 memcpy(&acknak_opt[acknak_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 743 memcpy(&pppoe_sdns, &buf[t_idx+2], opt_len-2);
hjjeon 0:7a9cde4dbf0b 744
hjjeon 0:7a9cde4dbf0b 745 acknak_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 746 break;
hjjeon 0:7a9cde4dbf0b 747 default : // reject
hjjeon 0:7a9cde4dbf0b 748 memcpy(&rjt_opt[rjt_idx], &buf[t_idx], opt_len);
hjjeon 0:7a9cde4dbf0b 749 rjt_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 750 break;
hjjeon 0:7a9cde4dbf0b 751 }
hjjeon 0:7a9cde4dbf0b 752 }
hjjeon 0:7a9cde4dbf0b 753 t_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 754 getlen -= opt_len;
hjjeon 0:7a9cde4dbf0b 755 }
hjjeon 0:7a9cde4dbf0b 756
hjjeon 0:7a9cde4dbf0b 757
hjjeon 0:7a9cde4dbf0b 758
hjjeon 0:7a9cde4dbf0b 759 if (rjt_idx)//if reject
hjjeon 0:7a9cde4dbf0b 760 {
hjjeon 0:7a9cde4dbf0b 761 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 762 printf("reject send!\r\n");
hjjeon 0:7a9cde4dbf0b 763 #endif
hjjeon 0:7a9cde4dbf0b 764 // reject send, then wait cr
hjjeon 0:7a9cde4dbf0b 765 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 766 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 767 PPPPROTO.protocol = (PPPoE_IPCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 768 PPPPROTO.protocol |= ((PPPoE_IPCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 769
hjjeon 0:7a9cde4dbf0b 770 PPPPROTO.pcode = 0x04; // Reject
hjjeon 0:7a9cde4dbf0b 771
hjjeon 0:7a9cde4dbf0b 772 memcpy(&PPPPROTO.opt[0], &rjt_opt[0], rjt_idx);
hjjeon 0:7a9cde4dbf0b 773
hjjeon 0:7a9cde4dbf0b 774 PPPPROTO.id = get_protocol_id;
hjjeon 0:7a9cde4dbf0b 775 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 776 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 777 PPPPROTO.len = ((rjt_idx+4) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 778 PPPPROTO.len |= (((rjt_idx+4) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 779 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 780 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 781 PPPMSG_req.len = ((rjt_idx+6) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 782 PPPMSG_req.len |= (((rjt_idx+6) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 783
hjjeon 0:7a9cde4dbf0b 784 ppp_send();
hjjeon 0:7a9cde4dbf0b 785 }
hjjeon 0:7a9cde4dbf0b 786 else // if not reject
hjjeon 0:7a9cde4dbf0b 787 {
hjjeon 0:7a9cde4dbf0b 788 // ack send, lcp_cr_rcv flag set
hjjeon 0:7a9cde4dbf0b 789 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 790 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 791 PPPPROTO.protocol = (PPPoE_IPCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 792 PPPPROTO.protocol |= ((PPPoE_IPCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 793
hjjeon 0:7a9cde4dbf0b 794 if(ppp_code == PPP_CONFIG_REQ)
hjjeon 0:7a9cde4dbf0b 795 {
hjjeon 0:7a9cde4dbf0b 796 PPPPROTO.pcode = 0x02; // if configuration request MSG received, send ack
hjjeon 0:7a9cde4dbf0b 797 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 798 printf("IPCP configuration ack send!\r\n");
hjjeon 0:7a9cde4dbf0b 799 #endif
hjjeon 0:7a9cde4dbf0b 800 }
hjjeon 0:7a9cde4dbf0b 801 else
hjjeon 0:7a9cde4dbf0b 802 {
hjjeon 0:7a9cde4dbf0b 803 PPPPROTO.pcode = 0x01; // if nak received, send cr
hjjeon 0:7a9cde4dbf0b 804 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 805 printf("IPCP Configuration Request send!\r\n");
hjjeon 0:7a9cde4dbf0b 806 #endif
hjjeon 0:7a9cde4dbf0b 807 }
hjjeon 0:7a9cde4dbf0b 808
hjjeon 0:7a9cde4dbf0b 809 memcpy(&PPPPROTO.opt[0], &acknak_opt[0], acknak_idx);
hjjeon 0:7a9cde4dbf0b 810
hjjeon 0:7a9cde4dbf0b 811 PPPPROTO.id = get_protocol_id;
hjjeon 0:7a9cde4dbf0b 812 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 813 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 814 PPPPROTO.len = ((acknak_idx+4) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 815 PPPPROTO.len |= (((acknak_idx+4) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 816 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 817 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 818 PPPMSG_req.len = ((acknak_idx+6) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 819 PPPMSG_req.len |= (((acknak_idx+6) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 820
hjjeon 0:7a9cde4dbf0b 821 ppp_send();
hjjeon 0:7a9cde4dbf0b 822 if(ppp_code == 0x01) pppoe_control_flag = pppoe_control_flag | FLAG_IPCP_CR_RCV;
hjjeon 0:7a9cde4dbf0b 823 else pppoe_control_flag = pppoe_control_flag | FLAG_IPCP_NAK_RCV;
hjjeon 0:7a9cde4dbf0b 824 }
hjjeon 0:7a9cde4dbf0b 825 break;
hjjeon 0:7a9cde4dbf0b 826
hjjeon 0:7a9cde4dbf0b 827
hjjeon 0:7a9cde4dbf0b 828 case PPP_CONFIG_REJ : // Reject receive.
hjjeon 0:7a9cde4dbf0b 829 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 830 printf("IPCP reject message received!!\r\n");
hjjeon 0:7a9cde4dbf0b 831 #endif
hjjeon 0:7a9cde4dbf0b 832
hjjeon 0:7a9cde4dbf0b 833 get_protocol_id = buf[23];
hjjeon 0:7a9cde4dbf0b 834 getlen = buf[24];
hjjeon 0:7a9cde4dbf0b 835 getlen = (getlen<<8) + buf[25];
hjjeon 0:7a9cde4dbf0b 836
hjjeon 0:7a9cde4dbf0b 837 getlen -= 4;
hjjeon 0:7a9cde4dbf0b 838 t_idx = 26;
hjjeon 0:7a9cde4dbf0b 839
hjjeon 0:7a9cde4dbf0b 840 ip_rjt = 0;
hjjeon 0:7a9cde4dbf0b 841 pdns_rjt =0;
hjjeon 0:7a9cde4dbf0b 842 sdns_rjt = 0;
hjjeon 0:7a9cde4dbf0b 843
hjjeon 0:7a9cde4dbf0b 844 while (getlen)
hjjeon 0:7a9cde4dbf0b 845 {
hjjeon 0:7a9cde4dbf0b 846 opt_code = buf[t_idx];
hjjeon 0:7a9cde4dbf0b 847 opt_len = buf[t_idx+1];
hjjeon 0:7a9cde4dbf0b 848
hjjeon 0:7a9cde4dbf0b 849 switch (opt_code)
hjjeon 0:7a9cde4dbf0b 850 {
hjjeon 0:7a9cde4dbf0b 851 //case 0x02 : // type : ip compression protocol
hjjeon 0:7a9cde4dbf0b 852 case 0x03 : // ip address
hjjeon 0:7a9cde4dbf0b 853 ip_rjt = 1;
hjjeon 0:7a9cde4dbf0b 854 break;
hjjeon 0:7a9cde4dbf0b 855 case 0x81 : // PDNS
hjjeon 0:7a9cde4dbf0b 856 pdns_rjt = 1;
hjjeon 0:7a9cde4dbf0b 857 break;
hjjeon 0:7a9cde4dbf0b 858 case 0x83 : // SDNS
hjjeon 0:7a9cde4dbf0b 859 sdns_rjt = 1;
hjjeon 0:7a9cde4dbf0b 860 break;
hjjeon 0:7a9cde4dbf0b 861 default :
hjjeon 0:7a9cde4dbf0b 862 break;
hjjeon 0:7a9cde4dbf0b 863 }
hjjeon 0:7a9cde4dbf0b 864 t_idx += opt_len;
hjjeon 0:7a9cde4dbf0b 865 getlen -= opt_len;
hjjeon 0:7a9cde4dbf0b 866 }
hjjeon 0:7a9cde4dbf0b 867
hjjeon 0:7a9cde4dbf0b 868 // Configuration send without reject protocol.
hjjeon 0:7a9cde4dbf0b 869
hjjeon 0:7a9cde4dbf0b 870 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 871 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 872 PPPPROTO.protocol = (PPPoE_IPCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 873 PPPPROTO.protocol |= ((PPPoE_IPCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 874
hjjeon 0:7a9cde4dbf0b 875 PPPPROTO.pcode = PPP_CONFIG_REQ ;
hjjeon 0:7a9cde4dbf0b 876 t_idx = 0;
hjjeon 0:7a9cde4dbf0b 877 if( ip_rjt == 0 )
hjjeon 0:7a9cde4dbf0b 878 {
hjjeon 0:7a9cde4dbf0b 879 PPPPROTO.opt[t_idx++] = 0x03; // option code, IP address
hjjeon 0:7a9cde4dbf0b 880 PPPPROTO.opt[t_idx++] = 0x06; // option len
hjjeon 0:7a9cde4dbf0b 881 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 882 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 883 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 884 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 885 }
hjjeon 0:7a9cde4dbf0b 886
hjjeon 0:7a9cde4dbf0b 887 if( pdns_rjt == 0 )
hjjeon 0:7a9cde4dbf0b 888 {
hjjeon 0:7a9cde4dbf0b 889 PPPPROTO.opt[t_idx++] = 0x81; // option code, PDNS address
hjjeon 0:7a9cde4dbf0b 890 PPPPROTO.opt[t_idx++] = 0x06; // option len
hjjeon 0:7a9cde4dbf0b 891 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 892 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 893 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 894 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 895 }
hjjeon 0:7a9cde4dbf0b 896
hjjeon 0:7a9cde4dbf0b 897 if( sdns_rjt == 0 )
hjjeon 0:7a9cde4dbf0b 898 {
hjjeon 0:7a9cde4dbf0b 899 PPPPROTO.opt[t_idx++] = 0x83; // option code, SDNS address
hjjeon 0:7a9cde4dbf0b 900 PPPPROTO.opt[t_idx++] = 0x06; // option len
hjjeon 0:7a9cde4dbf0b 901 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 902 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 903 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 904 PPPPROTO.opt[t_idx++] = 0x00;
hjjeon 0:7a9cde4dbf0b 905 }
hjjeon 0:7a9cde4dbf0b 906
hjjeon 0:7a9cde4dbf0b 907 PPPPROTO.id = get_protocol_id;
hjjeon 0:7a9cde4dbf0b 908 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 909 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 910 PPPPROTO.len = ((t_idx+4) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 911 PPPPROTO.len |= (((t_idx+4) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 912 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 913 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 914 PPPMSG_req.len = ((t_idx+6) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 915 PPPMSG_req.len |= (((t_idx+6) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 916
hjjeon 0:7a9cde4dbf0b 917 if( ip_rjt && pdns_rjt && sdns_rjt)
hjjeon 0:7a9cde4dbf0b 918 {
hjjeon 0:7a9cde4dbf0b 919 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 920 printf("IPCP session : All IPCP options are rejected!!\r\n");
hjjeon 0:7a9cde4dbf0b 921 #endif
hjjeon 0:7a9cde4dbf0b 922 do_lcp_terminate();
hjjeon 0:7a9cde4dbf0b 923 }
hjjeon 0:7a9cde4dbf0b 924 else
hjjeon 0:7a9cde4dbf0b 925 {
hjjeon 0:7a9cde4dbf0b 926 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 927 printf("IPCP configuration request send without reject protocol\r\n");
hjjeon 0:7a9cde4dbf0b 928 #endif
hjjeon 0:7a9cde4dbf0b 929 ppp_send();
hjjeon 0:7a9cde4dbf0b 930 }
hjjeon 0:7a9cde4dbf0b 931
hjjeon 0:7a9cde4dbf0b 932
hjjeon 0:7a9cde4dbf0b 933 break;
hjjeon 0:7a9cde4dbf0b 934 case PPP_CONFIG_ACK : // ack, then ipcp_cr_snt flag set
hjjeon 0:7a9cde4dbf0b 935 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 936 printf("PPPoE Session IPCP: Configure-Ack received\r\n");
hjjeon 0:7a9cde4dbf0b 937 #endif
hjjeon 0:7a9cde4dbf0b 938 if((pppoe_control_flag & FLAG_IPCP_NAK_RCV) == FLAG_IPCP_NAK_RCV) pppoe_control_flag = pppoe_control_flag | FLAG_IPCP_CR_SNT;
hjjeon 0:7a9cde4dbf0b 939 break;
hjjeon 0:7a9cde4dbf0b 940 }
hjjeon 0:7a9cde4dbf0b 941 }
hjjeon 0:7a9cde4dbf0b 942 break;
hjjeon 0:7a9cde4dbf0b 943 default:
hjjeon 0:7a9cde4dbf0b 944 break;
hjjeon 0:7a9cde4dbf0b 945 }
hjjeon 0:7a9cde4dbf0b 946 }
hjjeon 0:7a9cde4dbf0b 947 }
hjjeon 0:7a9cde4dbf0b 948
hjjeon 0:7a9cde4dbf0b 949
hjjeon 0:7a9cde4dbf0b 950
hjjeon 0:7a9cde4dbf0b 951 void PPPOEClient::do_discovery(void)
hjjeon 0:7a9cde4dbf0b 952 {
hjjeon 0:7a9cde4dbf0b 953 uint16_t i = 0;
hjjeon 0:7a9cde4dbf0b 954 uint8_t mac[6] = {0,};
hjjeon 0:7a9cde4dbf0b 955 //getSHAR(mac);
hjjeon 0:7a9cde4dbf0b 956 eth->getSHAR(mac);
hjjeon 0:7a9cde4dbf0b 957
hjjeon 0:7a9cde4dbf0b 958 // PPPoE Frame
hjjeon 0:7a9cde4dbf0b 959 for(i = 0; i < 6; i++)
hjjeon 0:7a9cde4dbf0b 960 {
hjjeon 0:7a9cde4dbf0b 961 PPPMSG_req.dst_mac[i] = 0xFF; // Broadcast MAC address
hjjeon 0:7a9cde4dbf0b 962 PPPMSG_req.src_mac[i] = mac[i]; // Source MAC address
hjjeon 0:7a9cde4dbf0b 963 //-- Opt. Device MAC Address
hjjeon 0:7a9cde4dbf0b 964 PPPPROTO.opt[10+i] = mac[i];
hjjeon 0:7a9cde4dbf0b 965 }
hjjeon 0:7a9cde4dbf0b 966 //Reset control flag.
hjjeon 0:7a9cde4dbf0b 967 pppoe_control_flag = 0;
hjjeon 0:7a9cde4dbf0b 968
hjjeon 0:7a9cde4dbf0b 969 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 970 PPPMSG_req.ether_type = 0;
hjjeon 0:7a9cde4dbf0b 971 PPPMSG_req.ether_type = (PPPoE_DISCOVERY & 0xFF) << 8;//session data
hjjeon 0:7a9cde4dbf0b 972 PPPMSG_req.ether_type |= ((PPPoE_DISCOVERY >> 8) & 0xFF);//session data
hjjeon 0:7a9cde4dbf0b 973
hjjeon 0:7a9cde4dbf0b 974 PPPMSG_req.version_type = PPPoE_VER_TYPE; // Ver : 0001, Type : 0001
hjjeon 0:7a9cde4dbf0b 975 PPPMSG_req.frame_code = PPPoE_PADI; // PADI
hjjeon 0:7a9cde4dbf0b 976
hjjeon 0:7a9cde4dbf0b 977 PPPMSG_req.session_id = 0;
hjjeon 0:7a9cde4dbf0b 978
hjjeon 0:7a9cde4dbf0b 979
hjjeon 0:7a9cde4dbf0b 980 // Tag name : PPPoED_SERVICE_NAME
hjjeon 0:7a9cde4dbf0b 981 PPPPROTO.opt[0] = 0x01;
hjjeon 0:7a9cde4dbf0b 982 PPPPROTO.opt[1] = 0x01;
hjjeon 0:7a9cde4dbf0b 983 // Tag len
hjjeon 0:7a9cde4dbf0b 984 PPPPROTO.opt[2] = 0x00;
hjjeon 0:7a9cde4dbf0b 985 PPPPROTO.opt[3] = 0x00;
hjjeon 0:7a9cde4dbf0b 986
hjjeon 0:7a9cde4dbf0b 987 // Tag name : PPPoED_HOST_UNIQ
hjjeon 0:7a9cde4dbf0b 988 PPPPROTO.opt[4] = 0x01;
hjjeon 0:7a9cde4dbf0b 989 PPPPROTO.opt[5] = 0x03;
hjjeon 0:7a9cde4dbf0b 990 // Tag len (2bytes)
hjjeon 0:7a9cde4dbf0b 991 PPPPROTO.opt[6] = 0x00;
hjjeon 0:7a9cde4dbf0b 992 PPPPROTO.opt[7] = 0x08;
hjjeon 0:7a9cde4dbf0b 993 // Fill the Host-Uniq field using MAC address
hjjeon 0:7a9cde4dbf0b 994 PPPPROTO.opt[8] = 0x00;
hjjeon 0:7a9cde4dbf0b 995 PPPPROTO.opt[9] = 0x00;
hjjeon 0:7a9cde4dbf0b 996 //PPPPROTO.opt[10~15] refer to "//-- Opt. Device MAC Address"
hjjeon 0:7a9cde4dbf0b 997
hjjeon 0:7a9cde4dbf0b 998 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 999 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 1000 PPPMSG_req.len = (16 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1001 PPPMSG_req.len |= ((16 >> 8) & 0xFF);//size of opt[0-9]+ opt[10-15]
hjjeon 0:7a9cde4dbf0b 1002
hjjeon 0:7a9cde4dbf0b 1003 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1004 printf("PPPoE Discovery : PADI send\r\n");
hjjeon 0:7a9cde4dbf0b 1005 #endif
hjjeon 0:7a9cde4dbf0b 1006 ppp_send();
hjjeon 0:7a9cde4dbf0b 1007
hjjeon 0:7a9cde4dbf0b 1008 }
hjjeon 0:7a9cde4dbf0b 1009
hjjeon 0:7a9cde4dbf0b 1010 void PPPOEClient::do_lcp(void)
hjjeon 0:7a9cde4dbf0b 1011 {
hjjeon 0:7a9cde4dbf0b 1012
hjjeon 0:7a9cde4dbf0b 1013 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1014 PPPMSG_req.ether_type = 0;
hjjeon 0:7a9cde4dbf0b 1015 PPPMSG_req.ether_type = (PPPoE_SESSION & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1016 PPPMSG_req.ether_type |= ((PPPoE_SESSION >> 8) & 0xFF);//session data
hjjeon 0:7a9cde4dbf0b 1017
hjjeon 0:7a9cde4dbf0b 1018 PPPMSG_req.frame_code = 0x00; //session data
hjjeon 0:7a9cde4dbf0b 1019 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1020 PPPMSG_req.session_id = 0;
hjjeon 0:7a9cde4dbf0b 1021 PPPMSG_req.session_id = (NAS_sessionid & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1022 PPPMSG_req.session_id |= ((NAS_sessionid >> 8) & 0xFF);//session data
hjjeon 0:7a9cde4dbf0b 1023
hjjeon 0:7a9cde4dbf0b 1024 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1025 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 1026 PPPPROTO.protocol = (PPPoE_LCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1027 PPPPROTO.protocol |= ((PPPoE_LCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1028
hjjeon 0:7a9cde4dbf0b 1029
hjjeon 0:7a9cde4dbf0b 1030 PPPPROTO.pcode = PPP_CONFIG_REQ; // CR
hjjeon 0:7a9cde4dbf0b 1031
hjjeon 0:7a9cde4dbf0b 1032 PPPPROTO.opt[0] = 0x05;
hjjeon 0:7a9cde4dbf0b 1033 PPPPROTO.opt[1] = 0x06;
hjjeon 0:7a9cde4dbf0b 1034 PPPPROTO.opt[2] = 0x00;
hjjeon 0:7a9cde4dbf0b 1035 PPPPROTO.opt[3] = 0x01;
hjjeon 0:7a9cde4dbf0b 1036 PPPPROTO.opt[4] = 0x02;
hjjeon 0:7a9cde4dbf0b 1037 PPPPROTO.opt[5] = 0x03;
hjjeon 0:7a9cde4dbf0b 1038
hjjeon 0:7a9cde4dbf0b 1039 PPPPROTO.id = protocol_id++;
hjjeon 0:7a9cde4dbf0b 1040 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1041 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 1042 PPPPROTO.len = (10 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1043 PPPPROTO.len |= ((10 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1044
hjjeon 0:7a9cde4dbf0b 1045 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1046 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 1047 PPPMSG_req.len = (12 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1048 PPPMSG_req.len |= ((12 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1049
hjjeon 0:7a9cde4dbf0b 1050 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1051 printf("LCP configuration Request send\r\n");
hjjeon 0:7a9cde4dbf0b 1052 #endif
hjjeon 0:7a9cde4dbf0b 1053 ppp_send();
hjjeon 0:7a9cde4dbf0b 1054
hjjeon 0:7a9cde4dbf0b 1055 }
hjjeon 0:7a9cde4dbf0b 1056
hjjeon 0:7a9cde4dbf0b 1057 void PPPOEClient::do_lcp_echo(void)
hjjeon 0:7a9cde4dbf0b 1058 {
hjjeon 0:7a9cde4dbf0b 1059
hjjeon 0:7a9cde4dbf0b 1060 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1061 PPPMSG_req.ether_type = 0;
hjjeon 0:7a9cde4dbf0b 1062 PPPMSG_req.ether_type = (PPPoE_SESSION & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1063 PPPMSG_req.ether_type |= ((PPPoE_SESSION >> 8) & 0xFF);// session
hjjeon 0:7a9cde4dbf0b 1064
hjjeon 0:7a9cde4dbf0b 1065 PPPMSG_req.frame_code = 0x00; // session data
hjjeon 0:7a9cde4dbf0b 1066 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1067 PPPMSG_req.session_id = 0;
hjjeon 0:7a9cde4dbf0b 1068 PPPMSG_req.session_id = (NAS_sessionid & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1069 PPPMSG_req.session_id |= ((NAS_sessionid >> 8) & 0xFF);// session id
hjjeon 0:7a9cde4dbf0b 1070
hjjeon 0:7a9cde4dbf0b 1071 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1072 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 1073 PPPPROTO.protocol = (PPPoE_LCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1074 PPPPROTO.protocol |= ((PPPoE_LCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1075
hjjeon 0:7a9cde4dbf0b 1076 PPPPROTO.pcode = PPP_ECHO_REQ; // Echo-Requset
hjjeon 0:7a9cde4dbf0b 1077
hjjeon 0:7a9cde4dbf0b 1078 PPPPROTO.opt[0] = 0x00; // Magic number
hjjeon 0:7a9cde4dbf0b 1079 PPPPROTO.opt[1] = 0x01;
hjjeon 0:7a9cde4dbf0b 1080 PPPPROTO.opt[2] = 0x02;
hjjeon 0:7a9cde4dbf0b 1081 PPPPROTO.opt[3] = 0x03;
hjjeon 0:7a9cde4dbf0b 1082
hjjeon 0:7a9cde4dbf0b 1083 PPPPROTO.id = protocol_id++;
hjjeon 0:7a9cde4dbf0b 1084 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1085 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 1086 PPPPROTO.len = (8 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1087 PPPPROTO.len |= ((8 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1088 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1089 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 1090 PPPMSG_req.len = (10 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1091 PPPMSG_req.len |= ((10 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1092 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1093 printf("LCP echo request send\r\n");
hjjeon 0:7a9cde4dbf0b 1094 #endif
hjjeon 0:7a9cde4dbf0b 1095 ppp_send();
hjjeon 0:7a9cde4dbf0b 1096
hjjeon 0:7a9cde4dbf0b 1097 }
hjjeon 0:7a9cde4dbf0b 1098
hjjeon 0:7a9cde4dbf0b 1099 //return -- 1 : success, 0 : failed
hjjeon 0:7a9cde4dbf0b 1100 uint8_t PPPOEClient::do_lcp_terminate(void)
hjjeon 0:7a9cde4dbf0b 1101 {
hjjeon 0:7a9cde4dbf0b 1102 uint16_t received_len = 0;
hjjeon 0:7a9cde4dbf0b 1103 uint8_t sock_num = 0;
hjjeon 0:7a9cde4dbf0b 1104
hjjeon 0:7a9cde4dbf0b 1105
hjjeon 0:7a9cde4dbf0b 1106 pppoe_retry_count = 0;
hjjeon 0:7a9cde4dbf0b 1107
hjjeon 0:7a9cde4dbf0b 1108 //while( (pppoe_control_flag & FLAG_TERMINATION_ACK_RCV) == 0 )
hjjeon 0:7a9cde4dbf0b 1109 while(1)
hjjeon 0:7a9cde4dbf0b 1110 {
hjjeon 0:7a9cde4dbf0b 1111 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1112 PPPMSG_req.ether_type = 0;
hjjeon 0:7a9cde4dbf0b 1113 PPPMSG_req.ether_type = (PPPoE_SESSION & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1114 PPPMSG_req.ether_type |= ((PPPoE_SESSION >> 8) & 0xFF);// session
hjjeon 0:7a9cde4dbf0b 1115
hjjeon 0:7a9cde4dbf0b 1116 PPPMSG_req.frame_code = 0x00; // session data
hjjeon 0:7a9cde4dbf0b 1117 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1118 PPPMSG_req.session_id = 0;
hjjeon 0:7a9cde4dbf0b 1119 PPPMSG_req.session_id = (NAS_sessionid & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1120 PPPMSG_req.session_id |= ((NAS_sessionid >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1121
hjjeon 0:7a9cde4dbf0b 1122 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1123 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 1124 PPPPROTO.protocol = (PPPoE_LCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1125 PPPPROTO.protocol |= ((PPPoE_LCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1126
hjjeon 0:7a9cde4dbf0b 1127 PPPPROTO.pcode = PPP_TERM_REQ; // Terminate-Requset
hjjeon 0:7a9cde4dbf0b 1128
hjjeon 0:7a9cde4dbf0b 1129 PPPPROTO.opt[0] = 0x00; // Magic number
hjjeon 0:7a9cde4dbf0b 1130 PPPPROTO.opt[1] = 0x01;
hjjeon 0:7a9cde4dbf0b 1131 PPPPROTO.opt[2] = 0x02;
hjjeon 0:7a9cde4dbf0b 1132 PPPPROTO.opt[3] = 0x03;
hjjeon 0:7a9cde4dbf0b 1133
hjjeon 0:7a9cde4dbf0b 1134 PPPPROTO.id = protocol_id++;
hjjeon 0:7a9cde4dbf0b 1135 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1136 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 1137 PPPPROTO.len = (8 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1138 PPPPROTO.len |= ((8 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1139
hjjeon 0:7a9cde4dbf0b 1140 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1141 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 1142 PPPMSG_req.len = (10 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1143 PPPMSG_req.len |= ((10 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1144
hjjeon 0:7a9cde4dbf0b 1145
hjjeon 0:7a9cde4dbf0b 1146 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1147 printf("Termination Request send\r\n");
hjjeon 0:7a9cde4dbf0b 1148 #endif
hjjeon 0:7a9cde4dbf0b 1149 ppp_send();
hjjeon 0:7a9cde4dbf0b 1150 pppoe_retry_count++;
hjjeon 0:7a9cde4dbf0b 1151
hjjeon 0:7a9cde4dbf0b 1152
hjjeon 0:7a9cde4dbf0b 1153 if(pppoe_retry_count > PPP_MAX_RETRY_COUNT)
hjjeon 0:7a9cde4dbf0b 1154 {
hjjeon 0:7a9cde4dbf0b 1155 printf("Termination Failed\r\n");
hjjeon 0:7a9cde4dbf0b 1156 return 0;//termination fail
hjjeon 0:7a9cde4dbf0b 1157 }
hjjeon 0:7a9cde4dbf0b 1158
hjjeon 0:7a9cde4dbf0b 1159
hjjeon 0:7a9cde4dbf0b 1160 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1161 while((pppoe_control_flag & FLAG_TERMINATION_ACK_RCV) == 0 && pppoe_recv_count < PPP_MAX_RETRYRECV_COUNT)
hjjeon 0:7a9cde4dbf0b 1162 {
hjjeon 0:7a9cde4dbf0b 1163 wait(0.4);
hjjeon 0:7a9cde4dbf0b 1164 pppoe_recv_count ++;
hjjeon 0:7a9cde4dbf0b 1165
hjjeon 0:7a9cde4dbf0b 1166
hjjeon 0:7a9cde4dbf0b 1167 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1168
hjjeon 0:7a9cde4dbf0b 1169 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1170 {
hjjeon 0:7a9cde4dbf0b 1171 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1172 if((pppoe_control_flag & FLAG_TERMINATION_ACK_RCV) == FLAG_TERMINATION_ACK_RCV) // Termination success
hjjeon 0:7a9cde4dbf0b 1173 {
hjjeon 0:7a9cde4dbf0b 1174 pppoe_state = PPPoE_FAILED;
hjjeon 0:7a9cde4dbf0b 1175
hjjeon 0:7a9cde4dbf0b 1176 // Flags reset
hjjeon 0:7a9cde4dbf0b 1177 pppoe_control_flag = 0;
hjjeon 0:7a9cde4dbf0b 1178 // Clear Session ID for new PPPoE Discovery process
hjjeon 0:7a9cde4dbf0b 1179 NAS_sessionid = 0;
hjjeon 0:7a9cde4dbf0b 1180
hjjeon 0:7a9cde4dbf0b 1181 NAS_mac[0] = 0;
hjjeon 0:7a9cde4dbf0b 1182 NAS_mac[1] = 0;
hjjeon 0:7a9cde4dbf0b 1183 NAS_mac[2] = 0;
hjjeon 0:7a9cde4dbf0b 1184 NAS_mac[3] = 0;
hjjeon 0:7a9cde4dbf0b 1185 NAS_mac[4] = 0;
hjjeon 0:7a9cde4dbf0b 1186 NAS_mac[5] = 0;
hjjeon 0:7a9cde4dbf0b 1187
hjjeon 0:7a9cde4dbf0b 1188 pppoe_ip[0] = 0;
hjjeon 0:7a9cde4dbf0b 1189 pppoe_ip[1] = 0;
hjjeon 0:7a9cde4dbf0b 1190 pppoe_ip[2] = 0;
hjjeon 0:7a9cde4dbf0b 1191 pppoe_ip[3] = 0;
hjjeon 0:7a9cde4dbf0b 1192
hjjeon 0:7a9cde4dbf0b 1193 printf("Termination completed\r\n");
hjjeon 0:7a9cde4dbf0b 1194 return 1;//termination success
hjjeon 0:7a9cde4dbf0b 1195 }
hjjeon 0:7a9cde4dbf0b 1196 }
hjjeon 0:7a9cde4dbf0b 1197 }
hjjeon 0:7a9cde4dbf0b 1198
hjjeon 0:7a9cde4dbf0b 1199 }
hjjeon 0:7a9cde4dbf0b 1200
hjjeon 0:7a9cde4dbf0b 1201 }
hjjeon 0:7a9cde4dbf0b 1202
hjjeon 0:7a9cde4dbf0b 1203
hjjeon 0:7a9cde4dbf0b 1204 void PPPOEClient::do_pap(void)
hjjeon 0:7a9cde4dbf0b 1205 {
hjjeon 0:7a9cde4dbf0b 1206
hjjeon 0:7a9cde4dbf0b 1207 uint16_t i=0, j=0;
hjjeon 0:7a9cde4dbf0b 1208
hjjeon 0:7a9cde4dbf0b 1209 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1210 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 1211 PPPPROTO.protocol = (PPPoE_PAP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1212 PPPPROTO.protocol |= ((PPPoE_PAP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1213
hjjeon 0:7a9cde4dbf0b 1214 PPPPROTO.pcode = PPP_CONFIG_REQ; // cr
hjjeon 0:7a9cde4dbf0b 1215 PPPPROTO.opt[i++] = pppoe_id_len;
hjjeon 0:7a9cde4dbf0b 1216
hjjeon 0:7a9cde4dbf0b 1217 for(j = 0; j < pppoe_id_len; j++)
hjjeon 0:7a9cde4dbf0b 1218 {
hjjeon 0:7a9cde4dbf0b 1219 PPPPROTO.opt[i++] = pppoe_id[j];
hjjeon 0:7a9cde4dbf0b 1220 }
hjjeon 0:7a9cde4dbf0b 1221
hjjeon 0:7a9cde4dbf0b 1222 PPPPROTO.opt[i++] = pppoe_pw_len;
hjjeon 0:7a9cde4dbf0b 1223 for(j = 0; j < pppoe_pw_len; j++)
hjjeon 0:7a9cde4dbf0b 1224 {
hjjeon 0:7a9cde4dbf0b 1225 PPPPROTO.opt[i++] = pppoe_pw[j];
hjjeon 0:7a9cde4dbf0b 1226 }
hjjeon 0:7a9cde4dbf0b 1227
hjjeon 0:7a9cde4dbf0b 1228 PPPPROTO.id = protocol_id++;
hjjeon 0:7a9cde4dbf0b 1229 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1230 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 1231 PPPPROTO.len = ((i+4) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1232 PPPPROTO.len |= (((i+4) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1233 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1234 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 1235 PPPMSG_req.len = (((i+4)+2) & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1236 PPPMSG_req.len |= ((((i+4)+2) >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1237
hjjeon 0:7a9cde4dbf0b 1238 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1239 printf("PAP authenticate-Request send\r\n");
hjjeon 0:7a9cde4dbf0b 1240 #endif
hjjeon 0:7a9cde4dbf0b 1241
hjjeon 0:7a9cde4dbf0b 1242 ppp_send();
hjjeon 0:7a9cde4dbf0b 1243
hjjeon 0:7a9cde4dbf0b 1244 }
hjjeon 0:7a9cde4dbf0b 1245
hjjeon 0:7a9cde4dbf0b 1246 void PPPOEClient::do_ipcp(void)
hjjeon 0:7a9cde4dbf0b 1247 {
hjjeon 0:7a9cde4dbf0b 1248
hjjeon 0:7a9cde4dbf0b 1249 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1250 PPPPROTO.protocol = 0;
hjjeon 0:7a9cde4dbf0b 1251 PPPPROTO.protocol = (PPPoE_IPCP & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1252 PPPPROTO.protocol |= ((PPPoE_IPCP >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1253
hjjeon 0:7a9cde4dbf0b 1254 PPPPROTO.pcode = PPP_CONFIG_REQ; // configuration-req
hjjeon 0:7a9cde4dbf0b 1255
hjjeon 0:7a9cde4dbf0b 1256 PPPPROTO.opt[0] = 0x03; // option code, IP address
hjjeon 0:7a9cde4dbf0b 1257 PPPPROTO.opt[1] = 0x06; // option len
hjjeon 0:7a9cde4dbf0b 1258 PPPPROTO.opt[2] = 0x00;
hjjeon 0:7a9cde4dbf0b 1259 PPPPROTO.opt[3] = 0x00;
hjjeon 0:7a9cde4dbf0b 1260 PPPPROTO.opt[4] = 0x00;
hjjeon 0:7a9cde4dbf0b 1261 PPPPROTO.opt[5] = 0x00;
hjjeon 0:7a9cde4dbf0b 1262 //Option PDNS
hjjeon 0:7a9cde4dbf0b 1263 PPPPROTO.opt[6] = 0x81; //op code, PDNS
hjjeon 0:7a9cde4dbf0b 1264 PPPPROTO.opt[7] = 0x06; //option len
hjjeon 0:7a9cde4dbf0b 1265 PPPPROTO.opt[8] = 0x00;
hjjeon 0:7a9cde4dbf0b 1266 PPPPROTO.opt[9] = 0x00;
hjjeon 0:7a9cde4dbf0b 1267 PPPPROTO.opt[10] = 0x00;
hjjeon 0:7a9cde4dbf0b 1268 PPPPROTO.opt[11] = 0x00;
hjjeon 0:7a9cde4dbf0b 1269 //Option SDNS
hjjeon 0:7a9cde4dbf0b 1270 PPPPROTO.opt[12] = 0x83; //op code, SDNS
hjjeon 0:7a9cde4dbf0b 1271 PPPPROTO.opt[13] = 0x06; //option len
hjjeon 0:7a9cde4dbf0b 1272 PPPPROTO.opt[14] = 0x00;
hjjeon 0:7a9cde4dbf0b 1273 PPPPROTO.opt[15] = 0x00;
hjjeon 0:7a9cde4dbf0b 1274 PPPPROTO.opt[16] = 0x00;
hjjeon 0:7a9cde4dbf0b 1275 PPPPROTO.opt[17] = 0x00;
hjjeon 0:7a9cde4dbf0b 1276
hjjeon 0:7a9cde4dbf0b 1277
hjjeon 0:7a9cde4dbf0b 1278 PPPPROTO.id = protocol_id++;
hjjeon 0:7a9cde4dbf0b 1279
hjjeon 0:7a9cde4dbf0b 1280 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1281 /*
hjjeon 0:7a9cde4dbf0b 1282 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 1283 PPPPROTO.len = (10 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1284 PPPPROTO.len |= ((10 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1285
hjjeon 0:7a9cde4dbf0b 1286 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1287 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 1288 PPPMSG_req.len = (12 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1289 PPPMSG_req.len |= ((12 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1290 */
hjjeon 0:7a9cde4dbf0b 1291 PPPPROTO.len = 0;
hjjeon 0:7a9cde4dbf0b 1292 PPPPROTO.len = (22 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1293 PPPPROTO.len |= ((22 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1294
hjjeon 0:7a9cde4dbf0b 1295 //change MSB and LSB because of different endian.
hjjeon 0:7a9cde4dbf0b 1296 PPPMSG_req.len = 0;
hjjeon 0:7a9cde4dbf0b 1297 PPPMSG_req.len = (24 & 0xFF) << 8;
hjjeon 0:7a9cde4dbf0b 1298 PPPMSG_req.len |= ((24 >> 8) & 0xFF);
hjjeon 0:7a9cde4dbf0b 1299 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1300 printf("IPCP Configuration request send\r\n");
hjjeon 0:7a9cde4dbf0b 1301 #endif
hjjeon 0:7a9cde4dbf0b 1302
hjjeon 0:7a9cde4dbf0b 1303 ppp_send();
hjjeon 0:7a9cde4dbf0b 1304
hjjeon 0:7a9cde4dbf0b 1305 }
hjjeon 0:7a9cde4dbf0b 1306
hjjeon 0:7a9cde4dbf0b 1307
hjjeon 0:7a9cde4dbf0b 1308
hjjeon 0:7a9cde4dbf0b 1309 // PPPoE start
hjjeon 0:7a9cde4dbf0b 1310 //ret = Success : 1, Fail : 0, continue : 2
hjjeon 0:7a9cde4dbf0b 1311 uint8_t PPPOEClient::ppp_start(uint8_t * pppoe_buf)
hjjeon 0:7a9cde4dbf0b 1312 {
hjjeon 0:7a9cde4dbf0b 1313 uint8_t sock_num;
hjjeon 0:7a9cde4dbf0b 1314 uint8_t mFlag;
hjjeon 0:7a9cde4dbf0b 1315 uint16_t dummyPort;
hjjeon 0:7a9cde4dbf0b 1316 uint8_t ret = 2;
hjjeon 0:7a9cde4dbf0b 1317 uint16_t received_len = 0;
hjjeon 0:7a9cde4dbf0b 1318
hjjeon 0:7a9cde4dbf0b 1319 buf = pppoe_buf;
hjjeon 0:7a9cde4dbf0b 1320 //-- Init. param
hjjeon 0:7a9cde4dbf0b 1321 sock_num = 0;
hjjeon 0:7a9cde4dbf0b 1322 dummyPort = 0;
hjjeon 0:7a9cde4dbf0b 1323 mFlag = 0x80; //MAC filter enable in MACRAW
hjjeon 0:7a9cde4dbf0b 1324
hjjeon 0:7a9cde4dbf0b 1325
hjjeon 0:7a9cde4dbf0b 1326 switch(eth->getSn_SR(sock_num))
hjjeon 0:7a9cde4dbf0b 1327 {
hjjeon 0:7a9cde4dbf0b 1328 case WIZnet_Chip::SOCK_CLOSED:
hjjeon 0:7a9cde4dbf0b 1329 eth->close(sock_num); // Close the SOCKET
hjjeon 0:7a9cde4dbf0b 1330 eth->Socket_macraw(sock_num, dummyPort, mFlag); // Open the SOCKET with MACRAW mode
hjjeon 0:7a9cde4dbf0b 1331 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1332 printf("No.%d socket is opened with MACRAW and flag is 0x%2x\r\n", sock_num, mFlag);
hjjeon 0:7a9cde4dbf0b 1333 #endif
hjjeon 0:7a9cde4dbf0b 1334 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1335 printf("\r\n=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1336 printf("PHASE 0. PPPoE setup\r\n");
hjjeon 0:7a9cde4dbf0b 1337 printf("=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1338 #endif
hjjeon 0:7a9cde4dbf0b 1339 break;
hjjeon 0:7a9cde4dbf0b 1340
hjjeon 0:7a9cde4dbf0b 1341 case SOCK_MACRAW:
hjjeon 0:7a9cde4dbf0b 1342
hjjeon 0:7a9cde4dbf0b 1343 if(pppoe_retry_send_count > PPP_MAX_RETRYSEND_COUNT) pppoe_state = PPPoE_FAILED;
hjjeon 0:7a9cde4dbf0b 1344
hjjeon 0:7a9cde4dbf0b 1345 switch(pppoe_state)
hjjeon 0:7a9cde4dbf0b 1346 {
hjjeon 0:7a9cde4dbf0b 1347 case PPPoE_DISCOVERY : // Discovery
hjjeon 0:7a9cde4dbf0b 1348 // PPPoE Discoveryecv(
hjjeon 0:7a9cde4dbf0b 1349 //if((pppoe_control_flag & FLAG_DISCOVERY_RCV_PADO) == 0)
hjjeon 0:7a9cde4dbf0b 1350 if((pppoe_control_flag & FLAG_DISCOVERY_RCV_PADO) == 0 || (pppoe_control_flag & FLAG_DISCOVERY_RCV_PADS) == 0) //Not recv PADO or PADS
hjjeon 0:7a9cde4dbf0b 1351 {
hjjeon 0:7a9cde4dbf0b 1352 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1353 printf("\r\n=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1354 printf("PHASE 1. PPPoE Discovery\r\n");
hjjeon 0:7a9cde4dbf0b 1355 printf("=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1356 #endif
hjjeon 0:7a9cde4dbf0b 1357 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1358 printf("Retry send count : %d\r\n", pppoe_retry_send_count);
hjjeon 0:7a9cde4dbf0b 1359 #endif
hjjeon 0:7a9cde4dbf0b 1360 do_discovery(); // Send PADI
hjjeon 0:7a9cde4dbf0b 1361 pppoe_retry_send_count++;
hjjeon 0:7a9cde4dbf0b 1362 }
hjjeon 0:7a9cde4dbf0b 1363
hjjeon 0:7a9cde4dbf0b 1364 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1365 while((pppoe_control_flag & FLAG_DISCOVERY_RCV_PADS) == 0 && pppoe_recv_count < (PPP_MAX_RETRYRECV_COUNT) * 2)
hjjeon 0:7a9cde4dbf0b 1366 {
hjjeon 0:7a9cde4dbf0b 1367 wait(0.2);
hjjeon 0:7a9cde4dbf0b 1368 pppoe_recv_count ++;
hjjeon 0:7a9cde4dbf0b 1369
hjjeon 0:7a9cde4dbf0b 1370 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1371
hjjeon 0:7a9cde4dbf0b 1372 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1373 {
hjjeon 0:7a9cde4dbf0b 1374 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1375
hjjeon 0:7a9cde4dbf0b 1376
hjjeon 0:7a9cde4dbf0b 1377 if((pppoe_control_flag & FLAG_DISCOVERY_RCV_PADS) == FLAG_DISCOVERY_RCV_PADS)// Discovery success
hjjeon 0:7a9cde4dbf0b 1378 {
hjjeon 0:7a9cde4dbf0b 1379 pppoe_state = PPPoE_LCP;
hjjeon 0:7a9cde4dbf0b 1380 pppoe_retry_send_count = 0;//reset
hjjeon 0:7a9cde4dbf0b 1381 }
hjjeon 0:7a9cde4dbf0b 1382 }
hjjeon 0:7a9cde4dbf0b 1383 }
hjjeon 0:7a9cde4dbf0b 1384
hjjeon 0:7a9cde4dbf0b 1385 break;
hjjeon 0:7a9cde4dbf0b 1386
hjjeon 0:7a9cde4dbf0b 1387 case PPPoE_LCP : // LCP
hjjeon 0:7a9cde4dbf0b 1388 if((pppoe_control_flag & FLAG_LCP_CR_RCV) == 0)
hjjeon 0:7a9cde4dbf0b 1389 {
hjjeon 0:7a9cde4dbf0b 1390 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1391 printf("\r\n=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1392 printf("PHASE 2. PPPoE LCP\r\n");
hjjeon 0:7a9cde4dbf0b 1393 printf("=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1394 #endif
hjjeon 0:7a9cde4dbf0b 1395 do_lcp_echo();
hjjeon 0:7a9cde4dbf0b 1396
hjjeon 0:7a9cde4dbf0b 1397 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1398 printf("Retry send count : %d\r\n", pppoe_retry_send_count);
hjjeon 0:7a9cde4dbf0b 1399 #endif
hjjeon 0:7a9cde4dbf0b 1400 pppoe_retry_send_count++;
hjjeon 0:7a9cde4dbf0b 1401 }
hjjeon 0:7a9cde4dbf0b 1402
hjjeon 0:7a9cde4dbf0b 1403 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1404 while((pppoe_control_flag & FLAG_LCP_CR_RCV) == 0 && pppoe_recv_count < PPP_MAX_RETRYRECV_COUNT)
hjjeon 0:7a9cde4dbf0b 1405 {
hjjeon 0:7a9cde4dbf0b 1406 wait(0.2);
hjjeon 0:7a9cde4dbf0b 1407 pppoe_recv_count++;
hjjeon 0:7a9cde4dbf0b 1408
hjjeon 0:7a9cde4dbf0b 1409 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1410 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1411 {
hjjeon 0:7a9cde4dbf0b 1412 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1413 if((pppoe_control_flag & FLAG_LCP_CR_RCV) == FLAG_LCP_CR_RCV) pppoe_retry_send_count = 0;//reset
hjjeon 0:7a9cde4dbf0b 1414 }
hjjeon 0:7a9cde4dbf0b 1415 }
hjjeon 0:7a9cde4dbf0b 1416
hjjeon 0:7a9cde4dbf0b 1417
hjjeon 0:7a9cde4dbf0b 1418 if((pppoe_control_flag & FLAG_LCP_CR_RCV) == FLAG_LCP_CR_RCV)
hjjeon 0:7a9cde4dbf0b 1419 {
hjjeon 0:7a9cde4dbf0b 1420 do_lcp();
hjjeon 0:7a9cde4dbf0b 1421
hjjeon 0:7a9cde4dbf0b 1422 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1423 printf("Retry send count : %d\r\n", pppoe_retry_send_count);
hjjeon 0:7a9cde4dbf0b 1424 #endif
hjjeon 0:7a9cde4dbf0b 1425 pppoe_retry_send_count++;
hjjeon 0:7a9cde4dbf0b 1426
hjjeon 0:7a9cde4dbf0b 1427 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1428 while((pppoe_control_flag & FLAG_LCP_CR_SNT) == 0 && pppoe_recv_count < PPP_MAX_RETRYRECV_COUNT)
hjjeon 0:7a9cde4dbf0b 1429 {
hjjeon 0:7a9cde4dbf0b 1430 wait(0.2);
hjjeon 0:7a9cde4dbf0b 1431 pppoe_recv_count++;
hjjeon 0:7a9cde4dbf0b 1432
hjjeon 0:7a9cde4dbf0b 1433 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1434 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1435 {
hjjeon 0:7a9cde4dbf0b 1436 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1437 if((pppoe_control_flag & FLAG_LCP_CR_SNT) == FLAG_LCP_CR_SNT)
hjjeon 0:7a9cde4dbf0b 1438 {
hjjeon 0:7a9cde4dbf0b 1439 // PAP
hjjeon 0:7a9cde4dbf0b 1440 if(auth_protocol == PPPoE_PAP)
hjjeon 0:7a9cde4dbf0b 1441 {
hjjeon 0:7a9cde4dbf0b 1442 pppoe_state = PPPoE_PAP;
hjjeon 0:7a9cde4dbf0b 1443 pppoe_retry_send_count = 0;//reset
hjjeon 0:7a9cde4dbf0b 1444 }
hjjeon 0:7a9cde4dbf0b 1445 // CHAP
hjjeon 0:7a9cde4dbf0b 1446 else if(auth_protocol == PPPoE_CHAP)
hjjeon 0:7a9cde4dbf0b 1447 {
hjjeon 0:7a9cde4dbf0b 1448 pppoe_state = PPPoE_CHAP;
hjjeon 0:7a9cde4dbf0b 1449 pppoe_retry_send_count = 0;//reset
hjjeon 0:7a9cde4dbf0b 1450 }
hjjeon 0:7a9cde4dbf0b 1451 // unknown auth protocol
hjjeon 0:7a9cde4dbf0b 1452 else
hjjeon 0:7a9cde4dbf0b 1453 {
hjjeon 0:7a9cde4dbf0b 1454 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1455 printf("\r\nError : Unknown authentication protocol");
hjjeon 0:7a9cde4dbf0b 1456 #endif
hjjeon 0:7a9cde4dbf0b 1457 pppoe_state = PPPoE_FAILED;
hjjeon 0:7a9cde4dbf0b 1458 }
hjjeon 0:7a9cde4dbf0b 1459
hjjeon 0:7a9cde4dbf0b 1460 }
hjjeon 0:7a9cde4dbf0b 1461 }
hjjeon 0:7a9cde4dbf0b 1462 }
hjjeon 0:7a9cde4dbf0b 1463 }
hjjeon 0:7a9cde4dbf0b 1464 break;
hjjeon 0:7a9cde4dbf0b 1465
hjjeon 0:7a9cde4dbf0b 1466 case PPPoE_PAP : // PAP
hjjeon 0:7a9cde4dbf0b 1467 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1468 printf("\r\n=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1469 printf("PHASE 3. PPPoE PAP\r\n");
hjjeon 0:7a9cde4dbf0b 1470 printf("=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1471 #endif
hjjeon 0:7a9cde4dbf0b 1472
hjjeon 0:7a9cde4dbf0b 1473
hjjeon 0:7a9cde4dbf0b 1474 if((pppoe_control_flag & FLAG_PAP_ACK_RCV) == 0 )
hjjeon 0:7a9cde4dbf0b 1475 {
hjjeon 0:7a9cde4dbf0b 1476 do_pap();
hjjeon 0:7a9cde4dbf0b 1477 pppoe_retry_send_count++;
hjjeon 0:7a9cde4dbf0b 1478 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1479 printf("Retry send count : %d\r\n", pppoe_retry_send_count );
hjjeon 0:7a9cde4dbf0b 1480 #endif
hjjeon 0:7a9cde4dbf0b 1481 }
hjjeon 0:7a9cde4dbf0b 1482
hjjeon 0:7a9cde4dbf0b 1483 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1484 while((pppoe_control_flag & FLAG_PAP_ACK_RCV) == 0 && pppoe_recv_count < PPP_MAX_RETRYRECV_COUNT)
hjjeon 0:7a9cde4dbf0b 1485 {
hjjeon 0:7a9cde4dbf0b 1486 wait(0.4);
hjjeon 0:7a9cde4dbf0b 1487 pppoe_recv_count++;
hjjeon 0:7a9cde4dbf0b 1488
hjjeon 0:7a9cde4dbf0b 1489 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1490 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1491 {
hjjeon 0:7a9cde4dbf0b 1492 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1493
hjjeon 0:7a9cde4dbf0b 1494 if((pppoe_control_flag & FLAG_PAP_ACK_RCV) == FLAG_PAP_ACK_RCV)// pap auth success
hjjeon 0:7a9cde4dbf0b 1495 {
hjjeon 0:7a9cde4dbf0b 1496 pppoe_state = PPPoE_IPCP;
hjjeon 0:7a9cde4dbf0b 1497 pppoe_retry_send_count = 0;//reset
hjjeon 0:7a9cde4dbf0b 1498 }
hjjeon 0:7a9cde4dbf0b 1499 }
hjjeon 0:7a9cde4dbf0b 1500 }
hjjeon 0:7a9cde4dbf0b 1501 break;
hjjeon 0:7a9cde4dbf0b 1502
hjjeon 0:7a9cde4dbf0b 1503 case PPPoE_CHAP : // CHAP
hjjeon 0:7a9cde4dbf0b 1504 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1505 printf("\r\n=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1506 printf("PHASE 3. PPPoE CHAP\r\n");
hjjeon 0:7a9cde4dbf0b 1507 printf("=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1508 #endif
hjjeon 0:7a9cde4dbf0b 1509
hjjeon 0:7a9cde4dbf0b 1510
hjjeon 0:7a9cde4dbf0b 1511 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1512 while((pppoe_control_flag & FLAG_CHAP_SUC_RCV) == 0 && pppoe_recv_count < 50)
hjjeon 0:7a9cde4dbf0b 1513 {
hjjeon 0:7a9cde4dbf0b 1514 wait(0.4);
hjjeon 0:7a9cde4dbf0b 1515 pppoe_recv_count++;
hjjeon 0:7a9cde4dbf0b 1516
hjjeon 0:7a9cde4dbf0b 1517 printf("test\r\n");
hjjeon 0:7a9cde4dbf0b 1518
hjjeon 0:7a9cde4dbf0b 1519 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1520 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1521 {
hjjeon 0:7a9cde4dbf0b 1522 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1523
hjjeon 0:7a9cde4dbf0b 1524 if((pppoe_control_flag & FLAG_CHAP_SUC_RCV) == FLAG_CHAP_SUC_RCV)
hjjeon 0:7a9cde4dbf0b 1525 {
hjjeon 0:7a9cde4dbf0b 1526 pppoe_state = PPPoE_IPCP;
hjjeon 0:7a9cde4dbf0b 1527 }
hjjeon 0:7a9cde4dbf0b 1528
hjjeon 0:7a9cde4dbf0b 1529 if((pppoe_control_flag & FLAG_TERMINATION_REQ_RCV) == FLAG_TERMINATION_REQ_RCV)
hjjeon 0:7a9cde4dbf0b 1530 {
hjjeon 0:7a9cde4dbf0b 1531 pppoe_state = PPPoE_FAILED;
hjjeon 0:7a9cde4dbf0b 1532
hjjeon 0:7a9cde4dbf0b 1533 break;
hjjeon 0:7a9cde4dbf0b 1534 }
hjjeon 0:7a9cde4dbf0b 1535 }
hjjeon 0:7a9cde4dbf0b 1536 }
hjjeon 0:7a9cde4dbf0b 1537
hjjeon 0:7a9cde4dbf0b 1538 if( pppoe_recv_count >= 50)
hjjeon 0:7a9cde4dbf0b 1539 {
hjjeon 0:7a9cde4dbf0b 1540 if(do_lcp_terminate() == 0) //if termination is failed.
hjjeon 0:7a9cde4dbf0b 1541 return 0;
hjjeon 0:7a9cde4dbf0b 1542 }
hjjeon 0:7a9cde4dbf0b 1543
hjjeon 0:7a9cde4dbf0b 1544 break;
hjjeon 0:7a9cde4dbf0b 1545
hjjeon 0:7a9cde4dbf0b 1546 case PPPoE_IPCP : // IPCP
hjjeon 0:7a9cde4dbf0b 1547 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1548 printf("\r\n=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1549 printf("PHASE 4. PPPoE IPCP\r\n");
hjjeon 0:7a9cde4dbf0b 1550 printf("=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1551 #endif
hjjeon 0:7a9cde4dbf0b 1552
hjjeon 0:7a9cde4dbf0b 1553 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1554 while((pppoe_control_flag & FLAG_IPCP_CR_RCV) == 0 && pppoe_recv_count < PPP_MAX_RETRYRECV_COUNT)
hjjeon 0:7a9cde4dbf0b 1555 {
hjjeon 0:7a9cde4dbf0b 1556 wait(1);
hjjeon 0:7a9cde4dbf0b 1557 pppoe_recv_count++;
hjjeon 0:7a9cde4dbf0b 1558
hjjeon 0:7a9cde4dbf0b 1559 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1560 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1561 {
hjjeon 0:7a9cde4dbf0b 1562 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1563
hjjeon 0:7a9cde4dbf0b 1564 if((pppoe_control_flag & FLAG_IPCP_CR_RCV) == FLAG_IPCP_CR_RCV) pppoe_retry_send_count = 0;//reset
hjjeon 0:7a9cde4dbf0b 1565
hjjeon 0:7a9cde4dbf0b 1566 }
hjjeon 0:7a9cde4dbf0b 1567
hjjeon 0:7a9cde4dbf0b 1568 }
hjjeon 0:7a9cde4dbf0b 1569 // After received IPCP Configuration-Request and sent ACK,
hjjeon 0:7a9cde4dbf0b 1570 // User device have to send IPCP Configuration-Request and receive ACK.
hjjeon 0:7a9cde4dbf0b 1571 if((pppoe_control_flag & FLAG_IPCP_CR_RCV) == FLAG_IPCP_CR_RCV)
hjjeon 0:7a9cde4dbf0b 1572 {
hjjeon 0:7a9cde4dbf0b 1573 do_ipcp();
hjjeon 0:7a9cde4dbf0b 1574 pppoe_retry_send_count++;
hjjeon 0:7a9cde4dbf0b 1575
hjjeon 0:7a9cde4dbf0b 1576 pppoe_recv_count = 0;
hjjeon 0:7a9cde4dbf0b 1577 while((pppoe_control_flag & FLAG_IPCP_CR_SNT) == 0 && pppoe_recv_count < PPP_MAX_RETRYRECV_COUNT)
hjjeon 0:7a9cde4dbf0b 1578 {
hjjeon 0:7a9cde4dbf0b 1579 wait(1);
hjjeon 0:7a9cde4dbf0b 1580 pppoe_recv_count++;
hjjeon 0:7a9cde4dbf0b 1581
hjjeon 0:7a9cde4dbf0b 1582 received_len = eth->getSn_RX_RSR(sock_num);
hjjeon 0:7a9cde4dbf0b 1583 if(received_len > 0)
hjjeon 0:7a9cde4dbf0b 1584 {
hjjeon 0:7a9cde4dbf0b 1585 ppp_recv(received_len);
hjjeon 0:7a9cde4dbf0b 1586
hjjeon 0:7a9cde4dbf0b 1587 if((pppoe_control_flag & FLAG_IPCP_CR_SNT) == FLAG_IPCP_CR_SNT)
hjjeon 0:7a9cde4dbf0b 1588 {
hjjeon 0:7a9cde4dbf0b 1589 pppoe_retry_send_count = 0;//reset
hjjeon 0:7a9cde4dbf0b 1590 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1591 printf("\r\n=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1592 printf("PHASE 5. PPPoE Socket open\r\n");
hjjeon 0:7a9cde4dbf0b 1593 printf("=======================================\r\n");
hjjeon 0:7a9cde4dbf0b 1594 #endif
hjjeon 0:7a9cde4dbf0b 1595 set_pppinfo(NAS_mac, pppoe_ip, NAS_sessionid);
hjjeon 0:7a9cde4dbf0b 1596 ret = PPP_SUCCESS;
hjjeon 0:7a9cde4dbf0b 1597 }
hjjeon 0:7a9cde4dbf0b 1598 else if( (pppoe_control_flag & FLAG_TERMINATION_ACK_RCV) == FLAG_TERMINATION_ACK_RCV)
hjjeon 0:7a9cde4dbf0b 1599 {
hjjeon 0:7a9cde4dbf0b 1600 return 0;
hjjeon 0:7a9cde4dbf0b 1601 }
hjjeon 0:7a9cde4dbf0b 1602 else if( (pppoe_control_flag & FLAG_TERMINATION_REQ_RCV) == FLAG_TERMINATION_REQ_RCV)
hjjeon 0:7a9cde4dbf0b 1603 {
hjjeon 0:7a9cde4dbf0b 1604 return 0;
hjjeon 0:7a9cde4dbf0b 1605 }
hjjeon 0:7a9cde4dbf0b 1606 }
hjjeon 0:7a9cde4dbf0b 1607 }
hjjeon 0:7a9cde4dbf0b 1608 }
hjjeon 0:7a9cde4dbf0b 1609 break;
hjjeon 0:7a9cde4dbf0b 1610
hjjeon 0:7a9cde4dbf0b 1611 case PPPoE_FAILED :
hjjeon 0:7a9cde4dbf0b 1612 pppoe_retry_count++;
hjjeon 0:7a9cde4dbf0b 1613 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1614 printf("\r\nPPPoE FAILED !!!\r\n");
hjjeon 0:7a9cde4dbf0b 1615 #endif
hjjeon 0:7a9cde4dbf0b 1616 #ifdef __DEF_PPP_DBG1__
hjjeon 0:7a9cde4dbf0b 1617 printf("Retry count : %d\r\n", pppoe_retry_count);
hjjeon 0:7a9cde4dbf0b 1618 #endif
hjjeon 0:7a9cde4dbf0b 1619 // All flags reset
hjjeon 0:7a9cde4dbf0b 1620 pppoe_control_flag = 0;
hjjeon 0:7a9cde4dbf0b 1621
hjjeon 0:7a9cde4dbf0b 1622 // Clear Session ID for new PPPoE Discovery process
hjjeon 0:7a9cde4dbf0b 1623 //NAS_sessionid = 0;
hjjeon 0:7a9cde4dbf0b 1624
hjjeon 0:7a9cde4dbf0b 1625 pppoe_retry_send_count = 0;
hjjeon 0:7a9cde4dbf0b 1626 pppoe_state = PPPoE_DISCOVERY;
hjjeon 0:7a9cde4dbf0b 1627
hjjeon 0:7a9cde4dbf0b 1628 break;
hjjeon 0:7a9cde4dbf0b 1629
hjjeon 0:7a9cde4dbf0b 1630
hjjeon 0:7a9cde4dbf0b 1631 default :
hjjeon 0:7a9cde4dbf0b 1632 #ifdef __DEF_PPP_DBG__
hjjeon 0:7a9cde4dbf0b 1633 printf("\r\nUndefined state!\r\n");
hjjeon 0:7a9cde4dbf0b 1634 #endif
hjjeon 0:7a9cde4dbf0b 1635 pppoe_state = PPPoE_FAILED;
hjjeon 0:7a9cde4dbf0b 1636 break;
hjjeon 0:7a9cde4dbf0b 1637 }
hjjeon 0:7a9cde4dbf0b 1638
hjjeon 0:7a9cde4dbf0b 1639 // PPPoE packet send count over : connection terminate
hjjeon 0:7a9cde4dbf0b 1640 if(pppoe_retry_send_count >= PPP_MAX_RETRYSEND_COUNT) pppoe_state = PPPoE_FAILED;
hjjeon 0:7a9cde4dbf0b 1641 break;
hjjeon 0:7a9cde4dbf0b 1642
hjjeon 0:7a9cde4dbf0b 1643 default:
hjjeon 0:7a9cde4dbf0b 1644 break;
hjjeon 0:7a9cde4dbf0b 1645 }
hjjeon 0:7a9cde4dbf0b 1646 return ret;
hjjeon 0:7a9cde4dbf0b 1647 }
hjjeon 0:7a9cde4dbf0b 1648 /*
hjjeon 0:7a9cde4dbf0b 1649 void PPPOEClient::delay_ms(uint32_t time)
hjjeon 0:7a9cde4dbf0b 1650 {
hjjeon 0:7a9cde4dbf0b 1651 uint32_t i;
hjjeon 0:7a9cde4dbf0b 1652
hjjeon 0:7a9cde4dbf0b 1653 for(i=0; i<time; i++)
hjjeon 0:7a9cde4dbf0b 1654 {
hjjeon 0:7a9cde4dbf0b 1655 xSysCtlDelay((xSysCtlClockGet()/1000)); // wait 1ms
hjjeon 0:7a9cde4dbf0b 1656 }
hjjeon 0:7a9cde4dbf0b 1657 }
hjjeon 0:7a9cde4dbf0b 1658 */