Blame view

RIOT/sys/include/net/gnrc/conn.h 4.42 KB
fb11e647   vrobic   reseau statique a...
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  /*
   * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
   *
   * 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_conn   GNRC-specific implementation of the connection API
   * @ingroup     net_gnrc
   * @brief       Provides an implementation of the @ref net_conn by the
   *              @ref net_gnrc
   *
   * @{
   *
   * @file
   * @brief   GNRC-specific types and function definitions
   *
   * @author  Martine Lenders <mlenders@inf.fu-berlin.de>
   */
  #ifndef GNRC_CONN_H_
  #define GNRC_CONN_H_
  
  #include <stdbool.h>
  #include <stdint.h>
  #include "net/ipv6/addr.h"
  #include "net/gnrc.h"
  #include "sched.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief   Connection base class
   * @internal
   */
  typedef struct {
      gnrc_nettype_t l3_type;                     /**< Network layer type of the connection */
      gnrc_nettype_t l4_type;                     /**< Transport layer type of the connection */
      gnrc_netreg_entry_t netreg_entry;           /**< @p net_ng_netreg entry for the connection */
  } conn_t;
  
  /**
   * @brief   Raw connection type
   * @internal
   * @extends conn_t
   */
  struct conn_ip {
      gnrc_nettype_t l3_type;                     /**< Network layer type of the connection. */
      gnrc_nettype_t l4_type;                     /**< Transport layer type of the connection.
                                                   *   Always GNRC_NETTYPE_UNDEF */
      gnrc_netreg_entry_t netreg_entry;           /**< @p net_ng_netreg entry for the connection */
      uint8_t local_addr[sizeof(ipv6_addr_t)];    /**< local IP address */
      size_t local_addr_len;                      /**< length of struct conn_ip::local_addr */
  };
  
  /**
   * @brief   UDP connection type
   * @internal
   * @extends conn_t
   */
  struct conn_udp {
      gnrc_nettype_t l3_type;                     /**< Network layer type of the connection.
                                                   *   Always GNRC_NETTYPE_IPV6 */
      gnrc_nettype_t l4_type;                     /**< Transport layer type of the connection.
                                                   *   Always GNRC_NETTYPE_UDP */
      gnrc_netreg_entry_t netreg_entry;           /**< @p net_ng_netreg entry for the connection */
      uint8_t local_addr[sizeof(ipv6_addr_t)];    /**< local IP address */
      size_t local_addr_len;                      /**< length of struct conn_ip::local_addr */
  };
  
  /**
   * @brief  Bind connection to demux context
   *
   * @internal
   *
   * @param[out] entry    @ref net_ng_netreg entry.
   * @param[in] type      @ref net_ng_nettype.
   * @param[in] demux_ctx demux context (port or proto) for the connection.
   */
  static inline void gnrc_conn_reg(gnrc_netreg_entry_t *entry, gnrc_nettype_t type,
                                   uint32_t demux_ctx)
  {
      gnrc_netreg_entry_init_pid(entry, demux_ctx, sched_active_pid);
      gnrc_netreg_register(type, entry);
  }
  
  /**
   * @brief   Sets local address for a connection
   *
   * @internal
   *
   * @param[out] conn_addr    Pointer to the local address on the connection.
   * @param[in] addr          An IPv6 address.
   *
   * @return  true, if @p addr was a legal address (`::`, `::1` or an address assigned to any
   *          interface of this node) for the connection.
   * @return  false if @p addr was not a legal address for the connection.
   */
  bool gnrc_conn6_set_local_addr(uint8_t *conn_addr, const ipv6_addr_t *addr);
  
  /**
   * @brief   Generic recvfrom
   *
   * @internal
   *
   * @param[in] conn      Connection object.
   * @param[out] data     Pointer where the received data should be stored.
   * @param[in] max_len   Maximum space available at @p data.
   * @param[out] addr     NULL pointer or the sender's IP address. Must fit address of connection's
   *                      family if not NULL.
   * @param[out] addr_len Length of @p addr. May be NULL if @p addr is NULL.
   * @param[out] port     NULL pointer or the sender's port.
   *
   * @return  The number of bytes received on success.
   * @return  0, if no received data is available, but everything is in order.
   * @return  -ENOMEM, if received data was more than max_len.
   * @returne -ETIMEDOUT, if more than 3 IPC messages were not @ref net_ng_netapi receive commands
   *          with the required headers in the packet
   */
  int gnrc_conn_recvfrom(conn_t *conn, void *data, size_t max_len, void *addr, size_t *addr_len,
                         uint16_t *port);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* GNRC_CONN_H_ */
  /** @} */