nimbuscontrols / EIPScanner

Free implementation of EtherNet/IP in C++
https://eipscanner.readthedocs.io/en/latest/
MIT License
241 stars 98 forks source link

Implicit messaging doesn't work with PowerFlex 525 #9

Closed atimin closed 4 years ago

atimin commented 4 years ago

Describe the bug I can open an implicit connection with the device and it is working for a while, but then it is closed by timeout after 10 messages have been received.

To Reproduce I use the following code:


  auto si = std::make_shared<SessionInfo>("172.28.1.3", 0xAF12); // Here I have an exception!!
    ConnectionManager connectionManager(messageRouter);

    ConnectionParameters parameters;
    parameters.connectionPath = {0x20, 0x04,0x24, 6, 0x2C, 2, 0x2C, 1}; 
    parameters.o2tRealTimeFormat = true;
    parameters.originatorVendorId = 342;
    parameters.originatorSerialNumber = 32423;
    parameters.t2oNetworkConnectionParams |= NetworkConnectionParams::P2P;
    parameters.t2oNetworkConnectionParams |= NetworkConnectionParams::SCHEDULED_PRIORITY;
    parameters.t2oNetworkConnectionParams |=12
    parameters.o2tNetworkConnectionParams |= NetworkConnectionParams::P2P;
    parameters.o2tNetworkConnectionParams |= NetworkConnectionParams::SCHEDULED_PRIORITY;
    parameters.o2tNetworkConnectionParams |= 12

    parameters.o2tRPI = 1000000;
    parameters.t2oRPI = 1000000;
    parameters.transportTypeTrigger |= NetworkConnectionParams::CLASS1;

    auto io = connectionManager.forwardOpen(si, parameters);
    if (auto ptr = io.lock()) {
        ptr->setDataToSend(std::vector<uint8_t>(32));

        ptr->setReceiveDataListener([](auto realTimeHeader, auto sequence, auto data) {
            std::ostringstream ss;
            ss << "secNum=" << sequence << " data=";
            for (auto &byte : data) {
                ss << "[" << std::hex << (int) byte << "]";
            }

            Logger(LogLevel::INFO) << "Received: " << ss.str();
        });

        ptr->setCloseListener([]() {
            Logger(LogLevel::INFO) << "Closed";
        });
    }

    int count = 200;
    while (connectionManager.hasOpenConnections() && count-- > 0) {
        connectionManager.handleConnections(std::chrono::milliseconds(100));
    }

    connectionManager.forwardClose(si, io);

    return 0;

Expected behavior I must have received 20 messages instead of 10.

Wireshark dump wrong_communication_with_eipscanner.zip good_communication_with_other_lib.zip

Logs

[DEBUG] Opened socket fd=3
[DEBUG] Parsing IP from 192.168.1.15
[DEBUG] Connecting to 192.168.1.15:44818
[INFO] Registered session 12
[INFO] Send request: service=0x54 epath=[classId=6 objectId=1]
[INFO] Open IO connection O2T_ID=1489698821 T2O_ID=1 SerialNumber 1
[DEBUG] Opened socket fd=4
[DEBUG] Parsing IP from 192.168.1.15
[DEBUG] Opened socket fd=5
[DEBUG] Parsing IP from 192.168.1.15
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=1 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=2 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=3 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=4 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=5 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=6 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=7 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=8 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=9 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[DEBUG] Received data from connection T2O_ID=1
[INFO] Received: secNum=10 data=[0][0][0][0][8c][0][0][0][0][0][0][0]
[WARNING] Connection SeriaNumber=1 is closed by timeout
[INFO] Closed
[DEBUG] Close socket fd=4
[WARNING] Attempt to close an already closed connection
[DEBUG] Close socket fd=5
[INFO] Unregistered session 12
[DEBUG] Close socket fd=3

Process finished with exit code 0

Environment (please complete the following information):

atimin commented 4 years ago

The implicit messaging failed because the size of the sending data was wrong. It should be 12 but we send 32 bytes.

ptr->setDataToSend(std::vector<uint8_t>(32));

In PR #10 I've added checks for this case.