@@ -19,62 +19,62 @@ extern "C" {
19
19
20
20
/* the maximum of all used hardware address lengths */
21
21
#ifndef NETDEV_HWADDR_MAX_LEN
22
- #define NETDEV_HWADDR_MAX_LEN 8U
22
+ #define NETDEV_HWADDR_MAX_LEN 8U
23
23
#endif
24
24
25
25
/* the maximum of dns server number supported */
26
26
#ifndef NETDEV_DNS_SERVERS_NUM
27
- #define NETDEV_DNS_SERVERS_NUM 2U
27
+ #define NETDEV_DNS_SERVERS_NUM 2U
28
28
#endif
29
29
30
30
#if NETDEV_IPV6
31
31
/* the maximum of dns server number supported */
32
32
#ifndef NETDEV_IPV6_NUM_ADDRESSES
33
- #define NETDEV_IPV6_NUM_ADDRESSES 3U
33
+ #define NETDEV_IPV6_NUM_ADDRESSES 3U
34
34
#endif
35
35
#endif /* NETDEV_IPV6 */
36
36
37
37
/* whether the network interface device is 'up' (set by the network interface driver or application) */
38
- #define NETDEV_FLAG_UP 0x01U
38
+ #define NETDEV_FLAG_UP 0x01U
39
39
/* if set, the network interface device has broadcast capability, only supported in the 'lwIP' stack */
40
- #define NETDEV_FLAG_BROADCAST 0x02U
40
+ #define NETDEV_FLAG_BROADCAST 0x02U
41
41
/* if set, the network interface device has an active link (set by the network interface driver) */
42
- #define NETDEV_FLAG_LINK_UP 0x04U
42
+ #define NETDEV_FLAG_LINK_UP 0x04U
43
43
/* if set, the network interface device is an ethernet device using ARP, only supported in the 'lwIP' stack */
44
- #define NETDEV_FLAG_ETHARP 0x08U
44
+ #define NETDEV_FLAG_ETHARP 0x08U
45
45
/* if set, the network interface device is an ethernet device, only supported in the 'lwIP' stack */
46
- #define NETDEV_FLAG_ETHERNET 0x10U
46
+ #define NETDEV_FLAG_ETHERNET 0x10U
47
47
/* if set, the network interface device has IGMP capability, only supported in the 'lwIP' stack */
48
- #define NETDEV_FLAG_IGMP 0x20U
48
+ #define NETDEV_FLAG_IGMP 0x20U
49
49
/* if set, the network interface device has MLD6 capability, only supported in the 'lwIP' stack */
50
- #define NETDEV_FLAG_MLD6 0x40U
50
+ #define NETDEV_FLAG_MLD6 0x40U
51
51
/* if set, the network interface device connected to internet successfully (set by the network interface driver) */
52
- #define NETDEV_FLAG_INTERNET_UP 0x80U
52
+ #define NETDEV_FLAG_INTERNET_UP 0x80U
53
53
/* if set, the network interface device has DHCP capability (set by the network interface device driver or application) */
54
- #define NETDEV_FLAG_DHCP 0x100U
54
+ #define NETDEV_FLAG_DHCP 0x100U
55
55
56
56
enum netdev_cb_type
57
57
{
58
- NETDEV_CB_ADDR_IP , /* IP address */
59
- NETDEV_CB_ADDR_NETMASK , /* subnet mask */
60
- NETDEV_CB_ADDR_GATEWAY , /* netmask */
61
- NETDEV_CB_ADDR_DNS_SERVER , /* dns server */
62
- NETDEV_CB_STATUS_UP , /* changed to 'up' */
63
- NETDEV_CB_STATUS_DOWN , /* changed to 'down' */
64
- NETDEV_CB_STATUS_LINK_UP , /* changed to 'link up' */
65
- NETDEV_CB_STATUS_LINK_DOWN , /* changed to 'link down' */
66
- NETDEV_CB_STATUS_INTERNET_UP , /* changed to 'internet up' */
67
- NETDEV_CB_STATUS_INTERNET_DOWN , /* changed to 'internet down' */
68
- NETDEV_CB_STATUS_DHCP_ENABLE , /* enable DHCP capability */
69
- NETDEV_CB_STATUS_DHCP_DISABLE , /* disable DHCP capability */
70
- NETDEV_CB_REGISTER , /* netdev register */
71
- NETDEV_CB_DEFAULT_CHANGE , /* netdev default change */
58
+ NETDEV_CB_ADDR_IP , /* IP address */
59
+ NETDEV_CB_ADDR_NETMASK , /* subnet mask */
60
+ NETDEV_CB_ADDR_GATEWAY , /* netmask */
61
+ NETDEV_CB_ADDR_DNS_SERVER , /* dns server */
62
+ NETDEV_CB_STATUS_UP , /* changed to 'up' */
63
+ NETDEV_CB_STATUS_DOWN , /* changed to 'down' */
64
+ NETDEV_CB_STATUS_LINK_UP , /* changed to 'link up' */
65
+ NETDEV_CB_STATUS_LINK_DOWN , /* changed to 'link down' */
66
+ NETDEV_CB_STATUS_INTERNET_UP , /* changed to 'internet up' */
67
+ NETDEV_CB_STATUS_INTERNET_DOWN , /* changed to 'internet down' */
68
+ NETDEV_CB_STATUS_DHCP_ENABLE , /* enable DHCP capability */
69
+ NETDEV_CB_STATUS_DHCP_DISABLE , /* disable DHCP capability */
70
+ NETDEV_CB_REGISTER , /* netdev register */
71
+ NETDEV_CB_DEFAULT_CHANGE , /* netdev default change */
72
72
};
73
73
74
74
struct netdev ;
75
75
76
76
/* function prototype for network interface device status or address change callback functions */
77
- typedef void (* netdev_callback_fn )(struct netdev * netdev , enum netdev_cb_type type );
77
+ typedef void (* netdev_callback_fn )(struct netdev * netdev , enum netdev_cb_type type );
78
78
79
79
struct netdev_ops ;
80
80
@@ -83,30 +83,30 @@ struct netdev
83
83
{
84
84
rt_slist_t list ;
85
85
86
- char name [ RT_NAME_MAX ]; /* network interface device name */
87
- ip_addr_t ip_addr ; /* IP address */
88
- ip_addr_t netmask ; /* subnet mask */
89
- ip_addr_t gw ; /* gateway */
86
+ char name [ RT_NAME_MAX ]; /* network interface device name */
87
+ ip_addr_t ip_addr ; /* IP address */
88
+ ip_addr_t netmask ; /* subnet mask */
89
+ ip_addr_t gw ; /* gateway */
90
90
#if NETDEV_IPV6
91
- ip_addr_t ip6_addr [NETDEV_IPV6_NUM_ADDRESSES ]; /* array of IPv6 addresses */
92
- #endif /* NETDEV_IPV6 */
93
- ip_addr_t dns_servers [NETDEV_DNS_SERVERS_NUM ]; /* DNS server */
94
- uint8_t hwaddr_len ; /* hardware address length */
95
- uint8_t hwaddr [NETDEV_HWADDR_MAX_LEN ]; /* hardware address */
91
+ ip_addr_t ip6_addr [NETDEV_IPV6_NUM_ADDRESSES ]; /* array of IPv6 addresses */
92
+ #endif /* NETDEV_IPV6 */
93
+ ip_addr_t dns_servers [NETDEV_DNS_SERVERS_NUM ]; /* DNS server */
94
+ uint8_t hwaddr_len ; /* hardware address length */
95
+ uint8_t hwaddr [NETDEV_HWADDR_MAX_LEN ]; /* hardware address */
96
96
97
- uint16_t flags ; /* network interface device status flag */
98
- uint16_t mtu ; /* maximum transfer unit (in bytes) */
99
- const struct netdev_ops * ops ; /* network interface device operations */
97
+ uint16_t flags ; /* network interface device status flag */
98
+ uint16_t mtu ; /* maximum transfer unit (in bytes) */
99
+ const struct netdev_ops * ops ; /* network interface device operations */
100
100
101
- netdev_callback_fn status_callback ; /* network interface device flags change callback */
102
- netdev_callback_fn addr_callback ; /* network interface device address information change callback */
101
+ netdev_callback_fn status_callback ; /* network interface device flags change callback */
102
+ netdev_callback_fn addr_callback ; /* network interface device address information change callback */
103
103
104
- int ifindex ; /* network interface device ifindex */
104
+ int ifindex ; /* network interface device ifindex */
105
105
106
106
#ifdef RT_USING_SAL
107
- void * sal_user_data ; /* user-specific data for SAL */
108
- #endif /* RT_USING_SAL */
109
- void * user_data ; /* user-specific data */
107
+ void * sal_user_data ; /* user-specific data for SAL */
108
+ #endif /* RT_USING_SAL */
109
+ void * user_data ; /* user-specific data */
110
110
};
111
111
112
112
/* The list of network interface device */
@@ -116,11 +116,11 @@ extern struct netdev *netdev_default;
116
116
/* The network interface device ping response object */
117
117
struct netdev_ping_resp
118
118
{
119
- ip_addr_t ip_addr ; /* response IP address */
120
- uint16_t data_len ; /* response data length */
121
- uint16_t ttl ; /* time to live */
122
- uint32_t ticks ; /* response time, unit tick */
123
- void * user_data ; /* user-specific data */
119
+ ip_addr_t ip_addr ; /* response IP address */
120
+ uint16_t data_len ; /* response data length */
121
+ uint16_t ttl ; /* time to live */
122
+ uint32_t ticks ; /* response time, unit tick */
123
+ void * user_data ; /* user-specific data */
124
124
};
125
125
126
126
/* The network interface device operations */
@@ -156,7 +156,7 @@ struct netdev *netdev_get_by_name(const char *name);
156
156
struct netdev * netdev_get_by_ifindex (int ifindex );
157
157
#ifdef RT_USING_SAL
158
158
struct netdev * netdev_get_by_family (int family );
159
- int netdev_family_get (struct netdev * netdev );
159
+ int netdev_family_get (struct netdev * netdev );
160
160
#endif /* RT_USING_SAL */
161
161
#if defined(SAL_USING_AF_NETLINK )
162
162
int netdev_getnetdev (struct msg_buf * msg , int (* cb )(struct msg_buf * m_buf , struct netdev * nd , int nd_num , int index , int ipvx ));
@@ -172,16 +172,18 @@ int netdev_set_down(struct netdev *netdev);
172
172
int netdev_dhcp_enabled (struct netdev * netdev , rt_bool_t is_enabled );
173
173
174
174
/* Get network interface device status */
175
- #define netdev_is_up (netdev ) (((netdev)->flags & NETDEV_FLAG_UP) ? (uint8_t)1 : (uint8_t)0)
176
- #define netdev_is_link_up (netdev ) (((netdev)->flags & NETDEV_FLAG_LINK_UP) ? (uint8_t)1 : (uint8_t)0)
177
- #define netdev_is_internet_up (netdev ) (((netdev)->flags & NETDEV_FLAG_INTERNET_UP) ? (uint8_t)1 : (uint8_t)0)
175
+ #define netdev_is_up (netdev ) (((netdev)->flags & NETDEV_FLAG_UP) ? (uint8_t)1 : (uint8_t)0)
176
+ #define netdev_is_link_up (netdev ) (((netdev)->flags & NETDEV_FLAG_LINK_UP) ? (uint8_t)1 : (uint8_t)0)
177
+ #define netdev_is_internet_up (netdev ) (((netdev)->flags & NETDEV_FLAG_INTERNET_UP) ? (uint8_t)1 : (uint8_t)0)
178
178
#define netdev_is_dhcp_enabled (netdev ) (((netdev)->flags & NETDEV_FLAG_DHCP) ? (uint8_t)1 : (uint8_t)0)
179
179
180
180
/* Set network interface device address */
181
- int netdev_set_ipaddr (struct netdev * netdev , const ip_addr_t * ipaddr );
182
- int netdev_set_netmask (struct netdev * netdev , const ip_addr_t * netmask );
183
- int netdev_set_gw (struct netdev * netdev , const ip_addr_t * gw );
184
- int netdev_set_dns_server (struct netdev * netdev , uint8_t dns_num , const ip_addr_t * dns_server );
181
+ int netdev_set_ipaddr (struct netdev * netdev , const ip_addr_t * ipaddr );
182
+ int netdev_set_netmask (struct netdev * netdev , const ip_addr_t * netmask );
183
+ int netdev_set_gw (struct netdev * netdev , const ip_addr_t * gw );
184
+ void netdev_set_dns (char * netdev_name , uint8_t dns_num , char * dns_server );
185
+ int netdev_set_dns_server (struct netdev * netdev , uint8_t dns_num , const ip_addr_t * dns_server );
186
+ void netdev_set_if (char * netdev_name , char * ip_addr , char * gw_addr , char * nm_addr );
185
187
186
188
/* Set network interface device callback, it can be called when the status or address changed */
187
189
void netdev_set_register_callback (netdev_callback_fn status_callback );
0 commit comments