| 1 | #ifndef RIST_PROTO_GRE_H |
| 2 | #define RIST_PROTO_GRE_H |
| 3 | |
| 4 | #include "common/attributes.h" |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #define RIST_GRE_PROTOCOL_TYPE_KEEPALIVE 0x88B5 |
| 8 | #define RIST_GRE_PROTOCOL_TYPE_REDUCED 0x88B6 |
| 9 | #define RIST_GRE_PROTOCOL_TYPE_FULL 0x0800 |
| 10 | #define RIST_GRE_PROTOCOL_TYPE_EAPOL 0x888E |
| 11 | #define RIST_GRE_PROTOCOL_TYPE_VSF 0xCCE0 |
| 12 | #define RIST_GRE_PROTOCOL_REDUCED_SIZE 4 |
| 13 | |
| 14 | #define RIST_GRE_FLAGS_KEY_SEQ 0x000C |
| 15 | #define RIST_GRE_FLAGS_SEQ 0x0008 |
| 16 | |
| 17 | #define RIST_VSF_PROTOCOL_TYPE_RIST 0x0000 |
| 18 | |
| 19 | #define RIST_VSF_PROTOCOL_SUBTYPE_REDUCED 0x0000 |
| 20 | #define RIST_VSF_PROTOCOL_SUBTYPE_KEEPALIVE 0x8000 |
| 21 | #define RIST_VSF_PROTOCOL_SUBTYPE_FUTURE_NONCE 0x8001 |
| 22 | #define RIST_VSF_PROTOCOL_SUBTYPE_BUFFER_NEGOTIATION 0x8002 |
| 23 | |
| 24 | #define RIST_GRE_VERSION_CUR 2 |
| 25 | #define RIST_GRE_VERSION_MIN 1 |
| 26 | |
| 27 | /* |
| 28 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 29 | |0| |0|0|Reserved0|H|RVer | Ver | Protocol Type | |
| 30 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 31 | Figure 1: GRE header with no options |
| 32 | |
| 33 | |
| 34 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 35 | |0| |0|1|Reserved0|H|RVer | Ver | Protocol Type | |
| 36 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 37 | | Sequence Number | |
| 38 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 39 | Figure 2: GRE header with sequence number |
| 40 | |
| 41 | |
| 42 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 43 | |0| |1|1|Reserved0|H|RVer | Ver | Protocol Type | |
| 44 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 45 | | Key/Nonce | |
| 46 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 47 | | Sequence Number | |
| 48 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 49 | Figure 5: GRE header with Key/Nonce |
| 50 | |
| 51 | The sequence number will become the higher 4byte of AES IV. |
| 52 | So, that on increment - the lower bits (which are zero) get incremented |
| 53 | |
| 54 | |
| 55 | Reduce overhead GRE payload header (only one supported for now) |
| 56 | |
| 57 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 58 | | source port | destination port | |
| 59 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 60 | |
| 61 | Keep alive message |
| 62 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 63 | |0| |1|1| Reserved0 | Ver | Protocol Type = 0x88B5 | |
| 64 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 65 | | | |
| 66 | | 48-bit MAC Address +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 67 | | |X|R|B|A|P|E|L|N|D|T|V|J|F|Rsvd1| |
| 68 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 69 | | Message Payload (JSON format) | |
| 70 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 71 | |
| 72 | Buffer negotiation message |
| 73 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 74 | | Sender Max allowed buffer ms | Receiver current buffer MS | |
| 75 | | Protocol type | protocol specific data ... | |
| 76 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 77 | The buffer negotiation message can be used by sender and receiver |
| 78 | to negotiate the configure the desired buffer duration. |
| 79 | Either side may send the message unsollicited. How the receiver |
| 80 | decides on it's current buffer value is implementation defined. |
| 81 | Implementations capable of buffer negotiation shall respond with |
| 82 | their (scoped) values. |
| 83 | Sender max allowed buffer MS (16bit): the maximum buffer value a sender allows |
| 84 | this value /not/ allowed to be decreased during a session. |
| 85 | This value shall be set to 0 if the device isn't capable or configured |
| 86 | for sending data. |
| 87 | Receiver current buffer MS (16bit): the current buffer duration the client |
| 88 | is configured for. The client is free to change this value during |
| 89 | the session up to the senders maximum value. When changing it's |
| 90 | configured buffer duration setting it will notify the sender |
| 91 | via this message. |
| 92 | This value shall be set to 0 if the device isn't capable or configured |
| 93 | for receiving data. |
| 94 | |
| 95 | Protocol type (16bit): setting this value to anything but 0 allows scoping |
| 96 | the buffer configuration protocol to a single stream in a main |
| 97 | profile multiplex. |
| 98 | Allowed values: |
| 99 | 0, no protocol specific data follows. The message |
| 100 | applies to all flows in the session. |
| 101 | Devices not capable of setting a single buffer value to all |
| 102 | flows in a session shall respond with sender and receiver |
| 103 | buffer values set to 0. |
| 104 | 0x88B6, reduced overhead header follows. The message is taken |
| 105 | to apply to the single flow specified by the reduced overhead |
| 106 | header parameters. |
| 107 | Devices not capable of scoping buffer settings to a single flow |
| 108 | shall respond to this message with their buffer values set to 0, |
| 109 | while copying the received protocol type and protocol data |
| 110 | 0x0800, ip + udp header follows. Same logic applies as with reduced |
| 111 | overhead type. |
| 112 | |
| 113 | |
| 114 | Data Channel: |
| 115 | |
| 116 | [ GRE header ] |
| 117 | [ Reduced overhead header .] |
| 118 | [ RTP header .] |
| 119 | [ User payload ] |
| 120 | |
| 121 | */ |
| 122 | |
| 123 | #define SIZEOF_GRE_KEEPALIVE 8 |
| 124 | |
| 125 | RIST_PACKED_STRUCT(rist_gre_keepalive,{ |
| 126 | uint8_t mac_array[6]; |
| 127 | uint8_t capabilities1; |
| 128 | uint8_t capabilities2; |
| 129 | }) |
| 130 | |
| 131 | RIST_PACKED_STRUCT(rist_gre_hdr,{ |
| 132 | uint8_t flags1; |
| 133 | uint8_t flags2; |
| 134 | uint16_t prot_type; |
| 135 | }) |
| 136 | |
| 137 | RIST_PACKED_STRUCT(rist_gre,{ |
| 138 | uint8_t flags1; |
| 139 | uint8_t flags2; |
| 140 | uint16_t prot_type; |
| 141 | uint32_t checksum_reserved1; |
| 142 | }) |
| 143 | |
| 144 | RIST_PACKED_STRUCT(rist_gre_seq,{ |
| 145 | uint8_t flags1; |
| 146 | uint8_t flags2; |
| 147 | uint16_t prot_type; |
| 148 | uint32_t checksum_reserved1; |
| 149 | uint32_t seq; |
| 150 | }) |
| 151 | |
| 152 | RIST_PACKED_STRUCT(rist_gre_key_seq_real,{ |
| 153 | uint8_t flags1; |
| 154 | uint8_t flags2; |
| 155 | uint16_t prot_type; |
| 156 | uint32_t nonce; |
| 157 | uint32_t seq; |
| 158 | }) |
| 159 | |
| 160 | RIST_PACKED_STRUCT(rist_gre_key_seq,{ |
| 161 | uint8_t flags1; |
| 162 | uint8_t flags2; |
| 163 | uint16_t prot_type; |
| 164 | uint32_t checksum_reserved1; |
| 165 | uint32_t nonce; |
| 166 | uint32_t seq; |
| 167 | }) |
| 168 | |
| 169 | RIST_PACKED_STRUCT(rist_vsf_proto,{ |
| 170 | uint16_t type; |
| 171 | uint16_t subtype; |
| 172 | }) |
| 173 | |
| 174 | RIST_PACKED_STRUCT(rist_reduced,{ |
| 175 | uint16_t src_port; |
| 176 | uint16_t dst_port; |
| 177 | }) |
| 178 | |
| 179 | RIST_PACKED_STRUCT(rist_buffer_negotiation, { |
| 180 | uint16_t sender_max_buffer_size_ms; |
| 181 | uint16_t receiver_current_buffer_size_ms; |
| 182 | uint16_t protocol_type; |
| 183 | }) |
| 184 | |
| 185 | #define MAX_GRE_SIZE (sizeof(struct rist_gre_key_seq_real) + sizeof(struct rist_vsf_proto) + sizeof(struct rist_reduced)) |
| 186 | |
| 187 | #endif /* RIST_PROTO_GRE_H */ |