MCPcopy Create free account
hub / github.com/EIPStackGroup/OpENer / ForwardOpen

Function ForwardOpen

source/src/cip/cipconnectionmanager.c:491–557  ·  view source on GitHub ↗

@brief Check if resources for new connection available, generate ForwardOpen Reply message. * * Forward Open four cases * Non-Null/Not matching - open a connection * Non-Null/Matching - error * Null/Not matching - ping a device/configure * Null/Matching - reconfigure * * Null connection - both O->T and T->O connection parameter field are null * Non-Null connection - one or both O->

Source from the content-addressed store, hash-verified

489 * -1 .. error
490 */
491EipStatus ForwardOpen(
492 CipInstance *instance,
493 CipMessageRouterRequest *message_router_request,
494 CipMessageRouterResponse *message_router_response,
495 struct sockaddr *originator_address,
496 const int encapsulation_session
497 ) {
498 (void) instance; /*suppress compiler warning */
499
500 bool is_null_request = false; /* 1 = Null Request, 0 = Non-Null Request */
501 bool is_matching_request = false; /* 1 = Matching Request, 0 = Non-Matching Request */
502
503 /*first check if we have already a connection with the given params */
504 ConnectionObjectInitializeFromMessage(&(message_router_request->data),
505 &g_dummy_connection_object);
506 g_dummy_connection_object.associated_encapsulation_session =
507 encapsulation_session;
508
509 memcpy( &(g_dummy_connection_object.originator_address), originator_address,
510 sizeof(g_dummy_connection_object.originator_address) );
511
512 ConnectionObjectConnectionType o_to_t_connection_type =
513 ConnectionObjectGetOToTConnectionType(&g_dummy_connection_object);
514 ConnectionObjectConnectionType t_to_o_connection_type =
515 ConnectionObjectGetTToOConnectionType(&g_dummy_connection_object);
516
517 /* Check if both connection types are valid, otherwise send error response */
518 if (kConnectionObjectConnectionTypeInvalid == o_to_t_connection_type) {
519 return AssembleForwardOpenResponse(
520 &g_dummy_connection_object, message_router_response,
521 kCipErrorConnectionFailure,
522 kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionType);
523 }
524
525 if (kConnectionObjectConnectionTypeInvalid == t_to_o_connection_type) {
526 return AssembleForwardOpenResponse(
527 &g_dummy_connection_object, message_router_response,
528 kCipErrorConnectionFailure,
529 kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionType);
530 }
531
532 /* Check if request is a Null request or a Non-Null request */
533 if (kConnectionObjectConnectionTypeNull == o_to_t_connection_type
534 && kConnectionObjectConnectionTypeNull == t_to_o_connection_type) {
535 is_null_request = true;
536 OPENER_TRACE_INFO("We have a Null request\n");
537 } else {
538 is_null_request = false;
539 OPENER_TRACE_INFO("We have a Non-Null request\n");
540 }
541
542 /* Check if we have a matching or non matching request */
543 if ( NULL != CheckForExistingConnection(&g_dummy_connection_object) ) {
544 OPENER_TRACE_INFO("We have a Matching request\n");
545 is_matching_request = true;
546
547 } else {
548 OPENER_TRACE_INFO("We have a Non-Matching request\n");

Callers

nothing calls this directly

Tested by

no test coverage detected