e_e
Hello, 

Is there any way to set the PLC Device Identification? I need it to simulate "real" PLCs in an industrial control system network. I just need the "banner" (e.g.-- Device Identification: Schneider Electric BMX P34 20302 v2.6 ). I would like to simulate as many devices as possible and then launch a network discovery (nmap,plcscan or similar). 

Thanks! (and congrats for the project! it is awesome!)
Reply 0 0
thiagoralves
According to the Modbus standard, the Device Identification (function code 43) is used to request information about the slave device. This function code is not implemented in OpenPLC built-in Modbus, so it will respond with an invalid function code error. If you want, you can modify the modbus.cpp file inside the /core folder to have that function code implemented as you want. Then you can fake it to respond with identification strings just like any of your devices.
Reply 0 0
e_e
Great! Thank you Thiago.
Reply 0 0
e_e
Hello again, 

I've modified the code and now is working as I expected. I've tested it with nmap  nse script modbus-discover.nse and I get the device identification. 
If someone is interested in the code, just ask me. 

Regards.
Reply 0 0
thiagoralves
e_e, could you please share your code with me? I'm planning to add this feature on the next version of the OpenPLC webserver. Just attach your code on a zip file here in the forum, so that everyone will have access to it as well. Thanks!
Reply 0 0
e_e
Sure, 

These are the modifications: 

Define the Function Code 43 (Device Identification):

#define MB_FC_READ_DEVICE_IDENTIFICATION 43

At the end of the file, call the function:

//****************** Read Device Identification ******************
else if(buffer[7] == MB_FC_READ_DEVICE_IDENTIFICATION)
{
DeviceIdentification(buffer, MB_FC_READ_DEVICE_IDENTIFICATION);
}

And this is the DeviceIdentification function for a "Simens SIMATIC S7-200" PLC. I've only implemented the VendorName object because I only need this. The right way to do it is adding the object 2: ProductCode and object (SIMATIC) 3: MajorMinorRevision (S7-200)

//-----------------------------------------------------------------------------
// Response to a Modbus Devide Identification
//-----------------------------------------------------------------------------
void DeviceIdentification(unsigned char *buffer, int mb_error)
{
buffer[3] = 0x00;//transaction identifier; 0
buffer[4] = 0x00;//protocol identifier; 0
buffer[5] = 0x03;//length
buffer[6] = 0x01; //unit identifier
buffer[7] = 0x2b; //function code: 43
buffer[8] = 0x0e; //MEI type 14
buffer[9] = 0x01;//data from here
buffer[10] = 0x81;//conformity level
buffer[11] = 0x00;//more Follows
buffer[12] = 0;//Next Object ID
buffer[13] = 0x01;//Number of objects
buffer[14] = 0x00;//Object id 0 (VendorName)
buffer[15] = 0x16;//Object lengh object 0
buffer[16] = 0x53;//S
buffer[17] = 0x69;//i
buffer[18] = 0x65;//e
buffer[19] = 0x6d;//m
buffer[20] = 0x65;//e
buffer[21] = 0x6e;//n
buffer[22] = 0x73;//s
buffer[23] = 0x20;//space
buffer[24] = 0x53;//S
buffer[25] = 0x49;//I
buffer[26] = 0x4d;//M
buffer[27] = 0x41;//A
buffer[28] = 0x54;//T
buffer[29] = 0x49;//I
buffer[30] = 0x43;//C
buffer[31] = 0x20;//space
buffer[32] = 0x53;//S
buffer[33] = 0x37;//7
buffer[34] = 0x2d;//-
buffer[35] = 0x32;//2
buffer[36] = 0x30;//0
buffer[37] = 0x30;//0
MessageLength = 38;
}

And the nmap output is:

Selection_065.png 

Find attached the modbus.cpp file. 

Regards.


Reply 1 0
Ed
Thanks very much.  A nice addition.  Just for clarity's sake for anybody else trying this out, rename/move the old Modbus.cpp file elsewhere and replace it with the file below (which I renamed to Modbus.cpp).  If you leave the old file in the core folder and merely rename it something like Modbus_old.cpp, the compiler gets upset; it looks as though it reads in all *.cpp files in the folder, not just specifically named ones.
Reply 0 0
ylevalle
Thank you, I am working in something similar and this was very helpful!
Reply 1 0
Reply