@@ -239,16 +239,50 @@ static struct net_pkt *slip_poll_handler(struct slip_context *slip)
239
239
return NULL ;
240
240
}
241
241
242
+ static inline struct net_if * get_iface (struct slip_context * context ,
243
+ u16_t vlan_tag )
244
+ {
245
+ #if defined(CONFIG_NET_VLAN )
246
+ struct net_if * iface ;
247
+
248
+ iface = net_eth_get_vlan_iface (context -> iface , vlan_tag );
249
+ if (!iface ) {
250
+ return context -> iface ;
251
+ }
252
+
253
+ return iface ;
254
+ #else
255
+ ARG_UNUSED (vlan_tag );
256
+
257
+ return context -> iface ;
258
+ #endif
259
+ }
260
+
242
261
static void process_msg (struct slip_context * slip )
243
262
{
263
+ u16_t vlan_tag = NET_VLAN_TAG_UNSPEC ;
244
264
struct net_pkt * pkt ;
245
265
246
266
pkt = slip_poll_handler (slip );
247
267
if (!pkt || !pkt -> frags ) {
248
268
return ;
249
269
}
250
270
251
- if (net_recv_data (slip -> iface , pkt ) < 0 ) {
271
+ #if defined(CONFIG_NET_VLAN )
272
+ {
273
+ struct net_eth_hdr * hdr = NET_ETH_HDR (pkt );
274
+
275
+ if (ntohs (hdr -> type ) == NET_ETH_PTYPE_VLAN ) {
276
+ struct net_eth_vlan_hdr * hdr_vlan =
277
+ (struct net_eth_vlan_hdr * )NET_ETH_HDR (pkt );
278
+
279
+ net_pkt_set_vlan_tci (pkt , ntohs (hdr_vlan -> vlan .tci ));
280
+ vlan_tag = net_pkt_vlan_tag (pkt );
281
+ }
282
+ }
283
+ #endif
284
+
285
+ if (net_recv_data (get_iface (slip , vlan_tag ), pkt ) < 0 ) {
252
286
net_pkt_unref (pkt );
253
287
}
254
288
@@ -441,8 +475,15 @@ static inline struct net_linkaddr *slip_get_mac(struct slip_context *slip)
441
475
static void slip_iface_init (struct net_if * iface )
442
476
{
443
477
struct slip_context * slip = net_if_get_device (iface )-> driver_data ;
444
- struct net_linkaddr * ll_addr = slip_get_mac (slip );
478
+ struct net_linkaddr * ll_addr ;
479
+
480
+ ethernet_init (iface );
481
+
482
+ if (slip -> init_done ) {
483
+ return ;
484
+ }
445
485
486
+ ll_addr = slip_get_mac (slip );
446
487
slip -> init_done = true;
447
488
slip -> iface = iface ;
448
489
@@ -467,15 +508,32 @@ static void slip_iface_init(struct net_if *iface)
467
508
468
509
static struct slip_context slip_context_data ;
469
510
511
+ #if defined(CONFIG_NET_VLAN )
512
+ static enum eth_hw_caps eth_capabilities (struct device * dev )
513
+ {
514
+ ARG_UNUSED (dev );
515
+
516
+ return ETH_HW_VLAN ;
517
+ }
518
+ #endif
519
+
470
520
#if defined(CONFIG_SLIP_TAP ) && defined(CONFIG_NET_L2_ETHERNET )
471
521
static const struct ethernet_api slip_if_api = {
472
522
.iface_api .init = slip_iface_init ,
473
523
.iface_api .send = slip_send ,
524
+
525
+ #if defined(CONFIG_NET_VLAN )
526
+ .get_capabilities = eth_capabilities ,
527
+ #endif
474
528
};
475
529
476
530
#define _SLIP_L2_LAYER ETHERNET_L2
477
531
#define _SLIP_L2_CTX_TYPE NET_L2_GET_CTX_TYPE(ETHERNET_L2)
478
532
#define _SLIP_MTU 1500
533
+
534
+ ETH_NET_DEVICE_INIT (slip , CONFIG_SLIP_DRV_NAME , slip_init , & slip_context_data ,
535
+ NULL , CONFIG_KERNEL_INIT_PRIORITY_DEFAULT , & slip_if_api ,
536
+ _SLIP_MTU );
479
537
#else
480
538
481
539
static const struct net_if_api slip_if_api = {
@@ -486,8 +544,8 @@ static const struct net_if_api slip_if_api = {
486
544
#define _SLIP_L2_LAYER DUMMY_L2
487
545
#define _SLIP_L2_CTX_TYPE NET_L2_GET_CTX_TYPE(DUMMY_L2)
488
546
#define _SLIP_MTU 576
489
- #endif
490
547
491
548
NET_DEVICE_INIT (slip , CONFIG_SLIP_DRV_NAME , slip_init , & slip_context_data ,
492
549
NULL , CONFIG_KERNEL_INIT_PRIORITY_DEFAULT , & slip_if_api ,
493
550
_SLIP_L2_LAYER , _SLIP_L2_CTX_TYPE , _SLIP_MTU );
551
+ #endif
0 commit comments