Embedded TCP/IP stack: fnet_netif_prv.h Source File

FNET

fnet_netif_prv.h
1 /**************************************************************************
2 *
3 * Copyright 2011-2016 by Andrey Butok. FNET Community.
4 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 ***************************************************************************
21 *
22 * Private. FNET Network interface API.
23 *
24 ***************************************************************************/
25 
26 #ifndef _FNET_NETIF_PRV_H_
27 
28 #define _FNET_NETIF_PRV_H_
29 
30 #include "fnet.h"
31 #include "fnet_netbuf.h"
32 #include "fnet_netif.h"
33 #include "fnet_eth.h"
34 #include "fnet_nd6.h"
35 #include "fnet_wifi_prv.h"
36 
37 /**************************************************************************/
41 typedef enum
42 {
43  FNET_NETIF_FEATURE_NONE = 0x00, /* No special feature.*/
44  FNET_NETIF_FEATURE_HW_TX_IP_CHECKSUM = 0x01, /* If an IP frame is transmitted, the checksum is inserted automatically. The IP header checksum field
45  * must be cleared. If a non-IP frame is transmitted the frame is not modified.*/
46  FNET_NETIF_FEATURE_HW_TX_PROTOCOL_CHECKSUM = 0x02, /* If an IP frame with a known protocol is transmitted (UDP,TCP,ICMP), the checksum is inserted automatically into the
47  * frame. The checksum field must be cleared. The other frames are not modified.*/
48  FNET_NETIF_FEATURE_HW_RX_IP_CHECKSUM = 0x04, /* If an IPv4 frame is received with a mismatching header checksum,
49  * the frame is discarded.*/
50  FNET_NETIF_FEATURE_HW_RX_PROTOCOL_CHECKSUM = 0x08 /* If a TCP/IP, UDP/IP, or ICMP/IP frame is received that has a wrong TCP, UDP, or ICMP checksum,
51  * the frame is discarded.*/
52 } fnet_netif_feature_t;
53 
54 /**************************************************************************/
57 typedef struct
58 {
67 #if FNET_CFG_DNS
68  fnet_ip4_addr_t dns;
69 #endif
70  fnet_netif_ip_addr_type_t address_type;
72 
73 /* Maxinmum number of IPv6 addresses per interface.*/
74 #define FNET_NETIF_IP6_ADDR_MAX FNET_CFG_NETIF_IP6_ADDR_MAX
75 /* A lifetime value of all one bits (0xffffffff) represents infinity. */
76 #define FNET_NETIF_IP6_ADDR_LIFETIME_INFINITE FNET_ND6_PREFIX_LIFETIME_INFINITE
77 
78 /*********************************************************************
79  * Interface IPv6 address structure.
80  *********************************************************************/
81 typedef struct fnet_netif_ip6_addr
82 {
83  fnet_ip6_addr_t address; /* IPv6 address.*/
84  fnet_netif_ip6_addr_state_t state; /* Address current state.*/
85  fnet_netif_ip_addr_type_t type; /* How the address was acquired.*/
86  fnet_ip6_addr_t solicited_multicast_addr; /* Solicited-node multicast */
87 
88  fnet_time_t creation_time; /* Time of entry creation (in seconds).*/
89  fnet_time_t lifetime; /* Address lifetime (in seconds). 0xFFFFFFFF = Infinite Lifetime
90  * RFC4862. A link-local address has an infinite preferred and valid lifetime; it
91  * is never timed out.*/
92  fnet_size_t prefix_length; /* Prefix length (in bits). The number of leading bits
93  * in the Prefix that are valid. */
94  fnet_index_t dad_transmit_counter; /* Counter used by DAD. Equals to the number
95  * of NS transmits till DAD is finished.*/
96  fnet_time_t state_time; /* Time of last state event.*/
97 } fnet_netif_ip6_addr_t;
98 
99 struct fnet_netif; /* Forward declaration.*/
100 /**************************************************************************/
104 typedef struct fnet_netif_api
105 {
106  fnet_netif_type_t netif_type; /* Data-link type. */
107  fnet_size_t netif_hw_addr_size; /* HW address size.*/
108  fnet_return_t (*netif_init)( struct fnet_netif *netif ); /* Initialization function.*/
109  void (*netif_release)( struct fnet_netif *netif ); /* Shutdown/release function.*/
110 #if FNET_CFG_IP4
111  void (*netif_output_ip4)(struct fnet_netif *netif, fnet_ip4_addr_t dest_ip_addr, fnet_netbuf_t *nb); /* IPv4 Transmit function.*/
112 #endif
113  void (*netif_change_addr_notify)( struct fnet_netif *netif ); /* Address change notification function.*/
114  void (*netif_drain)( struct fnet_netif *netif ); /* Memory drain function.*/
115  fnet_return_t (*netif_get_hw_addr)( struct fnet_netif *netif, fnet_uint8_t *hw_addr); /* Get HW address (Optional).*/
116  fnet_return_t (*netif_set_hw_addr)( struct fnet_netif *netif, fnet_uint8_t *hw_addr); /* Set HW address (Optional). */
117  fnet_bool_t (*netif_is_connected)( struct fnet_netif *netif ); /* Connection state flag (Optional).*/
118  fnet_return_t (*netif_get_statistics)( struct fnet_netif *netif, struct fnet_netif_statistics *statistics ); /* Get statistics */
119 #if FNET_CFG_MULTICAST
120 #if FNET_CFG_IP4
121  void (*netif_multicast_join_ip4)( struct fnet_netif *netif, fnet_ip4_addr_t multicast_addr ); /* Join IPv4 multicast group */
122  void (*netif_multicast_leave_ip4)( struct fnet_netif *netif, fnet_ip4_addr_t multicast_addr ); /* Leave IPv4 multicast group */
123 #endif
124 #if FNET_CFG_IP6
125  void (*netif_multicast_join_ip6)( struct fnet_netif *netif, const fnet_ip6_addr_t *multicast_addr ); /* Join IPv4 multicast group */
126  void (*netif_multicast_leave_ip6)( struct fnet_netif *netif, fnet_ip6_addr_t *multicast_addr ); /* Leave IPv6 multicast group */
127 #endif
128 #endif
129 #if FNET_CFG_IP6
130  void (*netif_output_ip6)(struct fnet_netif *netif, const fnet_ip6_addr_t *src_ip_addr, const fnet_ip6_addr_t *dest_ip_addr, fnet_netbuf_t *nb); /* IPv6 Transmit function.*/
131 #endif
132  union /* Points to interface specific API structure (Optional). For FNET_NETIF_TYPE_WIFI type it points to fnet_wifi_api_t, for other types it is set to NULL */
133  {
134  const fnet_wifi_api_t *wifi_api;
135  /* Put here new type-specific APIs */
136  };
137 } fnet_netif_api_t;
138 
139 /* Forward declaration.*/
140 struct fnet_nd6_if;
141 struct fnet_arp_if;
142 
143 /**************************************************************************/
147 typedef struct fnet_netif
148 {
149  fnet_char_t netif_name[FNET_NETIF_NAMELEN]; /* Network interface name (e.g. "eth0", "loop"). */
150  fnet_size_t netif_mtu; /* Maximum transmission unit. */
151  void *netif_prv; /* Points to interface specific control data structure (Optional). */
152  const fnet_netif_api_t *netif_api; /* Pointer to Interafce API structure.*/
153 
154  /* Privat structure fields.*/
155  struct fnet_netif *next; /* Pointer to the next net_if structure. */
156  struct fnet_netif *prev; /* Pointer to the previous net_if structure. */
157  fnet_scope_id_t scope_id; /* Scope zone index, defining network interface. Used by IPv6 sockets.*/
158  fnet_uint32_t features; /* Supported features. Bitwise of fnet_netif_feature_t.*/
159  fnet_bool_t is_connected; /* Connection state, updated by fnet_netif_is_connected() call.*/
160  fnet_time_t is_connected_timestamp; /* The timestamp, in milliseconds, when is_connected updated last time.*/
161 #if FNET_CFG_IP4
162  fnet_netif_ip4_addr_t ip4_addr; /* The interface IPv4 address structure. */
163  fnet_bool_t ip4_addr_conflict; /* Flag if the ip4_addr is duplicated.*/
164  struct fnet_arp_if *arp_if_ptr; /* Pointer to the ARP structure, if the interface supports ARP. */
165 #endif
166 #if FNET_CFG_IP6
167  fnet_netif_ip6_addr_t ip6_addr[FNET_NETIF_IP6_ADDR_MAX]; /* The interface IPv6 address structure. */
168  struct fnet_nd6_if *nd6_if_ptr; /* Pointer to the ND structure, if the interface supports ND. */
169 #if FNET_CFG_MLD
170  fnet_bool_t mld_invalid; /* Flag that, MLD message was sent with the unspecified address.
171  * Once a valid link-local address is available, a node SHOULD generate
172  * new MLD Report messages for all multicast addresses joined on the
173  * interface.*/
174 #endif
175 #if FNET_CFG_IP6_PMTU_DISCOVERY
176  fnet_size_t pmtu; /* Path MTU, changed by Path MTU Discovery for IPv6. If 0 - is disabled.*/
177  fnet_time_t pmtu_timestamp; /* The timestamp, in milliseconds, when PMTU was changed last time.*/
178  fnet_timer_desc_t pmtu_timer; /* PMTU timer,used to detect increases in PMTU.*/
179 #endif
180 #endif /* FNET_CFG_IP6 */
181 } fnet_netif_t;
182 
183 /************************************************************************
184 * Global Data Structures
185 *************************************************************************/
186 extern fnet_netif_t *fnet_netif_list; /* The list of network interfaces.*/
187 extern fnet_netif_t *fnet_netif_default; /* Default net_if. */
188 
189 /************************************************************************
190 * Function Prototypes
191 *************************************************************************/
192 #if defined(__cplusplus)
193 extern "C" {
194 #endif
195 
196 void fnet_netif_release_all( void );
197 void fnet_netif_drain( void );
198 void fnet_netif_signal_p4_addr_conflict( fnet_netif_desc_t netif );
199 
200 #if FNET_CFG_MULTICAST & FNET_CFG_IP4
201 void _fnet_netif_join_ip4_multicast (fnet_netif_desc_t netif_desc, fnet_ip4_addr_t multicast_addr);
202 void _fnet_netif_leave_ip4_multicast (fnet_netif_desc_t netif_desc, fnet_ip4_addr_t multicast_addr);
203 #endif
204 fnet_return_t _fnet_netif_set_hw_addr(fnet_netif_desc_t netif_desc, fnet_uint8_t *hw_addr, fnet_size_t hw_addr_size);
205 
206 #if FNET_CFG_IP6
207 fnet_netif_ip6_addr_t *fnet_netif_get_ip6_addr_info(fnet_netif_t *netif, const fnet_ip6_addr_t *ip_addr);
208 fnet_return_t fnet_netif_bind_ip6_addr_prv(fnet_netif_t *netif, const fnet_ip6_addr_t *addr, fnet_netif_ip_addr_type_t addr_type,
209  fnet_time_t lifetime /*in seconds*/, fnet_size_t prefix_length /* bits */ );
210 fnet_return_t fnet_netif_unbind_ip6_addr_prv ( fnet_netif_t *netif, fnet_netif_ip6_addr_t *if_addr );
211 fnet_bool_t fnet_netif_is_my_ip6_addr(fnet_netif_t *netif, const fnet_ip6_addr_t *ip_addr);
212 fnet_netif_desc_t fnet_netif_get_by_ip6_addr( const fnet_ip6_addr_t *ip_addr );
213 fnet_bool_t fnet_netif_is_my_ip6_solicited_multicast_addr(fnet_netif_t *netif, fnet_ip6_addr_t *ip_addr);
214 void fnet_netif_ip6_addr_timer ( fnet_netif_t *netif);
215 fnet_return_t fnet_netif_set_ip6_addr_autoconf(fnet_netif_t *netif, fnet_ip6_addr_t *ip_addr);
216 fnet_ip6_addr_t *fnet_netif_get_ip6_addr_valid_link_local (fnet_netif_t *netif);
217 #if FNET_CFG_IP6_PMTU_DISCOVERY
218 void fnet_netif_pmtu_init(fnet_netif_t *netif);
219 void fnet_netif_pmtu_release(fnet_netif_t *netif);
220 void fnet_netif_set_pmtu(fnet_netif_t *netif, fnet_size_t pmtu);
221 #endif
222 void _fnet_netif_join_ip6_multicast (fnet_netif_desc_t netif_desc, const fnet_ip6_addr_t *multicast_addr);
223 void _fnet_netif_leave_ip6_multicast (fnet_netif_desc_t netif_desc, fnet_ip6_addr_t *multicast_addr);
224 #endif /* FNET_CFG_IP6 */
225 
226 #if defined(__cplusplus)
227 }
228 #endif
229 
230 #endif /* _FNET_NETIF_PRV_H_ */
fnet_ip4_addr_t subnet
fnet_ip4_addr_t netmask
fnet_netif_ip_addr_type_t
Possible IPv6 address types.
Definition: fnet_netif.h:117
fnet_ip4_addr_t address
fnet_uint32_t fnet_time_t
Unsigned integer type representing time uinits. It can be ticks, seconds or milliseconds.
Definition: fnet_timer.h:66
fnet_ip4_addr_t subnetbroadcast
fnet_uint32_t fnet_scope_id_t
cope zone index type, defining network interface.
Definition: fnet_socket.h:144
#define FNET_NETIF_NAMELEN
The maximum length of a network interface name.
Definition: fnet_netif.h:66
fnet_return_t
General return codes, used by most of API functions.
Definition: fnet_stdlib.h:90
fnet_ip4_addr_t gateway
unsigned long fnet_size_t
Unsigned integer type representing the size in bytes.
Definition: fnet_stdlib.h:56
128-bit IPv6 address type.
Definition: fnet_ip6.h:38
fnet_netif_ip6_addr_state_t
Possible IPv6 address states.
Definition: fnet_netif.h:96
Network interface statistics, used by the fnet_netif_get_statistics().
Definition: fnet_netif.h:57
fnet_ip4_addr_t net
fnet_bool_t
Boolean type.
Definition: fnet_stdlib.h:81
fnet_ip4_addr_t netbroadcast
fnet_ip4_addr_t subnetmask
unsigned int fnet_index_t
Unsigned integer type representing the index.
Definition: fnet_stdlib.h:71
fnet_uint32_t fnet_ip4_addr_t
32-bit IPv4 address type.
Definition: fnet_ip4.h:36
char fnet_char_t
Type representing the charecter.
Definition: fnet_stdlib.h:76
void * fnet_netif_desc_t
Network interface descriptor.
Definition: fnet_netif.h:71
fnet_netif_type_t
Network interface types.
Definition: fnet_netif.h:46

© 2005-2018 by Andrey Butok. http://fnet.sourceforge.net