blob: 173727b8d0e845c00d8bf8e579cf2c18f690fd1b [file] [log] [blame]
Matteo Scandolo47e69bb2019-08-28 15:41:12 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package eapol
18
19import (
Matteo Scandolo40e067f2019-10-16 16:59:41 -070020 "context"
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070021 "crypto/md5"
22 "errors"
Shrey Baid688b4242020-07-10 20:40:10 +053023 "net"
24
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070025 "github.com/google/gopacket"
26 "github.com/google/gopacket/layers"
27 "github.com/looplab/fsm"
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070028 bbsim "github.com/opencord/bbsim/internal/bbsim/types"
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070029 "github.com/opencord/voltha-protos/v4/go/openolt"
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070030 log "github.com/sirupsen/logrus"
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070031)
32
33var eapolLogger = log.WithFields(log.Fields{
34 "module": "EAPOL",
35})
36
37var eapolVersion uint8 = 1
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070038
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070039func sendEapolPktIn(msg bbsim.ByteMsg, portNo uint32, gemid uint32, stream bbsim.Stream) error {
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070040 // FIXME unify sendDHCPPktIn and sendEapolPktIn methods
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070041
42 log.WithFields(log.Fields{
Shrey Baid688b4242020-07-10 20:40:10 +053043 "OnuId": msg.OnuId,
44 "IntfId": msg.IntfId,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070045 "GemPort": gemid,
Shrey Baid688b4242020-07-10 20:40:10 +053046 "Type": "EAPOL",
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070047 }).Trace("sending-pkt")
48
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070049 data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{
Matteo Scandolo27428702019-10-11 16:21:16 -070050 IntfType: "pon",
51 IntfId: msg.IntfId,
52 GemportId: uint32(gemid),
53 Pkt: msg.Bytes,
54 PortNo: portNo,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070055 }}
56
57 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
58 eapolLogger.Errorf("Fail to send EAPOL PktInd indication. %v", err)
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070059 return err
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070060 }
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070061 return nil
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070062}
63
64func getMD5Data(eap *layers.EAP) []byte {
65 i := byte(eap.Id)
66 C := []byte(eap.BaseLayer.Contents)[6:]
67 P := []byte{i, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64} // "password"
68 data := md5.Sum(append(P, C...))
69 ret := make([]byte, 16)
70 for j := 0; j < 16; j++ {
71 ret[j] = data[j]
72 }
73 return ret
74}
75
Matteo Scandolo40e067f2019-10-16 16:59:41 -070076func createEAPChallengeRequest(eapId uint8, payload []byte) *layers.EAP {
77 eap := layers.EAP{
78 Code: layers.EAPCodeRequest,
79 Id: eapId,
80 Length: 22,
81 Type: layers.EAPTypeOTP,
82 TypeData: payload,
83 }
84 return &eap
85}
86
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070087func createEAPChallengeResponse(eapId uint8, payload []byte) *layers.EAP {
88 eap := layers.EAP{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070089 Code: layers.EAPCodeResponse,
90 Id: eapId,
91 Length: 22,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070092 Type: layers.EAPTypeOTP,
93 TypeData: payload,
94 }
95 return &eap
96}
97
Matteo Scandolo40e067f2019-10-16 16:59:41 -070098func createEAPIdentityRequest(eapId uint8) *layers.EAP {
99 eap := layers.EAP{Code: layers.EAPCodeRequest,
100 Id: eapId,
101 Length: 9,
102 Type: layers.EAPTypeIdentity,
103 TypeData: []byte{0x75, 0x73, 0x65, 0x72}}
104 return &eap
105}
106
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700107func createEAPIdentityResponse(eapId uint8) *layers.EAP {
108 eap := layers.EAP{Code: layers.EAPCodeResponse,
109 Id: eapId,
110 Length: 9,
111 Type: layers.EAPTypeIdentity,
112 TypeData: []byte{0x75, 0x73, 0x65, 0x72}}
113 return &eap
114}
115
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700116func createEAPSuccess(eapId uint8) *layers.EAP {
117 eap := layers.EAP{
118 Code: layers.EAPCodeSuccess,
119 Id: eapId,
120 Length: 9,
121 Type: layers.EAPTypeNone,
122 TypeData: []byte{0x75, 0x73, 0x65, 0x72}}
123 return &eap
124}
125
Matteo Scandolo8a574812021-05-20 15:18:53 -0700126func createEAPOLPkt(eap *layers.EAP, serviceId uint32, uniId uint32, onuId uint32, intfId uint32, oltId int) []byte {
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700127 buffer := gopacket.NewSerializeBuffer()
128 options := gopacket.SerializeOptions{}
129
Matteo Scandolo8a574812021-05-20 15:18:53 -0700130 mac := net.HardwareAddr{0x2e, byte(oltId), byte(intfId), byte(onuId), byte(uniId), byte(serviceId)}
131 //net.HardwareAddr{0x2e, 0x60, byte(0), byte(intfId), byte(onuId), byte(0)},
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700132 ethernetLayer := &layers.Ethernet{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700133 SrcMAC: mac,
134 DstMAC: mac,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700135 EthernetType: layers.EthernetTypeEAPOL,
136 }
137
Shrey Baid688b4242020-07-10 20:40:10 +0530138 _ = gopacket.SerializeLayers(buffer, options,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700139 ethernetLayer,
140 &layers.EAPOL{Version: eapolVersion, Type: 0, Length: eap.Length},
141 eap,
142 )
143
144 bytes := buffer.Bytes()
145 return bytes
146}
147
148func extractEAP(pkt gopacket.Packet) (*layers.EAP, error) {
149 layerEAP := pkt.Layer(layers.LayerTypeEAP)
150 eap, _ := layerEAP.(*layers.EAP)
151 if eap == nil {
152 return nil, errors.New("Cannot extract EAP")
153 }
154 return eap, nil
155}
156
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700157func extractEAPOL(pkt gopacket.Packet) (*layers.EAPOL, error) {
158 layerEAPOL := pkt.Layer(layers.LayerTypeEAPOL)
159 eap, _ := layerEAPOL.(*layers.EAPOL)
160 if eap == nil {
161 return nil, errors.New("Cannot extract EAPOL")
162 }
163 return eap, nil
164}
165
166func sendEapolPktOut(client openolt.OpenoltClient, intfId uint32, onuId uint32, pkt []byte) error {
167 onuPacket := openolt.OnuPacket{
168 IntfId: intfId,
169 OnuId: onuId,
170 PortNo: onuId,
171 GemportId: 1,
172 Pkt: pkt,
173 }
174
175 if _, err := client.OnuPacketOut(context.Background(), &onuPacket); err != nil {
176 return err
177 }
178 return nil
179}
180
Matteo Scandolo075b1892019-10-07 12:11:07 -0700181func updateAuthFailed(onuId uint32, ponPortId uint32, serialNumber string, onuStateMachine *fsm.FSM) error {
182 if err := onuStateMachine.Event("auth_failed"); err != nil {
183 eapolLogger.WithFields(log.Fields{
184 "OnuId": onuId,
185 "IntfId": ponPortId,
186 "OnuSn": serialNumber,
187 }).Errorf("Error while transitioning ONU State %v", err)
188 return err
189 }
190 return nil
191}
192
Matteo Scandolo8a574812021-05-20 15:18:53 -0700193func SendEapStart(onuId uint32, ponPortId uint32, serialNumber string, portNo uint32, macAddress net.HardwareAddr, gemPort uint32, uniId uint32, stateMachine *fsm.FSM, stream bbsim.Stream) error {
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700194
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700195 // TODO use createEAPOLPkt
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700196 buffer := gopacket.NewSerializeBuffer()
197 options := gopacket.SerializeOptions{}
198
199 ethernetLayer := &layers.Ethernet{
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700200 SrcMAC: macAddress,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700201 DstMAC: net.HardwareAddr{0x01, 0x80, 0xC2, 0x00, 0x00, 0x03},
202 EthernetType: layers.EthernetTypeEAPOL,
203 }
204
Shrey Baid688b4242020-07-10 20:40:10 +0530205 _ = gopacket.SerializeLayers(buffer, options,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700206 ethernetLayer,
207 &layers.EAPOL{Version: eapolVersion, Type: 1, Length: 0},
208 )
209
210 msg := buffer.Bytes()
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700211 // TODO end createEAPOLPkt
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700212
Matteo Scandolo8a574812021-05-20 15:18:53 -0700213 // TODO the adapter uses Onu, Uni and gemPort to route the packet,
214 // stop using PortNo to ensure consistent behavior
215 // requires voltha-protos:4.1.6
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700216 data := &openolt.Indication_PktInd{
217 PktInd: &openolt.PacketIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700218 IntfType: "pon",
219 IntfId: ponPortId,
Matteo Scandolo4a036262020-08-17 15:56:13 -0700220 GemportId: gemPort,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700221 Pkt: msg,
Matteo Scandolo27428702019-10-11 16:21:16 -0700222 PortNo: portNo,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700223 },
224 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700225
Matteo Scandolo4a036262020-08-17 15:56:13 -0700226 err := stream.Send(&openolt.Indication{Data: data})
Matteo Scandolo075b1892019-10-07 12:11:07 -0700227 if err != nil {
228 eapolLogger.WithFields(log.Fields{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700229 "OnuId": onuId,
230 "IntfId": ponPortId,
231 "OnuSn": serialNumber,
232 "PortNo": portNo,
233 "UniId": uniId,
234 "GemPortId": gemPort,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700235 }).Errorf("Can't send EapStart Message: %s", err)
236
Matteo Scandolo4a036262020-08-17 15:56:13 -0700237 if err := updateAuthFailed(onuId, ponPortId, serialNumber, stateMachine); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700238 return err
239 }
240 return err
241 }
242
Matteo Scandolo27428702019-10-11 16:21:16 -0700243 eapolLogger.WithFields(log.Fields{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700244 "OnuId": onuId,
245 "IntfId": ponPortId,
246 "OnuSn": serialNumber,
247 "PortNo": portNo,
248 "UniId": uniId,
249 "GemPortId": gemPort,
250 }).Debug("Sent EapStart packet")
Matteo Scandolo075b1892019-10-07 12:11:07 -0700251
Matteo Scandolo4a036262020-08-17 15:56:13 -0700252 if err := stateMachine.Event("eap_start_sent"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700253 eapolLogger.WithFields(log.Fields{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700254 "OnuId": onuId,
255 "IntfId": ponPortId,
256 "OnuSn": serialNumber,
257 "PortNo": portNo,
258 "UniId": uniId,
259 "GemPortId": gemPort,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700260 }).Errorf("Error while transitioning ONU State %v", err)
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700261 return err
262 }
263 return nil
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700264}
Matteo Scandolo075b1892019-10-07 12:11:07 -0700265
Matteo Scandolo8a574812021-05-20 15:18:53 -0700266func HandleNextPacket(onuId uint32, ponPortId uint32, gemPortId uint32, serialNumber string, portNo uint32, uniId uint32, serviceId uint32, oltId int, stateMachine *fsm.FSM, pkt gopacket.Packet, stream bbsim.Stream, client openolt.OpenoltClient) {
267 // TODO add uni port ID and portNo to the logs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700268 eap, eapErr := extractEAP(pkt)
269
270 eapol, eapolErr := extractEAPOL(pkt)
271
272 if eapErr != nil && eapolErr != nil {
273 log.Fatalf("Failed to Extract EAP: %v - %v", eapErr, eapolErr)
274 return
Matteo Scandolo075b1892019-10-07 12:11:07 -0700275 }
276
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700277 fields := log.Fields{}
278 if eap != nil {
279 fields = log.Fields{
280 "Code": eap.Code,
281 "Type": eap.Type,
282 "OnuId": onuId,
283 "IntfId": ponPortId,
284 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700285 "PortNo": portNo,
286 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700287 }
288 } else if eapol != nil {
289 fields = log.Fields{
290 "Type": eapol.Type,
291 "OnuId": onuId,
292 "IntfId": ponPortId,
293 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700294 "PortNo": portNo,
295 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700296 }
297 }
Matteo Scandolo27428702019-10-11 16:21:16 -0700298
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700299 log.WithFields(fields).Tracef("Handle Next EAPOL Packet")
300
301 if eapol != nil && eapol.Type == layers.EAPOLTypeStart {
302 identityRequest := createEAPIdentityRequest(1)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700303 pkt := createEAPOLPkt(identityRequest, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700304
305 if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil {
306 log.WithFields(log.Fields{
307 "OnuId": onuId,
308 "IntfId": ponPortId,
309 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700310 "PortNo": portNo,
311 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700312 "error": err,
313 }).Errorf("Error while sending EAPIdentityRequest packet")
314 return
315 }
316
317 log.WithFields(log.Fields{
318 "OnuId": onuId,
319 "IntfId": ponPortId,
320 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700321 "PortNo": portNo,
322 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700323 }).Infof("Sent EAPIdentityRequest packet")
324 return
325 } else if eap.Code == layers.EAPCodeRequest && eap.Type == layers.EAPTypeIdentity {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700326 reseap := createEAPIdentityResponse(eap.Id)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700327 pkt := createEAPOLPkt(reseap, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo075b1892019-10-07 12:11:07 -0700328
329 msg := bbsim.ByteMsg{
330 IntfId: ponPortId,
331 OnuId: onuId,
332 Bytes: pkt,
333 }
334
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700335 if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil {
336 _ = stateMachine.Event("auth_failed")
337 return
338 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700339 eapolLogger.WithFields(log.Fields{
340 "OnuId": onuId,
341 "IntfId": ponPortId,
342 "OnuSn": serialNumber,
Matteo Scandolo27428702019-10-11 16:21:16 -0700343 "PortNo": portNo,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700344 "UniId": uniId,
Matteo Scandolo27428702019-10-11 16:21:16 -0700345 }).Debugf("Sent EAPIdentityResponse packet")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700346 if err := stateMachine.Event("eap_response_identity_sent"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700347 eapolLogger.WithFields(log.Fields{
348 "OnuId": onuId,
349 "IntfId": ponPortId,
350 "OnuSn": serialNumber,
351 }).Errorf("Error while transitioning ONU State %v", err)
352 }
353
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700354 } else if eap.Code == layers.EAPCodeResponse && eap.Type == layers.EAPTypeIdentity {
355 senddata := getMD5Data(eap)
356 senddata = append([]byte{0x10}, senddata...)
357 challengeRequest := createEAPChallengeRequest(eap.Id, senddata)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700358 pkt := createEAPOLPkt(challengeRequest, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700359
360 if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil {
361 log.WithFields(log.Fields{
362 "OnuId": onuId,
363 "IntfId": ponPortId,
364 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700365 "PortNo": portNo,
366 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700367 "error": err,
368 }).Errorf("Error while sending EAPChallengeRequest packet")
369 return
370 }
371 log.WithFields(log.Fields{
372 "OnuId": onuId,
373 "IntfId": ponPortId,
374 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700375 "PortNo": portNo,
376 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700377 }).Infof("Sent EAPChallengeRequest packet")
378 return
Matteo Scandolo075b1892019-10-07 12:11:07 -0700379 } else if eap.Code == layers.EAPCodeRequest && eap.Type == layers.EAPTypeOTP {
380 senddata := getMD5Data(eap)
381 senddata = append([]byte{0x10}, senddata...)
382 sendeap := createEAPChallengeResponse(eap.Id, senddata)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700383 pkt := createEAPOLPkt(sendeap, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo075b1892019-10-07 12:11:07 -0700384
385 msg := bbsim.ByteMsg{
386 IntfId: ponPortId,
387 OnuId: onuId,
388 Bytes: pkt,
389 }
390
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700391 if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil {
392 _ = stateMachine.Event("auth_failed")
393 return
394 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700395 eapolLogger.WithFields(log.Fields{
396 "OnuId": onuId,
397 "IntfId": ponPortId,
398 "OnuSn": serialNumber,
Matteo Scandolo27428702019-10-11 16:21:16 -0700399 "PortNo": portNo,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700400 "UniId": uniId,
Matteo Scandolo27428702019-10-11 16:21:16 -0700401 }).Debugf("Sent EAPChallengeResponse packet")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700402 if err := stateMachine.Event("eap_response_challenge_sent"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700403 eapolLogger.WithFields(log.Fields{
404 "OnuId": onuId,
405 "IntfId": ponPortId,
406 "OnuSn": serialNumber,
407 }).Errorf("Error while transitioning ONU State %v", err)
408 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700409 } else if eap.Code == layers.EAPCodeResponse && eap.Type == layers.EAPTypeOTP {
410 eapSuccess := createEAPSuccess(eap.Id)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700411 pkt := createEAPOLPkt(eapSuccess, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700412
413 if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil {
414 log.WithFields(log.Fields{
415 "OnuId": onuId,
416 "IntfId": ponPortId,
417 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700418 "PortNo": portNo,
419 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700420 "error": err,
421 }).Errorf("Error while sending EAPSuccess packet")
422 return
423 }
424
425 log.WithFields(log.Fields{
426 "OnuId": onuId,
427 "IntfId": ponPortId,
428 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700429 "PortNo": portNo,
430 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700431 }).Infof("Sent EAP Success packet")
432
Matteo Scandolo4a036262020-08-17 15:56:13 -0700433 if err := stateMachine.Event("send_dhcp_flow"); err != nil {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700434 eapolLogger.WithFields(log.Fields{
435 "OnuId": onuId,
436 "IntfId": ponPortId,
437 "OnuSn": serialNumber,
438 }).Errorf("Error while transitioning ONU State %v", err)
439 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700440 } else if eap.Code == layers.EAPCodeSuccess && eap.Type == layers.EAPTypeNone {
441 eapolLogger.WithFields(log.Fields{
442 "OnuId": onuId,
443 "IntfId": ponPortId,
444 "OnuSn": serialNumber,
Matteo Scandolo27428702019-10-11 16:21:16 -0700445 "PortNo": portNo,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700446 "UniId": uniId,
Matteo Scandolo27428702019-10-11 16:21:16 -0700447 }).Debugf("Received EAPSuccess packet")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700448 if err := stateMachine.Event("eap_response_success_received"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700449 eapolLogger.WithFields(log.Fields{
450 "OnuId": onuId,
451 "IntfId": ponPortId,
452 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700453 "PortNo": portNo,
454 "UniId": uniId,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700455 }).Errorf("Error while transitioning ONU State %v", err)
456 }
457 eapolLogger.WithFields(log.Fields{
458 "OnuId": onuId,
459 "IntfId": ponPortId,
460 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700461 "PortNo": portNo,
462 "UniId": uniId,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700463 }).Infof("EAPOL State machine completed")
464 return
465 }
466}