sc_zep.c
2.19 KB
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
/*
* 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.
*/
/**
* @{
*
* @file
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "net/ipv6/addr.h"
#include "net/gnrc/ipv6/netif.h"
#include "net/gnrc/nomac.h"
#include "net/gnrc/zep.h"
#include "thread.h"
static gnrc_zep_t zep;
static char zep_stack[THREAD_STACKSIZE_DEFAULT];
int _zep_init(int argc, char **argv)
{
uint16_t src_port = GNRC_ZEP_DEFAULT_PORT;
uint16_t dst_port = GNRC_ZEP_DEFAULT_PORT;
ipv6_addr_t dst_addr;
int res;
if (argc < 2) {
printf("usage: %s dst_addr [src_port [dst_port]]\n", argv[0]);
return 1;
}
if (argc > 2) {
src_port = (uint16_t)atoi(argv[2]);
}
if (argc > 3) {
dst_port = (uint16_t)atoi(argv[3]);
}
ipv6_addr_from_str(&dst_addr, argv[1]);
if ((res = gnrc_zep_init(&zep, src_port, &dst_addr, dst_port)) < 0) {
switch (res) {
case -EADDRINUSE:
printf("error: Source port %" PRIu16 " already in use\n", src_port);
break;
case -EEXIST:
puts("error: ZEP already intialized");
break;
case -ENOTSUP:
printf("error: dst_addr (%s) invalid\n", argv[1]);
break;
case -EOVERFLOW:
puts("error: too many threads running");
break;
default:
puts("unexpected error");
break;
}
return 1;
}
if ((res = gnrc_nomac_init(zep_stack, sizeof(zep_stack), THREAD_PRIORITY_MAIN - 3,
"zep_l2", (gnrc_netdev_t *)&zep)) < 0) {
switch (res) {
case -EOVERFLOW:
puts("error: too many threads running");
break;
default:
puts("unexpected error");
break;
}
return 1;
}
#ifdef MODULE_GNRC_IPV6_NETIF
gnrc_ipv6_netif_init_by_dev();
#endif
return 0;
}
/** @} */