link_layer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * link_layer.h
  3. *
  4. * Copyright 2017 MZ Automation GmbH
  5. *
  6. * This file is part of lib60870-C
  7. *
  8. * lib60870-C is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * lib60870-C is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with lib60870-C. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * See COPYING file for the complete license text.
  22. */
  23. #ifndef SRC_IEC60870_LINK_LAYER_LINK_LAYER_H_
  24. #define SRC_IEC60870_LINK_LAYER_LINK_LAYER_H_
  25. #include <stdbool.h>
  26. #include "iec60870_common.h"
  27. #include "frame.h"
  28. #include "buffer_frame.h"
  29. #include "serial_transceiver_ft_1_2.h"
  30. #include "link_layer_paramete.h"
  31. typedef struct sLinkLayer* LinkLayer;
  32. typedef struct sLinkLayerBalanced* LinkLayerBalanced;
  33. typedef struct sLinkLayerSecondaryUnbalanced* LinkLayerSecondaryUnbalanced;
  34. typedef struct sLinkLayerPrimaryUnbalanced* LinkLayerPrimaryUnbalanced;
  35. typedef struct sISecondaryApplicationLayer* ISecondaryApplicationLayer;
  36. struct sISecondaryApplicationLayer {
  37. bool (*IsClass1DataAvailable) (void* parameter);
  38. Frame (*GetClass1Data) (void* parameter, Frame frame);
  39. Frame (*GetClass2Data) (void* parameter, Frame frame);
  40. bool (*HandleReceivedData) (void* parameter, uint8_t* msg, bool isBroadcast, int userDataStart, int userDataLength);
  41. void (*ResetCUReceived) (void* parameter, bool onlyFCB);
  42. };
  43. typedef struct sIPrimaryApplicationLayer* IPrimaryApplicationLayer;
  44. struct sIPrimaryApplicationLayer {
  45. void (*AccessDemand) (void* parameter, int slaveAddress);
  46. void (*UserData) (void* parameter, int slaveAddress, uint8_t* msg, int start, int length);
  47. void (*Timeout) (void* parameter, int slaveAddress);
  48. };
  49. typedef struct sIBalancedApplicationLayer* IBalancedApplicationLayer;
  50. struct sIBalancedApplicationLayer {
  51. Frame (*GetUserData) (void* parameter, Frame frame);
  52. bool (*HandleReceivedData) (void* parameter, uint8_t* msg, bool isBroadcast, int userDataStart, int userDataLength);
  53. };
  54. LinkLayerPrimaryUnbalanced
  55. LinkLayerPrimaryUnbalanced_create(
  56. SerialTransceiverFT12 transceiver,
  57. LinkLayerParameters linkLayerParameters,
  58. IPrimaryApplicationLayer applicationLayer,
  59. void* applicationLayerParameter
  60. );
  61. void
  62. LinkLayerPrimaryUnbalanced_destroy(LinkLayerPrimaryUnbalanced self);
  63. void
  64. LinkLayerPrimaryUnbalanced_setStateChangeHandler(LinkLayerPrimaryUnbalanced self,
  65. IEC60870_LinkLayerStateChangedHandler handler, void* parameter);
  66. void
  67. LinkLayerPrimaryUnbalanced_addSlaveConnection(LinkLayerPrimaryUnbalanced self, int slaveAddress);
  68. void
  69. LinkLayerPrimaryUnbalanced_resetCU(LinkLayerPrimaryUnbalanced self, int slaveAddress);
  70. bool
  71. LinkLayerPrimaryUnbalanced_isChannelAvailable(LinkLayerPrimaryUnbalanced self, int slaveAddress);
  72. void
  73. LinkLayerPrimaryUnbalanced_sendLinkLayerTestFunction(LinkLayerPrimaryUnbalanced self, int slaveAddress);
  74. bool
  75. LinkLayerPrimaryUnbalanced_requestClass1Data(LinkLayerPrimaryUnbalanced self, int slaveAddress);
  76. bool
  77. LinkLayerPrimaryUnbalanced_requestClass2Data(LinkLayerPrimaryUnbalanced self, int slaveAddress);
  78. bool
  79. LinkLayerPrimaryUnbalanced_sendConfirmed(LinkLayerPrimaryUnbalanced self, int slaveAddress, BufferFrame message);
  80. bool
  81. LinkLayerPrimaryUnbalanced_sendNoReply(LinkLayerPrimaryUnbalanced self, int slaveAddress, BufferFrame message);
  82. void
  83. LinkLayerPrimaryUnbalanced_run(LinkLayerPrimaryUnbalanced self);
  84. LinkLayerSecondaryUnbalanced
  85. LinkLayerSecondaryUnbalanced_create(
  86. int linkLayerAddress,
  87. SerialTransceiverFT12 transceiver,
  88. LinkLayerParameters linkLayerParameters,
  89. ISecondaryApplicationLayer applicationLayer,
  90. void* applicationLayerParameter
  91. );
  92. void
  93. LinkLayerSecondaryUnbalanced_destroy(LinkLayerSecondaryUnbalanced self);
  94. void
  95. LinkLayerSecondaryUnbalanced_run(LinkLayerSecondaryUnbalanced self);
  96. void
  97. LinkLayerSecondaryUnbalanced_setIdleTimeout(LinkLayerSecondaryUnbalanced self, int timeoutInMs);
  98. void
  99. LinkLayerSecondaryUnbalanced_setStateChangeHandler(LinkLayerSecondaryUnbalanced self,
  100. IEC60870_LinkLayerStateChangedHandler handler, void* parameter);
  101. void
  102. LinkLayerSecondaryUnbalanced_setAddress(LinkLayerSecondaryUnbalanced self, int address);
  103. LinkLayerBalanced
  104. LinkLayerBalanced_create(
  105. int linkLayerAddress,
  106. SerialTransceiverFT12 transceiver,
  107. LinkLayerParameters linkLayerParameters,
  108. IBalancedApplicationLayer applicationLayer,
  109. void* applicationLayerParameter
  110. );
  111. void
  112. LinkLayerBalanced_setStateChangeHandler(LinkLayerBalanced self,
  113. IEC60870_LinkLayerStateChangedHandler handler, void* parameter);
  114. void
  115. LinkLayerBalanced_sendLinkLayerTestFunction(LinkLayerBalanced self);
  116. void
  117. LinkLayerBalanced_setIdleTimeout(LinkLayerBalanced self, int timeoutInMs);
  118. void
  119. LinkLayerBalanced_setDIR(LinkLayerBalanced self, bool dir);
  120. void
  121. LinkLayerBalanced_setAddress(LinkLayerBalanced self, int address);
  122. void
  123. LinkLayerBalanced_setOtherStationAddress(LinkLayerBalanced self, int address);
  124. void
  125. LinkLayerBalanced_destroy(LinkLayerBalanced self);
  126. void
  127. LinkLayerBalanced_run(LinkLayerBalanced self);
  128. LinkLayer
  129. LinkLayer_init(LinkLayer self, int address, SerialTransceiverFT12 transceiver, LinkLayerParameters linkLayerParameters);
  130. void
  131. LinkLayer_setDIR(LinkLayer self, bool dir);
  132. void
  133. LinkLayer_setAddress(LinkLayer self, int address);
  134. #endif /* SRC_IEC60870_LINK_LAYER_LINK_LAYER_H_ */