Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package eapol |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 20 | "context" |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 21 | "crypto/md5" |
| 22 | "errors" |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 23 | "net" |
| 24 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 25 | "github.com/google/gopacket" |
| 26 | "github.com/google/gopacket/layers" |
| 27 | "github.com/looplab/fsm" |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 28 | bbsim "github.com/opencord/bbsim/internal/bbsim/types" |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 29 | omci "github.com/opencord/omci-sim" |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v4/go/openolt" |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 31 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | var eapolLogger = log.WithFields(log.Fields{ |
| 35 | "module": "EAPOL", |
| 36 | }) |
| 37 | |
| 38 | var eapolVersion uint8 = 1 |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 39 | var GetGemPortId = omci.GetGemPortId |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 40 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 41 | func sendEapolPktIn(msg bbsim.ByteMsg, portNo uint32, gemid uint32, stream bbsim.Stream) error { |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 42 | // FIXME unify sendDHCPPktIn and sendEapolPktIn methods |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 43 | |
| 44 | log.WithFields(log.Fields{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 45 | "OnuId": msg.OnuId, |
| 46 | "IntfId": msg.IntfId, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 47 | "GemPort": gemid, |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 48 | "Type": "EAPOL", |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 49 | }).Trace("sending-pkt") |
| 50 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 51 | data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{ |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 52 | IntfType: "pon", |
| 53 | IntfId: msg.IntfId, |
| 54 | GemportId: uint32(gemid), |
| 55 | Pkt: msg.Bytes, |
| 56 | PortNo: portNo, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 57 | }} |
| 58 | |
| 59 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 60 | eapolLogger.Errorf("Fail to send EAPOL PktInd indication. %v", err) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 61 | return err |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 62 | } |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 63 | return nil |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | func 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 78 | func 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 Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 89 | func createEAPChallengeResponse(eapId uint8, payload []byte) *layers.EAP { |
| 90 | eap := layers.EAP{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 91 | Code: layers.EAPCodeResponse, |
| 92 | Id: eapId, |
| 93 | Length: 22, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 94 | Type: layers.EAPTypeOTP, |
| 95 | TypeData: payload, |
| 96 | } |
| 97 | return &eap |
| 98 | } |
| 99 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 100 | func 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 Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 109 | func 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 118 | func 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 Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 128 | func createEAPOLPkt(eap *layers.EAP, onuId uint32, intfId uint32) []byte { |
| 129 | buffer := gopacket.NewSerializeBuffer() |
| 130 | options := gopacket.SerializeOptions{} |
| 131 | |
| 132 | ethernetLayer := &layers.Ethernet{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 133 | SrcMAC: net.HardwareAddr{0x2e, 0x60, byte(0), byte(intfId), byte(onuId), byte(0)}, |
| 134 | DstMAC: net.HardwareAddr{0x2e, 0x60, byte(0), byte(intfId), byte(onuId), byte(0)}, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 135 | EthernetType: layers.EthernetTypeEAPOL, |
| 136 | } |
| 137 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 138 | _ = gopacket.SerializeLayers(buffer, options, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 139 | ethernetLayer, |
| 140 | &layers.EAPOL{Version: eapolVersion, Type: 0, Length: eap.Length}, |
| 141 | eap, |
| 142 | ) |
| 143 | |
| 144 | bytes := buffer.Bytes() |
| 145 | return bytes |
| 146 | } |
| 147 | |
| 148 | func 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 157 | func 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 | |
| 166 | func 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 Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 181 | func 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 Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 193 | func SendEapStart(onuId uint32, ponPortId uint32, serialNumber string, portNo uint32, macAddress net.HardwareAddr, gemPort uint32, stateMachine *fsm.FSM, stream bbsim.Stream) error { |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 194 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 195 | // TODO use createEAPOLPkt |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 196 | buffer := gopacket.NewSerializeBuffer() |
| 197 | options := gopacket.SerializeOptions{} |
| 198 | |
| 199 | ethernetLayer := &layers.Ethernet{ |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 200 | SrcMAC: macAddress, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 201 | DstMAC: net.HardwareAddr{0x01, 0x80, 0xC2, 0x00, 0x00, 0x03}, |
| 202 | EthernetType: layers.EthernetTypeEAPOL, |
| 203 | } |
| 204 | |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 205 | _ = gopacket.SerializeLayers(buffer, options, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 206 | ethernetLayer, |
| 207 | &layers.EAPOL{Version: eapolVersion, Type: 1, Length: 0}, |
| 208 | ) |
| 209 | |
| 210 | msg := buffer.Bytes() |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 211 | // TODO end createEAPOLPkt |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 212 | |
| 213 | data := &openolt.Indication_PktInd{ |
| 214 | PktInd: &openolt.PacketIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 215 | IntfType: "pon", |
| 216 | IntfId: ponPortId, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 217 | GemportId: gemPort, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 218 | Pkt: msg, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 219 | PortNo: portNo, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 220 | }, |
| 221 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 222 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 223 | err := stream.Send(&openolt.Indication{Data: data}) |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 224 | if err != nil { |
| 225 | eapolLogger.WithFields(log.Fields{ |
| 226 | "OnuId": onuId, |
| 227 | "IntfId": ponPortId, |
| 228 | "OnuSn": serialNumber, |
| 229 | }).Errorf("Can't send EapStart Message: %s", err) |
| 230 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 231 | if err := updateAuthFailed(onuId, ponPortId, serialNumber, stateMachine); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 232 | return err |
| 233 | } |
| 234 | return err |
| 235 | } |
| 236 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 237 | eapolLogger.WithFields(log.Fields{ |
| 238 | "OnuId": onuId, |
| 239 | "IntfId": ponPortId, |
| 240 | "OnuSn": serialNumber, |
| 241 | "PortNo": portNo, |
| 242 | }).Debugf("Sent EapStart packet") |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 243 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 244 | if err := stateMachine.Event("eap_start_sent"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 245 | eapolLogger.WithFields(log.Fields{ |
| 246 | "OnuId": onuId, |
| 247 | "IntfId": ponPortId, |
| 248 | "OnuSn": serialNumber, |
| 249 | }).Errorf("Error while transitioning ONU State %v", err) |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 250 | return err |
| 251 | } |
| 252 | return nil |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 253 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 254 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 255 | func HandleNextPacket(onuId uint32, ponPortId uint32, gemPortId uint32, serialNumber string, portNo uint32, stateMachine *fsm.FSM, pkt gopacket.Packet, stream bbsim.Stream, client openolt.OpenoltClient) { |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 256 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 257 | eap, eapErr := extractEAP(pkt) |
| 258 | |
| 259 | eapol, eapolErr := extractEAPOL(pkt) |
| 260 | |
| 261 | if eapErr != nil && eapolErr != nil { |
| 262 | log.Fatalf("Failed to Extract EAP: %v - %v", eapErr, eapolErr) |
| 263 | return |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 266 | fields := log.Fields{} |
| 267 | if eap != nil { |
| 268 | fields = log.Fields{ |
| 269 | "Code": eap.Code, |
| 270 | "Type": eap.Type, |
| 271 | "OnuId": onuId, |
| 272 | "IntfId": ponPortId, |
| 273 | "OnuSn": serialNumber, |
| 274 | } |
| 275 | } else if eapol != nil { |
| 276 | fields = log.Fields{ |
| 277 | "Type": eapol.Type, |
| 278 | "OnuId": onuId, |
| 279 | "IntfId": ponPortId, |
| 280 | "OnuSn": serialNumber, |
| 281 | } |
| 282 | } |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 283 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 284 | log.WithFields(fields).Tracef("Handle Next EAPOL Packet") |
| 285 | |
| 286 | if eapol != nil && eapol.Type == layers.EAPOLTypeStart { |
| 287 | identityRequest := createEAPIdentityRequest(1) |
| 288 | pkt := createEAPOLPkt(identityRequest, onuId, ponPortId) |
| 289 | |
| 290 | if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil { |
| 291 | log.WithFields(log.Fields{ |
| 292 | "OnuId": onuId, |
| 293 | "IntfId": ponPortId, |
| 294 | "OnuSn": serialNumber, |
| 295 | "error": err, |
| 296 | }).Errorf("Error while sending EAPIdentityRequest packet") |
| 297 | return |
| 298 | } |
| 299 | |
| 300 | log.WithFields(log.Fields{ |
| 301 | "OnuId": onuId, |
| 302 | "IntfId": ponPortId, |
| 303 | "OnuSn": serialNumber, |
| 304 | }).Infof("Sent EAPIdentityRequest packet") |
| 305 | return |
| 306 | } else if eap.Code == layers.EAPCodeRequest && eap.Type == layers.EAPTypeIdentity { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 307 | reseap := createEAPIdentityResponse(eap.Id) |
| 308 | pkt := createEAPOLPkt(reseap, onuId, ponPortId) |
| 309 | |
| 310 | msg := bbsim.ByteMsg{ |
| 311 | IntfId: ponPortId, |
| 312 | OnuId: onuId, |
| 313 | Bytes: pkt, |
| 314 | } |
| 315 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 316 | if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil { |
| 317 | _ = stateMachine.Event("auth_failed") |
| 318 | return |
| 319 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 320 | eapolLogger.WithFields(log.Fields{ |
| 321 | "OnuId": onuId, |
| 322 | "IntfId": ponPortId, |
| 323 | "OnuSn": serialNumber, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 324 | "PortNo": portNo, |
| 325 | }).Debugf("Sent EAPIdentityResponse packet") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 326 | if err := stateMachine.Event("eap_response_identity_sent"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 327 | eapolLogger.WithFields(log.Fields{ |
| 328 | "OnuId": onuId, |
| 329 | "IntfId": ponPortId, |
| 330 | "OnuSn": serialNumber, |
| 331 | }).Errorf("Error while transitioning ONU State %v", err) |
| 332 | } |
| 333 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 334 | } else if eap.Code == layers.EAPCodeResponse && eap.Type == layers.EAPTypeIdentity { |
| 335 | senddata := getMD5Data(eap) |
| 336 | senddata = append([]byte{0x10}, senddata...) |
| 337 | challengeRequest := createEAPChallengeRequest(eap.Id, senddata) |
| 338 | pkt := createEAPOLPkt(challengeRequest, onuId, ponPortId) |
| 339 | |
| 340 | if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil { |
| 341 | log.WithFields(log.Fields{ |
| 342 | "OnuId": onuId, |
| 343 | "IntfId": ponPortId, |
| 344 | "OnuSn": serialNumber, |
| 345 | "error": err, |
| 346 | }).Errorf("Error while sending EAPChallengeRequest packet") |
| 347 | return |
| 348 | } |
| 349 | log.WithFields(log.Fields{ |
| 350 | "OnuId": onuId, |
| 351 | "IntfId": ponPortId, |
| 352 | "OnuSn": serialNumber, |
| 353 | }).Infof("Sent EAPChallengeRequest packet") |
| 354 | return |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 355 | } else if eap.Code == layers.EAPCodeRequest && eap.Type == layers.EAPTypeOTP { |
| 356 | senddata := getMD5Data(eap) |
| 357 | senddata = append([]byte{0x10}, senddata...) |
| 358 | sendeap := createEAPChallengeResponse(eap.Id, senddata) |
| 359 | pkt := createEAPOLPkt(sendeap, onuId, ponPortId) |
| 360 | |
| 361 | msg := bbsim.ByteMsg{ |
| 362 | IntfId: ponPortId, |
| 363 | OnuId: onuId, |
| 364 | Bytes: pkt, |
| 365 | } |
| 366 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 367 | if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil { |
| 368 | _ = stateMachine.Event("auth_failed") |
| 369 | return |
| 370 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 371 | eapolLogger.WithFields(log.Fields{ |
| 372 | "OnuId": onuId, |
| 373 | "IntfId": ponPortId, |
| 374 | "OnuSn": serialNumber, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 375 | "PortNo": portNo, |
| 376 | }).Debugf("Sent EAPChallengeResponse packet") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 377 | if err := stateMachine.Event("eap_response_challenge_sent"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 378 | eapolLogger.WithFields(log.Fields{ |
| 379 | "OnuId": onuId, |
| 380 | "IntfId": ponPortId, |
| 381 | "OnuSn": serialNumber, |
| 382 | }).Errorf("Error while transitioning ONU State %v", err) |
| 383 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 384 | } else if eap.Code == layers.EAPCodeResponse && eap.Type == layers.EAPTypeOTP { |
| 385 | eapSuccess := createEAPSuccess(eap.Id) |
| 386 | pkt := createEAPOLPkt(eapSuccess, onuId, ponPortId) |
| 387 | |
| 388 | if err := sendEapolPktOut(client, ponPortId, onuId, pkt); err != nil { |
| 389 | log.WithFields(log.Fields{ |
| 390 | "OnuId": onuId, |
| 391 | "IntfId": ponPortId, |
| 392 | "OnuSn": serialNumber, |
| 393 | "error": err, |
| 394 | }).Errorf("Error while sending EAPSuccess packet") |
| 395 | return |
| 396 | } |
| 397 | |
| 398 | log.WithFields(log.Fields{ |
| 399 | "OnuId": onuId, |
| 400 | "IntfId": ponPortId, |
| 401 | "OnuSn": serialNumber, |
| 402 | }).Infof("Sent EAP Success packet") |
| 403 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 404 | if err := stateMachine.Event("send_dhcp_flow"); err != nil { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 405 | eapolLogger.WithFields(log.Fields{ |
| 406 | "OnuId": onuId, |
| 407 | "IntfId": ponPortId, |
| 408 | "OnuSn": serialNumber, |
| 409 | }).Errorf("Error while transitioning ONU State %v", err) |
| 410 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 411 | } else if eap.Code == layers.EAPCodeSuccess && eap.Type == layers.EAPTypeNone { |
| 412 | eapolLogger.WithFields(log.Fields{ |
| 413 | "OnuId": onuId, |
| 414 | "IntfId": ponPortId, |
| 415 | "OnuSn": serialNumber, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 416 | "PortNo": portNo, |
| 417 | }).Debugf("Received EAPSuccess packet") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 418 | if err := stateMachine.Event("eap_response_success_received"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 419 | eapolLogger.WithFields(log.Fields{ |
| 420 | "OnuId": onuId, |
| 421 | "IntfId": ponPortId, |
| 422 | "OnuSn": serialNumber, |
| 423 | }).Errorf("Error while transitioning ONU State %v", err) |
| 424 | } |
| 425 | eapolLogger.WithFields(log.Fields{ |
| 426 | "OnuId": onuId, |
| 427 | "IntfId": ponPortId, |
| 428 | "OnuSn": serialNumber, |
| 429 | }).Infof("EAPOL State machine completed") |
| 430 | return |
| 431 | } |
| 432 | } |