opcua_transportLayer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * opcua_transportLayer.h
  3. *
  4. * Created on: Dec 19, 2013
  5. * Author: opcua
  6. */
  7. #ifndef OPCUA_TRANSPORTLAYER_H_
  8. #define OPCUA_TRANSPORTLAYER_H_
  9. #include <stdio.h>
  10. #include "opcua.h"
  11. #include "UA_stack.h"
  12. #include "UA_connection.h"
  13. #include "UA_stackInternalTypes.h"
  14. //TODO : Implement this interface
  15. #include "tcp_layer.h"
  16. /*------------------Defined Error Codes------------------*/
  17. //transport errors begin at 1000
  18. #define UA_ERROR_MULTIPLE_HEL 1000
  19. #define UA_ERROR_RCV_ERROR 1001
  20. /*------------------Defined Lengths------------------*/
  21. #define SIZE_OF_ACKNOWLEDGE_MESSAGE 28
  22. //constants
  23. static const UA_UInt32 TL_HEADER_LENGTH = 8;
  24. static const UA_UInt32 TL_MESSAGE_TYPE_LEN = 3;
  25. static const UA_UInt32 TL_RESERVED_LEN = 1;
  26. //variables which belong to layer
  27. #define TL_SERVER_PROTOCOL_VERSION 0
  28. #define TL_SERVER_MAX_CHUNK_COUNT 1
  29. #define TL_SERVER_MAX_MESSAGE_SIZE 8192
  30. enum TL_messageType_td
  31. {
  32. TL_MESSAGETYPE_HEL = 1,
  33. TL_MESSAGETYPE_ACK = 2,
  34. TL_MESSAGETYPE_ERR = 3,
  35. TL_MESSAGETYPE_OPN = 4,
  36. TL_MESSAGETYPE_CLO = 5,
  37. TL_MESSAGETYPE_MSG = 6
  38. }TL_messageType;
  39. struct TL_header
  40. {
  41. UA_UInt32 MessageType;
  42. UA_Byte Reserved;
  43. UA_UInt32 MessageSize;
  44. };
  45. struct TL_message
  46. {
  47. struct TL_header Header;
  48. char *message;
  49. };
  50. struct TL_messageBodyHEL
  51. {
  52. UA_UInt32 ProtocolVersion;
  53. UA_UInt32 ReceiveBufferSize;
  54. UA_UInt32 SendBufferSize;
  55. UA_UInt32 MaxMessageSize;
  56. UA_UInt32 MaxChunkCount;
  57. UA_String EndpointUrl;
  58. };
  59. struct TL_messageBodyACK
  60. {
  61. UA_UInt32 ProtocolVersion;
  62. UA_UInt32 ReceiveBufferSize;
  63. UA_UInt32 SendBufferSize;
  64. UA_UInt32 MaxMessageSize;
  65. UA_UInt32 MaxChunkCount;
  66. UA_String EndpointUrl;
  67. };
  68. struct TL_messageBodyERR
  69. {
  70. UA_UInt32 Error;
  71. UA_String Reason;
  72. };
  73. //functions
  74. /**
  75. *
  76. * @param connection connection object
  77. * @param TL_message
  78. * @return
  79. */
  80. enum UA_TL_CHECK_enum {
  81. UA_TL_CHECK_LOCAL = 0,
  82. UA_TL_CHECK_REMOTE = 1
  83. };
  84. UA_Int32 TL_check(UA_TL_connection *connection, UA_ByteString* msg, UA_Int32 local);
  85. /**
  86. *
  87. * @param connection
  88. * @param TL_message
  89. */
  90. UA_Int32 TL_receive(UA_TL_connection *connection,UA_ByteString *packet);
  91. UA_Int32 TL_send(UA_TL_connection *connection, UA_ByteString *packet);
  92. UA_Int32 TL_getPacketType(UA_ByteString *packet, UA_Int32 *pos);
  93. UA_Int32 TL_process(UA_TL_connection *connection, UA_ByteString *packet);
  94. UA_Int32 TL_Connection_init(UA_TL_connection *c, UA_TL_Description* tld);
  95. #endif /* OPCUA_TRANSPORTLAYER_H_ */