更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
driverif.c 文件参考

浏览源代码.

函数

LWIP_STATIC void driverif_init_ifname (struct netif *netif)
 
LWIP_STATIC err_t driverif_output (struct netif *netif, struct pbuf *p)
 
void driverif_input (struct netif *netif, struct pbuf *p)
 

函数说明

◆ driverif_init_ifname()

LWIP_STATIC void driverif_init_ifname ( struct netif *  netif)

在文件 driverif.c52 行定义.

53{
54 struct netif *tmpnetif = NULL;
55 const char *prefix = (netif->link_layer_type == WIFI_DRIVER_IF) ? "wlan" : "eth";
56
57 netif->name[0] = prefix[0];
58 netif->name[1] = prefix[1];
59
60 for (int i = 0; i < LWIP_NETIF_IFINDEX_MAX_EX; ++i) {
61 if (snprintf_s(netif->full_name, sizeof(netif->full_name), sizeof(netif->full_name) - 1,
62 "%s%d", prefix, i) < 0) {
63 break;
64 }
65 NETIF_FOREACH(tmpnetif) {
66 if (strcmp(tmpnetif->full_name, netif->full_name) == 0) {
67 break;
68 }
69 }
70 if (tmpnetif == NULL) {
71 return;
72 }
73 }
74 netif->full_name[0] = '\0';
75}

◆ driverif_input()

void driverif_input ( struct netif *  netif,
struct pbuf *  p 
)

在文件 driverif.c134 行定义.

135{
136#if PF_PKT_SUPPORT
137#if (DRIVERIF_DEBUG & LWIP_DBG_OFF)
138 u16_t ethhdr_type;
139 struct eth_hdr* ethhdr = NULL;
140#endif
141#else
142 u16_t ethhdr_type;
143 struct eth_hdr *ethhdr = NULL;
144#endif
145 err_t ret = ERR_VAL;
146
147 LWIP_ERROR("driverif_input : invalid arguments", ((netif != NULL) && (p != NULL)), return);
148
149 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : going to receive input packet. netif 0x%p, pbuf 0x%p, \
150 packet_length %"U16_F"\n", (void *)netif, (void *)p, p->tot_len));
151
152 /* points to packet payload, which starts with an Ethernet header */
153 MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
154 if (p->len < SIZEOF_ETH_HDR) {
155 (void)pbuf_free(p);
156 LINK_STATS_INC(link.drop);
157 LINK_STATS_INC(link.link_rx_drop);
158 return;
159 }
160
161#if PF_PKT_SUPPORT
162#if (DRIVERIF_DEBUG & LWIP_DBG_OFF)
163 ethhdr = (struct eth_hdr *)p->payload;
164 ethhdr_type = ntohs(ethhdr->type);
165 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet of type %"U16_F" netif->input=%p\n", ethhdr_type, netif->input));
166#endif
167
168 /* full packet send to tcpip_thread to process */
169 if (netif->input) {
170 ret = netif->input(p, netif);
171 }
172 if (ret != ERR_OK) {
173 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input: IP input error\n"));
174 (void)pbuf_free(p);
175 LINK_STATS_INC(link.drop);
176 LINK_STATS_INC(link.link_rx_drop);
177 if (ret == ERR_MEM) {
178 LINK_STATS_INC(link.link_rx_overrun);
179 }
180 } else {
181 LINK_STATS_INC(link.recv);
182 }
183
184#else
185 ethhdr = (struct eth_hdr *)p->payload;
186 ethhdr_type = ntohs(ethhdr->type);
187
188 switch (ethhdr_type) {
189 /* IP or ARP packet? */
190 case ETHTYPE_IP:
191 case ETHTYPE_IPV6:
192 case ETHTYPE_ARP:
193#if ETHARP_SUPPORT_VLAN
194 case ETHTYPE_VLAN:
195#endif /* ETHARP_SUPPORT_VLAN */
196 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet of type %"U16_F"\n", ethhdr_type));
197 /* full packet send to tcpip_thread to process */
198 if (netif->input != NULL) {
199 ret = netif->input(p, netif);
200 }
201
202 if (ret != ERR_OK) {
203 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input: IP input error\n"));
204 (void)pbuf_free(p);
205 LINK_STATS_INC(link.drop);
206 LINK_STATS_INC(link.link_rx_drop);
207 if (ret == ERR_MEM) {
208 MIB2_STATS_NETIF_INC(netif, ifinoverruns);
209 LINK_STATS_INC(link.link_rx_overrun);
210 }
211 } else {
212 LINK_STATS_INC(link.recv);
213 }
214 break;
215
216 default:
217 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet is of unsupported type %"U16_F"\n", ethhdr_type));
218 (void)pbuf_free(p);
219 LINK_STATS_INC(link.drop);
220 LINK_STATS_INC(link.link_rx_drop);
221 break;
222 }
223#endif
224
225 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet is processed\n"));
226}
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void

◆ driverif_output()

LWIP_STATIC err_t driverif_output ( struct netif *  netif,
struct pbuf *  p 
)

在文件 driverif.c94 行定义.

95{
96 LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_output : going to send packet pbuf 0x%p of length %"U16_F" through netif 0x%p\n", \
97 (void *)p, p->tot_len, (void *)netif));
98
99#if PF_PKT_SUPPORT
100 if (all_pkt_raw_pcbs != NULL) {
101 p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST));
102 p->flags |= PBUF_FLAG_OUTGOING;
103 (void)raw_pkt_input(p, netif, NULL);
104 }
105#endif
106
107#if ETH_PAD_SIZE
108 (void)pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
109#endif
110
111 netif->drv_send(netif, p);
112
113#if ETH_PAD_SIZE
114 (void)pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
115#endif
116 MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
117 LINK_STATS_INC(link.xmit);
118
119 return ERR_OK;
120}