Blame view

RIOT/sys/net/gnrc/transport_layer/tcp/internal/option.h 1.74 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  /*
   * Copyright (C) 2015-2017 Simon Brummer
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    net_gnrc_tcp TCP
   * @ingroup     net_gnrc
   * @brief       RIOT's TCP implementation for the GNRC network stack.
   *
   * @{
   *
   * @file
   * @brief       TCP option handling declarations.
   *
   * @author      Simon Brummer <simon.brummer@posteo.de>
   */
  
  #ifndef OPTION_H
  #define OPTION_H
  
  #include <stdint.h>
  #include "assert.h"
  #include "net/tcp.h"
  #include "net/gnrc/tcp/tcb.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief Helper function to build the MSS option.
   *
   * @param[in] mss   MSS value that should be set.
   *
   * @returns   MSS option value.
   */
  inline static uint32_t _option_build_mss(uint16_t mss)
  {
      return (((uint32_t) TCP_OPTION_KIND_MSS << 24) |
              ((uint32_t) TCP_OPTION_LENGTH_MSS << 16) | mss);
  }
  
  /**
   * @brief Helper function to build the combined option and control flag field.
   *
   * @param[in]  nopts   Number of options.
   * @param[in]  ctl     Control flag field.
   *
   * @returns   Bitfield with encoded control bits and number of options.
   */
  inline static uint16_t _option_build_offset_control(uint16_t nopts, uint16_t ctl)
  {
      assert(TCP_HDR_OFFSET_MIN <= nopts && nopts <= TCP_HDR_OFFSET_MAX);
      return (nopts << 12) | ctl;
  }
  
  /**
   * @brief Parses options of a given TCP header.
   *
   * @param[in,out] tcb   TCB holding the connection information.
   * @param[in]     hdr   TCP header to be parsed.
   *
   * @returns   Zero on success.
   *            Negative value on error.
   */
  int _option_parse(gnrc_tcp_tcb_t *tcb, tcp_hdr_t *hdr);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* OPTION_H */
  /** @} */