@@ -77,12 +77,21 @@ class ForwardOpenRequest : public Serializable
7777 EIP_USINT timeout_multiplyer;
7878 EIP_UDINT o_to_t_rpi;
7979 EIP_DWORD o_to_t_conn_params;
80+ EIP_WORD o_to_t_conn_params_legacy;
8081 EIP_UDINT t_to_o_rpi;
8182 EIP_DWORD t_to_o_conn_params;
83+ EIP_WORD t_to_o_conn_params_legacy;
8284 EIP_BYTE conn_type;
8385
86+ bool use_legacy_forward_open_request;
87+
88+ ForwardOpenRequest (bool use_legacy_forward_open_request)
89+ : use_legacy_forward_open_request(use_legacy_forward_open_request)
90+ {
91+ }
92+
8493 /* *
85- * Helper to calculate connection parameters
94+ * Helper to calculate connection parameters for current 32 bit connection parameters
8695 * @param size Maximum size of the messages in the connection in byte
8796 * @param variable if set to true, variable message sizes
8897 * @param priority Priority value for the connection
@@ -96,13 +105,35 @@ class ForwardOpenRequest : public Serializable
96105 | (type & 0x03 ) << 29 | (shared ? 0x80000000 : 0 );
97106 }
98107
108+ /* *
109+ * Helper to calculate connection parameters for legacy 16 bit connection parameters
110+ * @param size Maximum size of the messages in the connection in byte
111+ * @param variable if set to true, variable message sizes
112+ * @param priority Priority value for the connection
113+ * @param type Connection type / class info
114+ * @param shared If set to true, then a shared connection
115+ */
116+ static EIP_WORD calcConnectionParamsLegacy (EIP_UINT size, bool variable, EIP_BYTE priority,
117+ EIP_BYTE type, bool shared)
118+ {
119+ return (size & 0x1FF ) | (variable ? 0x200 : 0 ) | (priority & 0x03 ) << 10
120+ | (type & 0x03 ) << 13 | (shared ? 0x8000 : 0 );
121+ }
122+
99123 /* *
100124 * Shortcut to set the origin to target parameters.
101125 */
102126 EIP_DWORD setOriginToTargetParams (EIP_UINT size, bool variable, EIP_BYTE priority,
103127 EIP_BYTE type, bool shared)
104128 {
105- o_to_t_conn_params = calcConnectionParams (size, variable, priority, type, shared);
129+ if (use_legacy_forward_open_request)
130+ {
131+ o_to_t_conn_params_legacy = calcConnectionParamsLegacy (size, variable, priority, type, shared);
132+ }
133+ else
134+ {
135+ o_to_t_conn_params = calcConnectionParams (size, variable, priority, type, shared);
136+ }
106137 return 0 ;
107138 }
108139
@@ -112,7 +143,14 @@ class ForwardOpenRequest : public Serializable
112143 EIP_DWORD setTargetToOriginParams (EIP_UINT size, bool variable, EIP_BYTE priority,
113144 EIP_BYTE type, bool shared)
114145 {
115- t_to_o_conn_params = calcConnectionParams (size, variable, priority, type, shared);
146+ if (use_legacy_forward_open_request)
147+ {
148+ t_to_o_conn_params_legacy = calcConnectionParamsLegacy (size, variable, priority, type, shared);
149+ }
150+ else
151+ {
152+ t_to_o_conn_params = calcConnectionParams (size, variable, priority, type, shared);
153+ }
116154 return 0 ;
117155 }
118156
@@ -131,21 +169,36 @@ class ForwardOpenRequest : public Serializable
131169 */
132170 virtual size_t getLength () const
133171 {
134- return sizeof (timeout_tick_size)
135- + sizeof (timeout_ticks)
136- + sizeof (o_to_t_connection_id)
137- + sizeof (t_to_o_connection_id)
138- + sizeof (connection_sn)
139- + sizeof (originator_vendor_id)
140- + sizeof (originator_sn)
141- + sizeof (timeout_multiplyer)
142- + sizeof (o_to_t_rpi)
143- + sizeof (o_to_t_conn_params)
144- + sizeof (t_to_o_rpi)
145- + sizeof (t_to_o_conn_params)
146- + sizeof (conn_type)
147- + 3 // reserved bytes
148- + path_.getLength ();
172+ size_t ret = sizeof (timeout_tick_size);
173+ ret += sizeof (timeout_ticks);
174+ ret += sizeof (o_to_t_connection_id);
175+ ret += sizeof (t_to_o_connection_id);
176+ ret += sizeof (connection_sn);
177+ ret += sizeof (originator_vendor_id);
178+ ret += sizeof (originator_sn);
179+ ret += sizeof (timeout_multiplyer);
180+ ret += sizeof (o_to_t_rpi);
181+ if (use_legacy_forward_open_request)
182+ {
183+ ret += sizeof (o_to_t_conn_params_legacy);
184+ }
185+ else
186+ {
187+ ret += sizeof (o_to_t_conn_params);
188+ }
189+ ret += sizeof (t_to_o_rpi);
190+ if (use_legacy_forward_open_request)
191+ {
192+ ret += sizeof (t_to_o_conn_params_legacy);
193+ }
194+ else
195+ {
196+ ret += sizeof (t_to_o_conn_params);
197+ }
198+ ret += sizeof (conn_type);
199+ ret += 3 ; // reserved bytes
200+ ret += path_.getLength ();
201+ return ret;
149202 }
150203
151204 /* *
@@ -169,9 +222,23 @@ class ForwardOpenRequest : public Serializable
169222 writer.write (reserved);
170223 writer.write (reserved);
171224 writer.write (o_to_t_rpi);
172- writer.write (o_to_t_conn_params);
225+ if (use_legacy_forward_open_request)
226+ {
227+ writer.write (o_to_t_conn_params_legacy);
228+ }
229+ else
230+ {
231+ writer.write (o_to_t_conn_params);
232+ }
173233 writer.write (t_to_o_rpi);
174- writer.write (t_to_o_conn_params);
234+ if (use_legacy_forward_open_request)
235+ {
236+ writer.write (t_to_o_conn_params_legacy);
237+ }
238+ else
239+ {
240+ writer.write (t_to_o_conn_params);
241+ }
175242 writer.write (conn_type);
176243 path_.serialize (writer);
177244 return writer;
0 commit comments