Skip to content

Commit

Permalink
merged bug fixes from 1.2.x branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Alois Zoitl committed Aug 7, 2012
1 parent 4922bc5 commit 9528c63
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 109 deletions.
162 changes: 79 additions & 83 deletions src/cip/appcontype.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,22 @@ typedef struct
unsigned int m_unOutputAssembly; /*< the O-to-T point for the connection */
unsigned int m_unInputAssembly; /*< the T-to-O point for the connection */
unsigned int m_unConfigAssembly; /*< the config point for the connection */
S_CIP_ConnectionObject
m_astConnectionData[OPENER_CIP_NUM_INPUT_ONLY_CONNS_PER_CON_PATH]; /*< the connection data */
S_CIP_ConnectionObject m_astConnectionData[OPENER_CIP_NUM_INPUT_ONLY_CONNS_PER_CON_PATH]; /*< the connection data */
} S_InputOnlyConnection;

typedef struct
{
unsigned int m_unOutputAssembly; /*< the O-to-T point for the connection */
unsigned int m_unInputAssembly; /*< the T-to-O point for the connection */
unsigned int m_unConfigAssembly; /*< the config point for the connection */
S_CIP_ConnectionObject
m_astConnectionData[OPENER_CIP_NUM_LISTEN_ONLY_CONNS_PER_CON_PATH]; /*< the connection data */
S_CIP_ConnectionObject m_astConnectionData[OPENER_CIP_NUM_LISTEN_ONLY_CONNS_PER_CON_PATH]; /*< the connection data */
} S_ListenOnlyConnection;

S_ExclusiveOwnerConnection
g_astExlusiveOwnerConnections[OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS];
S_ExclusiveOwnerConnection g_astExlusiveOwnerConnections[OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS];

S_InputOnlyConnection
g_astInputOnlyConnections[OPENER_CIP_NUM_INPUT_ONLY_CONNS];
S_InputOnlyConnection g_astInputOnlyConnections[OPENER_CIP_NUM_INPUT_ONLY_CONNS];

S_ListenOnlyConnection
g_astListenOnlyConnections[OPENER_CIP_NUM_LISTEN_ONLY_CONNS];
S_ListenOnlyConnection g_astListenOnlyConnections[OPENER_CIP_NUM_LISTEN_ONLY_CONNS];

S_CIP_ConnectionObject *
getExclusiveOwnerConnection(S_CIP_ConnectionObject * pa_pstConnData,
Expand All @@ -63,12 +58,12 @@ configureExclusiveOwnerConnectionPoint(unsigned int pa_unConnNum,
{
if (OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS > pa_unConnNum)
{
g_astExlusiveOwnerConnections[pa_unConnNum].m_unOutputAssembly
= pa_unOutputAssembly;
g_astExlusiveOwnerConnections[pa_unConnNum].m_unInputAssembly
= pa_unInputAssembly;
g_astExlusiveOwnerConnections[pa_unConnNum].m_unConfigAssembly
= pa_unConfigAssembly;
g_astExlusiveOwnerConnections[pa_unConnNum].m_unOutputAssembly =
pa_unOutputAssembly;
g_astExlusiveOwnerConnections[pa_unConnNum].m_unInputAssembly =
pa_unInputAssembly;
g_astExlusiveOwnerConnections[pa_unConnNum].m_unConfigAssembly =
pa_unConfigAssembly;
}
}

Expand All @@ -79,12 +74,12 @@ configureInputOnlyConnectionPoint(unsigned int pa_unConnNum,
{
if (OPENER_CIP_NUM_INPUT_ONLY_CONNS > pa_unConnNum)
{
g_astInputOnlyConnections[pa_unConnNum].m_unOutputAssembly
= pa_unOutputAssembly;
g_astInputOnlyConnections[pa_unConnNum].m_unInputAssembly
= pa_unInputAssembly;
g_astInputOnlyConnections[pa_unConnNum].m_unConfigAssembly
= pa_unConfigAssembly;
g_astInputOnlyConnections[pa_unConnNum].m_unOutputAssembly =
pa_unOutputAssembly;
g_astInputOnlyConnections[pa_unConnNum].m_unInputAssembly =
pa_unInputAssembly;
g_astInputOnlyConnections[pa_unConnNum].m_unConfigAssembly =
pa_unConfigAssembly;
}
}

Expand All @@ -95,12 +90,12 @@ configureListenOnlyConnectionPoint(unsigned int pa_unConnNum,
{
if (OPENER_CIP_NUM_LISTEN_ONLY_CONNS > pa_unConnNum)
{
g_astListenOnlyConnections[pa_unConnNum].m_unOutputAssembly
= pa_unOutputAssembly;
g_astListenOnlyConnections[pa_unConnNum].m_unInputAssembly
= pa_unInputAssembly;
g_astListenOnlyConnections[pa_unConnNum].m_unConfigAssembly
= pa_unConfigAssembly;
g_astListenOnlyConnections[pa_unConnNum].m_unOutputAssembly =
pa_unOutputAssembly;
g_astListenOnlyConnections[pa_unConnNum].m_unInputAssembly =
pa_unInputAssembly;
g_astListenOnlyConnections[pa_unConnNum].m_unConfigAssembly =
pa_unConfigAssembly;
}
}

Expand All @@ -117,8 +112,8 @@ getIOConnectionForConnectionData(S_CIP_ConnectionObject *pa_pstConnData,
if (0 == *pa_pnExtendedError)
{
/* we found no connection and don't have an error so try input only next */
pstRetVal
= getInputOnlyConnection(pa_pstConnData, pa_pnExtendedError);
pstRetVal = getInputOnlyConnection(pa_pstConnData,
pa_pnExtendedError);
if (NULL == pstRetVal)
{
if (0 == *pa_pnExtendedError)
Expand All @@ -130,12 +125,12 @@ getIOConnectionForConnectionData(S_CIP_ConnectionObject *pa_pstConnData,
{
/* no application connection type was found that suits the given data */
/* TODO check error code VS */
*pa_pnExtendedError
= CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
*pa_pnExtendedError =
CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
}
else
{
pa_pstConnData->m_eInstanceType = enConnTypeIOListenOnly;
pa_pstConnData->m_eInstanceType = enConnTypeIOListenOnly;
}
}
}
Expand Down Expand Up @@ -167,25 +162,18 @@ getExclusiveOwnerConnection(S_CIP_ConnectionObject * pa_pstConnData,

for (i = 0; i < OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS; i++)
{
if (g_astExlusiveOwnerConnections[i].m_unOutputAssembly
if ((g_astExlusiveOwnerConnections[i].m_unOutputAssembly
== pa_pstConnData->ConnectionPath.ConnectionPoint[0])
{ /* we have the same output assembly */
if (g_astExlusiveOwnerConnections[i].m_unInputAssembly
!= pa_pstConnData->ConnectionPath.ConnectionPoint[1])
{
*pa_pnExtendedError
= CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
break;
}
if (g_astExlusiveOwnerConnections[i].m_unConfigAssembly
!= pa_pstConnData->ConnectionPath.ConnectionPoint[2])
{
*pa_pnExtendedError
= CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
break;
}
if (g_astExlusiveOwnerConnections[i].m_stConnectionData.State
!= CONN_STATE_NONEXISTENT)
&& (g_astExlusiveOwnerConnections[i].m_unInputAssembly
== pa_pstConnData->ConnectionPath.ConnectionPoint[1])
&& (g_astExlusiveOwnerConnections[i].m_unConfigAssembly
== pa_pstConnData->ConnectionPath.ConnectionPoint[2]))
{

/* check if on other connection point with the same output assembly is currently connected */
if (NULL
!= getConnectedOutputAssembly(
pa_pstConnData->ConnectionPath.ConnectionPoint[0]))
{
*pa_pnExtendedError = CIP_CON_MGR_ERROR_OWNERSHIP_CONFLICT;
break;
Expand All @@ -212,15 +200,15 @@ getInputOnlyConnection(S_CIP_ConnectionObject * pa_pstConnData,
if (g_astInputOnlyConnections[i].m_unInputAssembly
!= pa_pstConnData->ConnectionPath.ConnectionPoint[1])
{
*pa_pnExtendedError
= CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
*pa_pnExtendedError =
CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
break;
}
if (g_astInputOnlyConnections[i].m_unConfigAssembly
!= pa_pstConnData->ConnectionPath.ConnectionPoint[2])
{
*pa_pnExtendedError
= CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
*pa_pnExtendedError =
CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
break;
}

Expand Down Expand Up @@ -263,23 +251,24 @@ getListenOnlyConnection(S_CIP_ConnectionObject * pa_pstConnData,
if (g_astListenOnlyConnections[i].m_unInputAssembly
!= pa_pstConnData->ConnectionPath.ConnectionPoint[1])
{
*pa_pnExtendedError
= CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
*pa_pnExtendedError =
CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
break;
}
if (g_astListenOnlyConnections[i].m_unConfigAssembly
!= pa_pstConnData->ConnectionPath.ConnectionPoint[2])
{
*pa_pnExtendedError
= CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
*pa_pnExtendedError =
CIP_CON_MGR_INVALID_PRODUCED_OR_CONSUMED_APPLICATION_PATH;
break;
}

if (NULL == getExistingProdMulticastConnection(
pa_pstConnData->ConnectionPath.ConnectionPoint[1]))
if (NULL
== getExistingProdMulticastConnection(
pa_pstConnData->ConnectionPath.ConnectionPoint[1]))
{
*pa_pnExtendedError
= CIP_CON_MGR_NON_LISTEN_ONLY_CONNECTION_NOT_OPENED;
*pa_pnExtendedError =
CIP_CON_MGR_NON_LISTEN_ONLY_CONNECTION_NOT_OPENED;
break;
}

Expand Down Expand Up @@ -311,8 +300,8 @@ getExistingProdMulticastConnection(EIP_UINT32 pa_unInputPoint)
if ((pa_unInputPoint == pstRunner->ConnectionPath.ConnectionPoint[1])
&& (CIP_MULTICAST_CONNECTION
== (pstRunner->T_to_O_NetworkConnectionParameter
& CIP_MULTICAST_CONNECTION)) && (EIP_INVALID_SOCKET
!= pstRunner->sockfd[PRODUCING]))
& CIP_MULTICAST_CONNECTION))
&& (EIP_INVALID_SOCKET != pstRunner->sockfd[PRODUCING]))
{
/* we have a connection that produces the same input assembly,
* is a multicast producer and manages the connection.
Expand All @@ -338,8 +327,8 @@ getNextNonCtrlMasterCon(EIP_UINT32 pa_unInputPoint)
if ((pa_unInputPoint == pstRunner->ConnectionPath.ConnectionPoint[1])
&& (CIP_MULTICAST_CONNECTION
== (pstRunner->T_to_O_NetworkConnectionParameter
& CIP_MULTICAST_CONNECTION)) && (EIP_INVALID_SOCKET
== pstRunner->sockfd[PRODUCING]))
& CIP_MULTICAST_CONNECTION))
&& (EIP_INVALID_SOCKET == pstRunner->sockfd[PRODUCING]))
{
/* we have a connection that produces the same input assembly,
* is a multicast producer and does not manages the connection.
Expand All @@ -361,13 +350,12 @@ closeAllConnsForInputWithSameType(EIP_UINT32 pa_unInputPoint,

while (NULL != pstRunner)
{
if ((pa_eInstanceType == pstRunner->m_eInstanceType) && (pa_unInputPoint
== pstRunner->ConnectionPath.ConnectionPoint[1]))
if ((pa_eInstanceType == pstRunner->m_eInstanceType)
&& (pa_unInputPoint == pstRunner->ConnectionPath.ConnectionPoint[1]))
{
pstToDelete = pstRunner;
pstRunner = pstRunner->m_pstNext;
IApp_IOConnectionEvent(
pstToDelete->ConnectionPath.ConnectionPoint[0],
IApp_IOConnectionEvent(pstToDelete->ConnectionPath.ConnectionPoint[0],
pstToDelete->ConnectionPath.ConnectionPoint[1], enClosed);

//FIXME check if this is ok
Expand All @@ -381,16 +369,19 @@ closeAllConnsForInputWithSameType(EIP_UINT32 pa_unInputPoint,
}
}

void closeAllConnections(void){
void
closeAllConnections(void)
{
S_CIP_ConnectionObject *pstRunner = g_pstActiveConnectionList;
while (NULL != pstRunner){
while (NULL != pstRunner)
{
//FIXME check if m_pfCloseFunc would be suitable
closeConnection(pstRunner);
/* Close connection will remove the connection from the list therefore we
* need to get again the start until there is no connection left
*/
pstRunner = g_pstActiveConnectionList;
}
closeConnection(pstRunner);
/* Close connection will remove the connection from the list therefore we
* need to get again the start until there is no connection left
*/
pstRunner = g_pstActiveConnectionList;
}

}

Expand All @@ -410,8 +401,13 @@ connectionWithSameConfigPointExists(EIP_UINT32 pa_unConfigPoint)
return (NULL != pstRunner);
}

void initializeIOConnectionData(){
memset(g_astExlusiveOwnerConnections, 0, OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS * sizeof(S_ExclusiveOwnerConnection));
memset(g_astInputOnlyConnections, 0, OPENER_CIP_NUM_INPUT_ONLY_CONNS * sizeof(S_InputOnlyConnection));
memset(g_astListenOnlyConnections, 0, OPENER_CIP_NUM_LISTEN_ONLY_CONNS * sizeof(S_ListenOnlyConnection));
void
initializeIOConnectionData()
{
memset(g_astExlusiveOwnerConnections, 0,
OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS * sizeof(S_ExclusiveOwnerConnection));
memset(g_astInputOnlyConnections, 0,
OPENER_CIP_NUM_INPUT_ONLY_CONNS * sizeof(S_InputOnlyConnection));
memset(g_astListenOnlyConnections, 0,
OPENER_CIP_NUM_LISTEN_ONLY_CONNS * sizeof(S_ListenOnlyConnection));
}
4 changes: 2 additions & 2 deletions src/cip/cipcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ createCIPClass(EIP_UINT32 pa_nClassID, int pa_nNr_of_ClassAttributes,
S_CIP_Class *pt2Class; /* pointer to the class struct */
S_CIP_Class *pt2MetaClass; /* pointer to the metaclass struct */

OPENER_TRACE_INFO("creating class '%s' with id: 0x%lx\n", pa_acName, pa_nClassID);
OPENER_TRACE_INFO("creating class '%s' with id: 0x%"PRIX32"\n", pa_acName, pa_nClassID);

pt2Class = getCIPClass(pa_nClassID); /* check if an class with the ClassID already exists */
OPENER_ASSERT(NULL == pt2Class);
Expand Down Expand Up @@ -320,7 +320,7 @@ insertAttribute(S_CIP_Instance * pa_pInstance, EIP_UINT16 pa_nAttributeNr,
p++;
}

OPENER_TRACE_ERR("Tried to insert to many attributes into class: %lu, instance %lu\n", pa_pInstance->pstClass->m_stSuper.nInstanceNr, pa_pInstance->nInstanceNr );
OPENER_TRACE_ERR("Tried to insert to many attributes into class: %"PRIu32", instance %"PRIu32"\n", pa_pInstance->pstClass->m_stSuper.nInstanceNr, pa_pInstance->nInstanceNr );
OPENER_ASSERT(0);
/* trying to insert too many attributes*/
}
Expand Down
32 changes: 25 additions & 7 deletions src/cip/cipconnectionmanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ ForwardOpen(S_CIP_Instance *pa_pstInstance, S_CIP_MR_Request *pa_MRRequest,
g_stDummyConnectionObject.ConnectionTimeoutMultiplier = *pa_MRRequest->Data++;
pa_MRRequest->Data += 3; /* reserved */
/* the requested packet interval parameter needs to be a multiple of TIMERTICK from the header file */
OPENER_TRACE_INFO("ForwardOpen: ConConnID %lu, ProdConnID %lu, ConnSerNo %u\n",
OPENER_TRACE_INFO("ForwardOpen: ConConnID %"PRIu32", ProdConnID %"PRIu32", ConnSerNo %u\n",
g_stDummyConnectionObject.CIPConsumedConnectionID,
g_stDummyConnectionObject.CIPProducedConnectionID,
g_stDummyConnectionObject.ConnectionSerialNumber);
Expand Down Expand Up @@ -766,6 +766,23 @@ getConnectedObject(EIP_UINT32 ConnectionID)
return NULL;
}

S_CIP_ConnectionObject *
getConnectedOutputAssembly(EIP_UINT32 pa_unOutputAssemblyId)
{
S_CIP_ConnectionObject *pstRunner = g_pstActiveConnectionList;

while (NULL != pstRunner)
{
if (pstRunner->State == CONN_STATE_ESTABLISHED)
{
if (pstRunner->ConnectionPath.ConnectionPoint[0] == pa_unOutputAssemblyId)
return pstRunner;
}
pstRunner = pstRunner->m_pstNext;
}
return NULL;
}

S_CIP_ConnectionObject *
checkForExistingConnection(S_CIP_ConnectionObject *pa_pstConnObj)
{
Expand Down Expand Up @@ -944,7 +961,7 @@ parseConnectionPath(S_CIP_ConnectionObject *pa_pstConnObj,
pstClass = getCIPClass(pa_pstConnObj->ConnectionPath.ClassID);
if (0 == pstClass)
{
OPENER_TRACE_ERR("classid %lx not found\n",
OPENER_TRACE_ERR("classid %"PRIx32" not found\n",
pa_pstConnObj->ConnectionPath.ClassID);
if (pa_pstConnObj->ConnectionPath.ClassID >= 0xC8) /*reserved range of class ids */

Expand All @@ -958,7 +975,7 @@ parseConnectionPath(S_CIP_ConnectionObject *pa_pstConnObj,
CIP_CON_MGR_ERROR_INVALID_CONNECTION_POINT;
}
return CIP_ERROR_CONNECTION_FAILURE;
}OPENER_TRACE_INFO("classid %lx (%s)\n",
}OPENER_TRACE_INFO("classid %"PRIx32" (%s)\n",
pa_pstConnObj->ConnectionPath.ClassID, pstClass->acName);
}
else
Expand All @@ -972,7 +989,7 @@ parseConnectionPath(S_CIP_ConnectionObject *pa_pstConnObj,
{ /* store the configuration ID for later checking in the application connection types */
pa_pstConnObj->ConnectionPath.ConnectionPoint[2] =
GETPADDEDLOGICALPATH(&pnMsg);
OPENER_TRACE_INFO("Configuration instance id %ld\n", pa_pstConnObj->ConnectionPath.ConnectionPoint[2]);
OPENER_TRACE_INFO("Configuration instance id %"PRId32"\n", pa_pstConnObj->ConnectionPath.ConnectionPoint[2]);
if (NULL
== getCIPInstance(pstClass,
pa_pstConnObj->ConnectionPath.ConnectionPoint[2]))
Expand Down Expand Up @@ -1056,7 +1073,7 @@ parseConnectionPath(S_CIP_ConnectionObject *pa_pstConnObj,
{ /* InstanceNR */
pa_pstConnObj->ConnectionPath.ConnectionPoint[i] =
GETPADDEDLOGICALPATH(&pnMsg);
OPENER_TRACE_INFO("connection point %lu\n",
OPENER_TRACE_INFO("connection point %"PRIu32"\n",
pa_pstConnObj->ConnectionPath.ConnectionPoint[i]);
if (0
== getCIPInstance(pstClass,
Expand Down Expand Up @@ -1218,11 +1235,12 @@ addConnectableObject(EIP_UINT32 pa_nClassId, TConnOpenFunc pa_pfOpenFunc)
{
g_astConnMgmList[i].m_nClassID = pa_nClassId;
g_astConnMgmList[i].m_pfOpenFunc = pa_pfOpenFunc;
return EIP_OK;
nRetVal = EIP_OK;
break;
}
}

return EIP_ERROR;
return nRetVal;
}

TConnMgmHandling *
Expand Down
Loading

0 comments on commit 9528c63

Please sign in to comment.