opcua_transportLayer.h 2.0 KB

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