dtls_record.hpp
Go to the documentation of this file.
1 #ifndef DTLS_RECORD_HPP
2 #define DTLS_RECORD_HPP
3 
4 #include "dtls.hpp"
5 
6 namespace DTLS {
7 
8 namespace Record {
9 
11  static constexpr uint8_t major12 = 254;
12  static constexpr uint8_t minor12 = 253;
13 
14  uint8_t major;
15  uint8_t minor;
16 
17  void set() {
18  major = major12;
19  minor = minor12;
20  };
21 
22  void set(uint8_t majorSet, uint8_t minorSet) {
23  major = majorSet;
24  minor = minorSet;
25  };
26 
27  bool check() {
28  if ((major == major12) && (minor == minor12)) {
29  return true;
30  } else {
31  return false;
32  }
33  }
34 };
35 
36 struct ContentType {
37  static constexpr uint8_t changeCipherSpec = 20;
38  static constexpr uint8_t alert = 21;
39  static constexpr uint8_t handshake = 22;
40  static constexpr uint8_t applicationData = 23;
41 
42  uint8_t val;
43 
45  void setAlert() { val = alert; };
46  void setHandshake() { val = handshake; };
48 
49  bool isChangeCipherSpec() { return val == changeCipherSpec; };
50  bool isAlert() { return val == alert; };
51  bool isHandshake() { return val == handshake; };
52  bool isApplicationData() { return val == applicationData; };
53 };
54 
55 struct Header {
58  uint16_t epoch;
60  uint16_t length;
61 
62  void setEpoch(uint16_t val) { epoch = val; };
63  void setSequenceNumber(uint48 val) { sequenceNumber = val; };
64  void setLength(uint16_t val) { length = val; };
65 
66  uint16_t getEpoch() { return epoch; };
68  uint16_t getLength() { return length; };
69 };
70 
71 }; // namespace Record
72 }; // namespace DTLS
73 
74 #endif /* DTLS_RECORD_HPP */
static constexpr uint8_t minor12
Definition: dtls_record.hpp:12
Definition: dtls.hpp:7
static constexpr uint8_t applicationData
Definition: dtls_record.hpp:40
This is a 48 bit variable.
Definition: common.hpp:33
uint48 getSequenceNumber()
Definition: dtls_record.hpp:67
void setSequenceNumber(uint48 val)
Definition: dtls_record.hpp:63
static constexpr uint8_t handshake
Definition: dtls_record.hpp:39
static constexpr uint8_t changeCipherSpec
Definition: dtls_record.hpp:37
void setEpoch(uint16_t val)
Definition: dtls_record.hpp:62
static constexpr uint8_t major12
Definition: dtls_record.hpp:11
ProtocolVersion version
Definition: dtls_record.hpp:57
static constexpr uint8_t alert
Definition: dtls_record.hpp:38
void setLength(uint16_t val)
Definition: dtls_record.hpp:64