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 | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/v4/go/openolt" |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 30 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | var eapolLogger = log.WithFields(log.Fields{ |
| 34 | "module": "EAPOL", |
| 35 | }) |
| 36 | |
| 37 | var eapolVersion uint8 = 1 |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 38 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 39 | 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] | 40 | // FIXME unify sendDHCPPktIn and sendEapolPktIn methods |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 41 | |
| 42 | log.WithFields(log.Fields{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 43 | "OnuId": msg.OnuId, |
| 44 | "IntfId": msg.IntfId, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 45 | "GemPort": gemid, |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 46 | "Type": "EAPOL", |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 47 | }).Trace("sending-pkt") |
| 48 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 49 | data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{ |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 50 | IntfType: "pon", |
| 51 | IntfId: msg.IntfId, |
| 52 | GemportId: uint32(gemid), |
| 53 | Pkt: msg.Bytes, |
| 54 | PortNo: portNo, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 55 | }} |
| 56 | |
| 57 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 58 | eapolLogger.Errorf("Fail to send EAPOL PktInd indication. %v", err) |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 59 | return err |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 60 | } |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 61 | return nil |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | func 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 76 | func 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 Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 87 | func createEAPChallengeResponse(eapId uint8, payload []byte) *layers.EAP { |
| 88 | eap := layers.EAP{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 89 | Code: layers.EAPCodeResponse, |
| 90 | Id: eapId, |
| 91 | Length: 22, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 92 | Type: layers.EAPTypeOTP, |
| 93 | TypeData: payload, |
| 94 | } |
| 95 | return &eap |
| 96 | } |
| 97 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 98 | func 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 Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 107 | func 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 116 | func 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 126 | func createEAPOLPkt(eap *layers.EAP, serviceId uint32, uniId uint32, onuId uint32, intfId uint32, oltId int) []byte { |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 127 | buffer := gopacket.NewSerializeBuffer() |
| 128 | options := gopacket.SerializeOptions{} |
| 129 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 130 | 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 Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 132 | ethernetLayer := &layers.Ethernet{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 133 | SrcMAC: mac, |
| 134 | DstMAC: mac, |
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 | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 193 | func SendEapStart(onuId uint32, ponPortId uint32, serialNumber string, portNo uint32, macAddress net.HardwareAddr, gemPort uint32, uniId 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 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 213 | // 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 Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 216 | data := &openolt.Indication_PktInd{ |
| 217 | PktInd: &openolt.PacketIndication{ |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 218 | IntfType: "pon", |
| 219 | IntfId: ponPortId, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 220 | GemportId: gemPort, |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 221 | Pkt: msg, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 222 | PortNo: portNo, |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 223 | }, |
| 224 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 225 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 226 | err := stream.Send(&openolt.Indication{Data: data}) |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 227 | if err != nil { |
| 228 | eapolLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 229 | "OnuId": onuId, |
| 230 | "IntfId": ponPortId, |
| 231 | "OnuSn": serialNumber, |
| 232 | "PortNo": portNo, |
| 233 | "UniId": uniId, |
| 234 | "GemPortId": gemPort, |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 235 | }).Errorf("Can't send EapStart Message: %s", err) |
| 236 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 237 | if err := updateAuthFailed(onuId, ponPortId, serialNumber, stateMachine); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 238 | return err |
| 239 | } |
| 240 | return err |
| 241 | } |
| 242 | |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 243 | eapolLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 244 | "OnuId": onuId, |
| 245 | "IntfId": ponPortId, |
| 246 | "OnuSn": serialNumber, |
| 247 | "PortNo": portNo, |
| 248 | "UniId": uniId, |
| 249 | "GemPortId": gemPort, |
| 250 | }).Debug("Sent EapStart packet") |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 251 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 252 | if err := stateMachine.Event("eap_start_sent"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 253 | eapolLogger.WithFields(log.Fields{ |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 254 | "OnuId": onuId, |
| 255 | "IntfId": ponPortId, |
| 256 | "OnuSn": serialNumber, |
| 257 | "PortNo": portNo, |
| 258 | "UniId": uniId, |
| 259 | "GemPortId": gemPort, |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 260 | }).Errorf("Error while transitioning ONU State %v", err) |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 261 | return err |
| 262 | } |
| 263 | return nil |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 264 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 265 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 266 | func 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 268 | 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 Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 277 | 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 285 | "PortNo": portNo, |
| 286 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 287 | } |
| 288 | } else if eapol != nil { |
| 289 | fields = log.Fields{ |
| 290 | "Type": eapol.Type, |
| 291 | "OnuId": onuId, |
| 292 | "IntfId": ponPortId, |
| 293 | "OnuSn": serialNumber, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 294 | "PortNo": portNo, |
| 295 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 298 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 299 | log.WithFields(fields).Tracef("Handle Next EAPOL Packet") |
| 300 | |
| 301 | if eapol != nil && eapol.Type == layers.EAPOLTypeStart { |
| 302 | identityRequest := createEAPIdentityRequest(1) |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 303 | pkt := createEAPOLPkt(identityRequest, serviceId, uniId, onuId, ponPortId, oltId) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 304 | |
| 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 310 | "PortNo": portNo, |
| 311 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 312 | "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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 321 | "PortNo": portNo, |
| 322 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 323 | }).Infof("Sent EAPIdentityRequest packet") |
| 324 | return |
| 325 | } else if eap.Code == layers.EAPCodeRequest && eap.Type == layers.EAPTypeIdentity { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 326 | reseap := createEAPIdentityResponse(eap.Id) |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 327 | pkt := createEAPOLPkt(reseap, serviceId, uniId, onuId, ponPortId, oltId) |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 328 | |
| 329 | msg := bbsim.ByteMsg{ |
| 330 | IntfId: ponPortId, |
| 331 | OnuId: onuId, |
| 332 | Bytes: pkt, |
| 333 | } |
| 334 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 335 | if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil { |
| 336 | _ = stateMachine.Event("auth_failed") |
| 337 | return |
| 338 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 339 | eapolLogger.WithFields(log.Fields{ |
| 340 | "OnuId": onuId, |
| 341 | "IntfId": ponPortId, |
| 342 | "OnuSn": serialNumber, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 343 | "PortNo": portNo, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 344 | "UniId": uniId, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 345 | }).Debugf("Sent EAPIdentityResponse packet") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 346 | if err := stateMachine.Event("eap_response_identity_sent"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 347 | 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 Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 354 | } 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 358 | pkt := createEAPOLPkt(challengeRequest, serviceId, uniId, onuId, ponPortId, oltId) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 359 | |
| 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 365 | "PortNo": portNo, |
| 366 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 367 | "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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 375 | "PortNo": portNo, |
| 376 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 377 | }).Infof("Sent EAPChallengeRequest packet") |
| 378 | return |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 379 | } 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 383 | pkt := createEAPOLPkt(sendeap, serviceId, uniId, onuId, ponPortId, oltId) |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 384 | |
| 385 | msg := bbsim.ByteMsg{ |
| 386 | IntfId: ponPortId, |
| 387 | OnuId: onuId, |
| 388 | Bytes: pkt, |
| 389 | } |
| 390 | |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 391 | if err := sendEapolPktIn(msg, portNo, gemPortId, stream); err != nil { |
| 392 | _ = stateMachine.Event("auth_failed") |
| 393 | return |
| 394 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 395 | eapolLogger.WithFields(log.Fields{ |
| 396 | "OnuId": onuId, |
| 397 | "IntfId": ponPortId, |
| 398 | "OnuSn": serialNumber, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 399 | "PortNo": portNo, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 400 | "UniId": uniId, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 401 | }).Debugf("Sent EAPChallengeResponse packet") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 402 | if err := stateMachine.Event("eap_response_challenge_sent"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 403 | eapolLogger.WithFields(log.Fields{ |
| 404 | "OnuId": onuId, |
| 405 | "IntfId": ponPortId, |
| 406 | "OnuSn": serialNumber, |
| 407 | }).Errorf("Error while transitioning ONU State %v", err) |
| 408 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 409 | } else if eap.Code == layers.EAPCodeResponse && eap.Type == layers.EAPTypeOTP { |
| 410 | eapSuccess := createEAPSuccess(eap.Id) |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 411 | pkt := createEAPOLPkt(eapSuccess, serviceId, uniId, onuId, ponPortId, oltId) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 412 | |
| 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 418 | "PortNo": portNo, |
| 419 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 420 | "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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 429 | "PortNo": portNo, |
| 430 | "UniId": uniId, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 431 | }).Infof("Sent EAP Success packet") |
| 432 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 433 | if err := stateMachine.Event("send_dhcp_flow"); err != nil { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 434 | eapolLogger.WithFields(log.Fields{ |
| 435 | "OnuId": onuId, |
| 436 | "IntfId": ponPortId, |
| 437 | "OnuSn": serialNumber, |
| 438 | }).Errorf("Error while transitioning ONU State %v", err) |
| 439 | } |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 440 | } 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 Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 445 | "PortNo": portNo, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 446 | "UniId": uniId, |
Matteo Scandolo | 2742870 | 2019-10-11 16:21:16 -0700 | [diff] [blame] | 447 | }).Debugf("Received EAPSuccess packet") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 448 | if err := stateMachine.Event("eap_response_success_received"); err != nil { |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 449 | eapolLogger.WithFields(log.Fields{ |
| 450 | "OnuId": onuId, |
| 451 | "IntfId": ponPortId, |
| 452 | "OnuSn": serialNumber, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 453 | "PortNo": portNo, |
| 454 | "UniId": uniId, |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 455 | }).Errorf("Error while transitioning ONU State %v", err) |
| 456 | } |
| 457 | eapolLogger.WithFields(log.Fields{ |
| 458 | "OnuId": onuId, |
| 459 | "IntfId": ponPortId, |
| 460 | "OnuSn": serialNumber, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 461 | "PortNo": portNo, |
| 462 | "UniId": uniId, |
Matteo Scandolo | 075b189 | 2019-10-07 12:11:07 -0700 | [diff] [blame] | 463 | }).Infof("EAPOL State machine completed") |
| 464 | return |
| 465 | } |
| 466 | } |