blob: e341cefcd49f644b73fddb4191dea3c16f793339 [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"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000029 "github.com/opencord/voltha-protos/v5/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,
Girish Gowdra62f24292021-05-12 16:28:39 -070055 OnuId: msg.OnuId,
56 UniId: 0, // FIXME: When multi-uni support comes in, this hardcoding has to be removed.
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070057 }}
58
59 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
60 eapolLogger.Errorf("Fail to send EAPOL PktInd indication. %v", err)
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070061 return err
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070062 }
Matteo Scandolo75ed5b92020-09-03 09:03:16 -070063 return nil
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070064}
65
66func getMD5Data(eap *layers.EAP) []byte {
67 i := byte(eap.Id)
68 C := []byte(eap.BaseLayer.Contents)[6:]
69 P := []byte{i, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64} // "password"
70 data := md5.Sum(append(P, C...))
71 ret := make([]byte, 16)
72 for j := 0; j < 16; j++ {
73 ret[j] = data[j]
74 }
75 return ret
76}
77
Matteo Scandolo40e067f2019-10-16 16:59:41 -070078func createEAPChallengeRequest(eapId uint8, payload []byte) *layers.EAP {
79 eap := layers.EAP{
80 Code: layers.EAPCodeRequest,
81 Id: eapId,
82 Length: 22,
83 Type: layers.EAPTypeOTP,
84 TypeData: payload,
85 }
86 return &eap
87}
88
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070089func createEAPChallengeResponse(eapId uint8, payload []byte) *layers.EAP {
90 eap := layers.EAP{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070091 Code: layers.EAPCodeResponse,
92 Id: eapId,
93 Length: 22,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -070094 Type: layers.EAPTypeOTP,
95 TypeData: payload,
96 }
97 return &eap
98}
99
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700100func createEAPIdentityRequest(eapId uint8) *layers.EAP {
101 eap := layers.EAP{Code: layers.EAPCodeRequest,
102 Id: eapId,
103 Length: 9,
104 Type: layers.EAPTypeIdentity,
105 TypeData: []byte{0x75, 0x73, 0x65, 0x72}}
106 return &eap
107}
108
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700109func createEAPIdentityResponse(eapId uint8) *layers.EAP {
110 eap := layers.EAP{Code: layers.EAPCodeResponse,
111 Id: eapId,
112 Length: 9,
113 Type: layers.EAPTypeIdentity,
114 TypeData: []byte{0x75, 0x73, 0x65, 0x72}}
115 return &eap
116}
117
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700118func createEAPSuccess(eapId uint8) *layers.EAP {
119 eap := layers.EAP{
120 Code: layers.EAPCodeSuccess,
121 Id: eapId,
122 Length: 9,
123 Type: layers.EAPTypeNone,
124 TypeData: []byte{0x75, 0x73, 0x65, 0x72}}
125 return &eap
126}
127
Matteo Scandolo8a574812021-05-20 15:18:53 -0700128func createEAPOLPkt(eap *layers.EAP, serviceId uint32, uniId uint32, onuId uint32, intfId uint32, oltId int) []byte {
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700129 buffer := gopacket.NewSerializeBuffer()
130 options := gopacket.SerializeOptions{}
131
Matteo Scandolo8a574812021-05-20 15:18:53 -0700132 mac := net.HardwareAddr{0x2e, byte(oltId), byte(intfId), byte(onuId), byte(uniId), byte(serviceId)}
133 //net.HardwareAddr{0x2e, 0x60, byte(0), byte(intfId), byte(onuId), byte(0)},
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700134 ethernetLayer := &layers.Ethernet{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700135 SrcMAC: mac,
136 DstMAC: mac,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700137 EthernetType: layers.EthernetTypeEAPOL,
138 }
139
Shrey Baid688b4242020-07-10 20:40:10 +0530140 _ = gopacket.SerializeLayers(buffer, options,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700141 ethernetLayer,
142 &layers.EAPOL{Version: eapolVersion, Type: 0, Length: eap.Length},
143 eap,
144 )
145
146 bytes := buffer.Bytes()
147 return bytes
148}
149
150func extractEAP(pkt gopacket.Packet) (*layers.EAP, error) {
151 layerEAP := pkt.Layer(layers.LayerTypeEAP)
152 eap, _ := layerEAP.(*layers.EAP)
153 if eap == nil {
154 return nil, errors.New("Cannot extract EAP")
155 }
156 return eap, nil
157}
158
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700159func extractEAPOL(pkt gopacket.Packet) (*layers.EAPOL, error) {
160 layerEAPOL := pkt.Layer(layers.LayerTypeEAPOL)
161 eap, _ := layerEAPOL.(*layers.EAPOL)
162 if eap == nil {
163 return nil, errors.New("Cannot extract EAPOL")
164 }
165 return eap, nil
166}
167
168func sendEapolPktOut(client openolt.OpenoltClient, intfId uint32, onuId uint32, pkt []byte) error {
169 onuPacket := openolt.OnuPacket{
170 IntfId: intfId,
171 OnuId: onuId,
172 PortNo: onuId,
173 GemportId: 1,
174 Pkt: pkt,
175 }
176
177 if _, err := client.OnuPacketOut(context.Background(), &onuPacket); err != nil {
178 return err
179 }
180 return nil
181}
182
Matteo Scandolo075b1892019-10-07 12:11:07 -0700183func updateAuthFailed(onuId uint32, ponPortId uint32, serialNumber string, onuStateMachine *fsm.FSM) error {
184 if err := onuStateMachine.Event("auth_failed"); err != nil {
185 eapolLogger.WithFields(log.Fields{
186 "OnuId": onuId,
187 "IntfId": ponPortId,
188 "OnuSn": serialNumber,
189 }).Errorf("Error while transitioning ONU State %v", err)
190 return err
191 }
192 return nil
193}
194
Matteo Scandolo8a574812021-05-20 15:18:53 -0700195func 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 -0700196
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700197 // TODO use createEAPOLPkt
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700198 buffer := gopacket.NewSerializeBuffer()
199 options := gopacket.SerializeOptions{}
200
201 ethernetLayer := &layers.Ethernet{
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700202 SrcMAC: macAddress,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700203 DstMAC: net.HardwareAddr{0x01, 0x80, 0xC2, 0x00, 0x00, 0x03},
204 EthernetType: layers.EthernetTypeEAPOL,
205 }
206
Shrey Baid688b4242020-07-10 20:40:10 +0530207 _ = gopacket.SerializeLayers(buffer, options,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700208 ethernetLayer,
209 &layers.EAPOL{Version: eapolVersion, Type: 1, Length: 0},
210 )
211
212 msg := buffer.Bytes()
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700213 // TODO end createEAPOLPkt
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700214
Matteo Scandolo8a574812021-05-20 15:18:53 -0700215 // TODO the adapter uses Onu, Uni and gemPort to route the packet,
216 // stop using PortNo to ensure consistent behavior
217 // requires voltha-protos:4.1.6
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700218 data := &openolt.Indication_PktInd{
219 PktInd: &openolt.PacketIndication{
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700220 IntfType: "pon",
221 IntfId: ponPortId,
Matteo Scandolo4a036262020-08-17 15:56:13 -0700222 GemportId: gemPort,
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700223 Pkt: msg,
Matteo Scandolo27428702019-10-11 16:21:16 -0700224 PortNo: portNo,
Girish Gowdra62f24292021-05-12 16:28:39 -0700225 OnuId: onuId,
226 UniId: uniId,
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700227 },
228 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700229
Matteo Scandolo4a036262020-08-17 15:56:13 -0700230 err := stream.Send(&openolt.Indication{Data: data})
Matteo Scandolo075b1892019-10-07 12:11:07 -0700231 if err != nil {
232 eapolLogger.WithFields(log.Fields{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700233 "OnuId": onuId,
234 "IntfId": ponPortId,
235 "OnuSn": serialNumber,
236 "PortNo": portNo,
237 "UniId": uniId,
238 "GemPortId": gemPort,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700239 }).Errorf("Can't send EapStart Message: %s", err)
240
Matteo Scandolo4a036262020-08-17 15:56:13 -0700241 if err := updateAuthFailed(onuId, ponPortId, serialNumber, stateMachine); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700242 return err
243 }
244 return err
245 }
246
Matteo Scandolo27428702019-10-11 16:21:16 -0700247 eapolLogger.WithFields(log.Fields{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700248 "OnuId": onuId,
249 "IntfId": ponPortId,
250 "OnuSn": serialNumber,
251 "PortNo": portNo,
252 "UniId": uniId,
253 "GemPortId": gemPort,
254 }).Debug("Sent EapStart packet")
Matteo Scandolo075b1892019-10-07 12:11:07 -0700255
Matteo Scandolo4a036262020-08-17 15:56:13 -0700256 if err := stateMachine.Event("eap_start_sent"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700257 eapolLogger.WithFields(log.Fields{
Matteo Scandolo8a574812021-05-20 15:18:53 -0700258 "OnuId": onuId,
259 "IntfId": ponPortId,
260 "OnuSn": serialNumber,
261 "PortNo": portNo,
262 "UniId": uniId,
263 "GemPortId": gemPort,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700264 }).Errorf("Error while transitioning ONU State %v", err)
Matteo Scandolo47e69bb2019-08-28 15:41:12 -0700265 return err
266 }
267 return nil
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -0700268}
Matteo Scandolo075b1892019-10-07 12:11:07 -0700269
Matteo Scandolo8a574812021-05-20 15:18:53 -0700270func 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) {
271 // TODO add uni port ID and portNo to the logs
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700272 eap, eapErr := extractEAP(pkt)
273
274 eapol, eapolErr := extractEAPOL(pkt)
275
276 if eapErr != nil && eapolErr != nil {
277 log.Fatalf("Failed to Extract EAP: %v - %v", eapErr, eapolErr)
278 return
Matteo Scandolo075b1892019-10-07 12:11:07 -0700279 }
280
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700281 fields := log.Fields{}
282 if eap != nil {
283 fields = log.Fields{
284 "Code": eap.Code,
285 "Type": eap.Type,
286 "OnuId": onuId,
287 "IntfId": ponPortId,
288 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700289 "PortNo": portNo,
290 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700291 }
292 } else if eapol != nil {
293 fields = log.Fields{
294 "Type": eapol.Type,
295 "OnuId": onuId,
296 "IntfId": ponPortId,
297 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700298 "PortNo": portNo,
299 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700300 }
301 }
Matteo Scandolo27428702019-10-11 16:21:16 -0700302
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700303 log.WithFields(fields).Tracef("Handle Next EAPOL Packet")
304
305 if eapol != nil && eapol.Type == layers.EAPOLTypeStart {
306 identityRequest := createEAPIdentityRequest(1)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700307 pkt := createEAPOLPkt(identityRequest, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700308
309 if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil {
310 log.WithFields(log.Fields{
311 "OnuId": onuId,
312 "IntfId": ponPortId,
313 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700314 "PortNo": portNo,
315 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700316 "error": err,
317 }).Errorf("Error while sending EAPIdentityRequest packet")
318 return
319 }
320
321 log.WithFields(log.Fields{
322 "OnuId": onuId,
323 "IntfId": ponPortId,
324 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700325 "PortNo": portNo,
326 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700327 }).Infof("Sent EAPIdentityRequest packet")
328 return
329 } else if eap.Code == layers.EAPCodeRequest && eap.Type == layers.EAPTypeIdentity {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700330 reseap := createEAPIdentityResponse(eap.Id)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700331 pkt := createEAPOLPkt(reseap, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo075b1892019-10-07 12:11:07 -0700332
333 msg := bbsim.ByteMsg{
334 IntfId: ponPortId,
335 OnuId: onuId,
336 Bytes: pkt,
337 }
338
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700339 if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil {
340 _ = stateMachine.Event("auth_failed")
341 return
342 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700343 eapolLogger.WithFields(log.Fields{
344 "OnuId": onuId,
345 "IntfId": ponPortId,
346 "OnuSn": serialNumber,
Matteo Scandolo27428702019-10-11 16:21:16 -0700347 "PortNo": portNo,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700348 "UniId": uniId,
Matteo Scandolo27428702019-10-11 16:21:16 -0700349 }).Debugf("Sent EAPIdentityResponse packet")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700350 if err := stateMachine.Event("eap_response_identity_sent"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700351 eapolLogger.WithFields(log.Fields{
352 "OnuId": onuId,
353 "IntfId": ponPortId,
354 "OnuSn": serialNumber,
355 }).Errorf("Error while transitioning ONU State %v", err)
356 }
357
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700358 } else if eap.Code == layers.EAPCodeResponse && eap.Type == layers.EAPTypeIdentity {
359 senddata := getMD5Data(eap)
360 senddata = append([]byte{0x10}, senddata...)
361 challengeRequest := createEAPChallengeRequest(eap.Id, senddata)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700362 pkt := createEAPOLPkt(challengeRequest, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700363
364 if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil {
365 log.WithFields(log.Fields{
366 "OnuId": onuId,
367 "IntfId": ponPortId,
368 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700369 "PortNo": portNo,
370 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700371 "error": err,
372 }).Errorf("Error while sending EAPChallengeRequest packet")
373 return
374 }
375 log.WithFields(log.Fields{
376 "OnuId": onuId,
377 "IntfId": ponPortId,
378 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700379 "PortNo": portNo,
380 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700381 }).Infof("Sent EAPChallengeRequest packet")
382 return
Matteo Scandolo075b1892019-10-07 12:11:07 -0700383 } else if eap.Code == layers.EAPCodeRequest && eap.Type == layers.EAPTypeOTP {
384 senddata := getMD5Data(eap)
385 senddata = append([]byte{0x10}, senddata...)
386 sendeap := createEAPChallengeResponse(eap.Id, senddata)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700387 pkt := createEAPOLPkt(sendeap, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo075b1892019-10-07 12:11:07 -0700388
389 msg := bbsim.ByteMsg{
390 IntfId: ponPortId,
391 OnuId: onuId,
392 Bytes: pkt,
393 }
394
Matteo Scandolo75ed5b92020-09-03 09:03:16 -0700395 if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil {
396 _ = stateMachine.Event("auth_failed")
397 return
398 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700399 eapolLogger.WithFields(log.Fields{
400 "OnuId": onuId,
401 "IntfId": ponPortId,
402 "OnuSn": serialNumber,
Matteo Scandolo27428702019-10-11 16:21:16 -0700403 "PortNo": portNo,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700404 "UniId": uniId,
Matteo Scandolo27428702019-10-11 16:21:16 -0700405 }).Debugf("Sent EAPChallengeResponse packet")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700406 if err := stateMachine.Event("eap_response_challenge_sent"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700407 eapolLogger.WithFields(log.Fields{
408 "OnuId": onuId,
409 "IntfId": ponPortId,
410 "OnuSn": serialNumber,
411 }).Errorf("Error while transitioning ONU State %v", err)
412 }
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700413 } else if eap.Code == layers.EAPCodeResponse && eap.Type == layers.EAPTypeOTP {
414 eapSuccess := createEAPSuccess(eap.Id)
Matteo Scandolo8a574812021-05-20 15:18:53 -0700415 pkt := createEAPOLPkt(eapSuccess, serviceId, uniId, onuId, ponPortId, oltId)
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700416
417 if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil {
418 log.WithFields(log.Fields{
419 "OnuId": onuId,
420 "IntfId": ponPortId,
421 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700422 "PortNo": portNo,
423 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700424 "error": err,
425 }).Errorf("Error while sending EAPSuccess packet")
426 return
427 }
428
429 log.WithFields(log.Fields{
430 "OnuId": onuId,
431 "IntfId": ponPortId,
432 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700433 "PortNo": portNo,
434 "UniId": uniId,
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700435 }).Infof("Sent EAP Success packet")
436
Matteo Scandolo4a036262020-08-17 15:56:13 -0700437 if err := stateMachine.Event("send_dhcp_flow"); err != nil {
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700438 eapolLogger.WithFields(log.Fields{
439 "OnuId": onuId,
440 "IntfId": ponPortId,
441 "OnuSn": serialNumber,
442 }).Errorf("Error while transitioning ONU State %v", err)
443 }
Matteo Scandolo075b1892019-10-07 12:11:07 -0700444 } else if eap.Code == layers.EAPCodeSuccess && eap.Type == layers.EAPTypeNone {
445 eapolLogger.WithFields(log.Fields{
446 "OnuId": onuId,
447 "IntfId": ponPortId,
448 "OnuSn": serialNumber,
Matteo Scandolo27428702019-10-11 16:21:16 -0700449 "PortNo": portNo,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700450 "UniId": uniId,
Matteo Scandolo27428702019-10-11 16:21:16 -0700451 }).Debugf("Received EAPSuccess packet")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700452 if err := stateMachine.Event("eap_response_success_received"); err != nil {
Matteo Scandolo075b1892019-10-07 12:11:07 -0700453 eapolLogger.WithFields(log.Fields{
454 "OnuId": onuId,
455 "IntfId": ponPortId,
456 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700457 "PortNo": portNo,
458 "UniId": uniId,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700459 }).Errorf("Error while transitioning ONU State %v", err)
460 }
461 eapolLogger.WithFields(log.Fields{
462 "OnuId": onuId,
463 "IntfId": ponPortId,
464 "OnuSn": serialNumber,
Matteo Scandolo8a574812021-05-20 15:18:53 -0700465 "PortNo": portNo,
466 "UniId": uniId,
Matteo Scandolo075b1892019-10-07 12:11:07 -0700467 }).Infof("EAPOL State machine completed")
468 return
469 }
470}