@@ -7076,6 +7076,90 @@ test_CS104Slave_rejectCommandsWithBroadcastCA()
70767076 CS104_Slave_destroy (slave );
70777077}
70787078
7079+ static bool
7080+ test_IsCAAllowedHandler (void * parameter , int ca )
7081+ {
7082+ int expectedCa = * ((int * )parameter );
7083+
7084+ return (expectedCa == ca );
7085+ }
7086+
7087+ void
7088+ test_CS104Slave_rejectCommandWithUnknownCA ()
7089+ {
7090+ int expectedCa = 100 ;
7091+ CS101_ASDU receivedASDU = NULL ;
7092+
7093+ CS104_Slave slave = CS104_Slave_create (10 , 10 );
7094+
7095+ CS104_Slave_setServerMode (slave , CS104_MODE_SINGLE_REDUNDANCY_GROUP );
7096+ CS104_Slave_setLocalPort (slave , 20004 );
7097+
7098+ CS104_Slave_setAllowedCAHandler (slave , test_IsCAAllowedHandler , & expectedCa );
7099+
7100+ CS104_Slave_start (slave );
7101+
7102+ CS101_AppLayerParameters alParams = CS104_Slave_getAppLayerParameters (slave );
7103+
7104+ CS104_Connection con = CS104_Connection_create ("127.0.0.1" , 20004 );
7105+
7106+ bool result = CS104_Connection_connect (con );
7107+ TEST_ASSERT_TRUE (result );
7108+
7109+ CS104_Connection_setASDUReceivedHandler (con , test_CS104Slave_handleTestCommand_asduReceivedHandler , & receivedASDU );
7110+
7111+ CS104_Connection_sendStartDT (con );
7112+
7113+ TestCommandWithCP56Time2a tc ;
7114+
7115+ uint64_t time1 = Hal_getTimeInMs ();
7116+ struct sCP56Time2a cpTime1 ;
7117+ CP56Time2a_createFromMsTimestamp (& cpTime1 , time1 );
7118+
7119+ /* send test command with unknown CA */
7120+ tc = TestCommandWithCP56Time2a_create (NULL , 0xaa55 , & cpTime1 );
7121+
7122+ CS101_ASDU asdu = CS101_ASDU_create (& defaultAppLayerParameters , false, CS101_COT_ACTIVATION , 0 , 1 , false, false);
7123+
7124+ CS101_ASDU_addInformationObject (asdu , (InformationObject ) tc );
7125+ TestCommandWithCP56Time2a_destroy (tc );
7126+ TEST_ASSERT_TRUE (CS104_Connection_sendASDU (con , asdu ));
7127+ CS101_ASDU_destroy (asdu );
7128+
7129+ Thread_sleep (500 );
7130+
7131+ TEST_ASSERT_NOT_NULL (receivedASDU );
7132+ TEST_ASSERT_EQUAL_INT (C_TS_TA_1 , CS101_ASDU_getTypeID (receivedASDU ));
7133+ TEST_ASSERT_EQUAL_INT (CS101_COT_UNKNOWN_CA , CS101_ASDU_getCOT (receivedASDU ));
7134+ TEST_ASSERT_TRUE (CS101_ASDU_isNegative (receivedASDU ));
7135+
7136+ /* send test command with known CA */
7137+ tc = TestCommandWithCP56Time2a_create (NULL , 0xaa55 , & cpTime1 );
7138+
7139+ asdu = CS101_ASDU_create (& defaultAppLayerParameters , false, CS101_COT_ACTIVATION , 0 , expectedCa , false, false);
7140+
7141+ CS101_ASDU_addInformationObject (asdu , (InformationObject ) tc );
7142+ TestCommandWithCP56Time2a_destroy (tc );
7143+ TEST_ASSERT_TRUE (CS104_Connection_sendASDU (con , asdu ));
7144+ CS101_ASDU_destroy (asdu );
7145+
7146+ Thread_sleep (500 );
7147+
7148+ TEST_ASSERT_NOT_NULL (receivedASDU );
7149+ TEST_ASSERT_EQUAL_INT (C_TS_TA_1 , CS101_ASDU_getTypeID (receivedASDU ));
7150+ TEST_ASSERT_EQUAL_INT (CS101_COT_ACTIVATION_CON , CS101_ASDU_getCOT (receivedASDU ));
7151+ TEST_ASSERT_FALSE (CS101_ASDU_isNegative (receivedASDU ));
7152+
7153+ CS104_Connection_close (con );
7154+
7155+ CS104_Connection_destroy (con );
7156+
7157+ if (receivedASDU )
7158+ CS101_ASDU_destroy (receivedASDU );
7159+
7160+ CS104_Slave_destroy (slave );
7161+ }
7162+
70797163int
70807164main (int argc , char * * argv )
70817165{
@@ -7213,5 +7297,7 @@ main(int argc, char** argv)
72137297
72147298 RUN_TEST (test_CS104Slave_rejectCommandsWithBroadcastCA );
72157299
7300+ RUN_TEST (test_CS104Slave_rejectCommandWithUnknownCA );
7301+
72167302 return UNITY_END ();
72177303}
0 commit comments