Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hn70ap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
f4grx
hn70ap
Commits
1d8b0320
Commit
1d8b0320
authored
6 years ago
by
f4grx
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://github.com/f4grx/hn70ap
parents
92569dcc
b12538e6
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
apps/export/tun.h
+1
-1
1 addition, 1 deletion
apps/export/tun.h
apps/libhn70ap/radio.c
+1
-0
1 addition, 0 deletions
apps/libhn70ap/radio.c
apps/libhn70ap/system.c
+7
-2
7 additions, 2 deletions
apps/libhn70ap/system.c
apps/libhn70ap/tun.c
+71
-9
71 additions, 9 deletions
apps/libhn70ap/tun.c
with
80 additions
and
12 deletions
apps/export/tun.h
+
1
−
1
View file @
1d8b0320
...
...
@@ -45,7 +45,7 @@
typedef
int
(
*
tunrxfunction_f
)(
uint8_t
tun
,
FAR
void
*
arg
,
FAR
uint8_t
*
data
,
int
length
);
int
hn70ap_tun_init
(
void
);
int
hn70ap_tun_init
device
(
char
ifname
[
IFNAMSIZ
]);
int
hn70ap_tun_
dev
init
(
char
ifname
[
IFNAMSIZ
]);
int
hn70ap_tun_addroute
(
int
tunnel
,
in_addr_t
destination
,
int
maskbits
);
int
hn70ap_tun_rxfunction
(
int
tunnel
,
tunrxfunction_f
rx
,
FAR
void
*
arg
,
FAR
uint8_t
*
userbuf
,
int
userbuflen
);
int
hn70ap_tun_transmit
(
int
tunnel
,
FAR
uint8_t
*
buf
,
size_t
len
);
...
...
This diff is collapsed.
Click to expand it.
apps/libhn70ap/radio.c
+
1
−
0
View file @
1d8b0320
...
...
@@ -170,6 +170,7 @@ int hn70ap_radio_devinit(struct radio_s *radio, const char *dev)
goto
lret
;
}
radio
->
alive
=
true
;
ret
=
pthread_create
(
&
radio
->
rxthread
,
NULL
,
hn70ap_radio_rxthread
,
NULL
);
if
(
ret
<
0
)
{
...
...
This diff is collapsed.
Click to expand it.
apps/libhn70ap/system.c
+
7
−
2
View file @
1d8b0320
...
...
@@ -37,9 +37,12 @@
#include
<stdint.h>
#include
<stdbool.h>
#include
<string.h>
#include
<syslog.h>
#include
<net/if.h>
#include
<hn70ap/eeprom.h>
#include
<hn70ap/timer.h>
#include
<hn70ap/leds.h>
...
...
@@ -52,6 +55,7 @@ static bool hn70ap_system_initialized = false;
int
hn70ap_system_init
(
void
)
{
int
ret
;
int
tunid
;
bool
defaults
;
char
tunname
[
IFNAMSIZ
];
...
...
@@ -105,12 +109,13 @@ int hn70ap_system_init(void)
syslog
(
LOG_ERR
,
"WARNING: Failed to initialize tunnels
\n
"
);
}
strcpy
(
tunname
,
"uhf%d"
);
ret
=
hn70ap_tun_init
device
(
tunname
);
str
n
cpy
(
tunname
,
"uhf%d"
,
IFNAMSIZ
);
ret
=
hn70ap_tun_
dev
init
(
tunname
);
if
(
ret
!=
0
)
{
syslog
(
LOG_ERR
,
"WARNING: Failed to initialize TUN interface
\n
"
);
}
tunid
=
ret
;
ret
=
hn70ap_radio_init
();
if
(
ret
!=
0
)
...
...
This diff is collapsed.
Click to expand it.
apps/libhn70ap/tun.c
+
71
−
9
View file @
1d8b0320
...
...
@@ -39,7 +39,9 @@
#include
<fcntl.h>
#include
<unistd.h>
#include
<errno.h>
#include
<pthread.h>
#include
<syslog.h>
#include
<sys/ioctl.h>
...
...
@@ -49,7 +51,9 @@
struct
iptunnel_s
{
int
fd
;
int
fd
;
char
ifname
[
IFNAMSIZ
];
bool
alive
;
pthread_t
rxthread
;
/*data reception and calling back to the user*/
...
...
@@ -61,6 +65,38 @@ struct iptunnel_s
struct
iptunnel_s
tunnels
[
2
];
/****************************************************************************
* hn70ap_tun_rxthread
* This thread waits for packets from the tun interface, and sends them to processes.
****************************************************************************/
void
*
hn70ap_tun_rxthread
(
void
*
arg
)
{
struct
iptunnel_s
*
tunnel
=
(
struct
iptunnel_s
*
)
arg
;
syslog
(
LOG_INFO
,
"Started tun RX thread
\n
"
);
int
ret
;
while
(
tunnel
->
alive
)
{
if
(
tunnel
->
callback
)
{
//Wait for messages on the air
ret
=
read
(
tunnel
->
fd
,
tunnel
->
userbuf
,
tunnel
->
userbuflen
);
if
(
ret
>
0
)
{
//Dispatch them to the callback
tunnel
->
callback
((
tunnel
==
tunnels
)
?
0
:
1
,
tunnel
->
arg
,
tunnel
->
userbuf
,
ret
);
}
else
{
syslog
(
LOG_ERR
,
"tunnel rx failed -> errno=%d
\n
"
,
errno
);
}
}
//callback defined
}
//tunnel alive
syslog
(
LOG_INFO
,
"Stopped tunnel RX thread
\n
"
);
return
NULL
;
}
/****************************************************************************
* hn70ap_tun_transmit
****************************************************************************/
...
...
@@ -95,14 +131,27 @@ int hn70ap_tun_rxfunction(int tunnel, tunrxfunction_f rx, FAR void *arg, FAR uin
}
/****************************************************************************
* hn70ap_tun_init
* hn70ap_tun_
dev
init
****************************************************************************/
int
hn70ap_tun_init
device
(
char
if
name
[
IFNAMSIZ
])
int
hn70ap_tun_
dev
init
(
char
name
[
IFNAMSIZ
])
{
struct
ifreq
ifr
;
int
errcode
;
int
fd
;
struct
ifreq
ifr
;
int
errcode
;
int
fd
;
int
ret
;
struct
iptunnel_s
*
tunnel
=
&
tunnels
[
0
];
if
(
tunnel
->
fd
!=
0
)
{
tunnel
=
&
tunnels
[
1
];
}
if
(
tunnel
->
fd
!=
0
)
{
syslog
(
LOG_ERR
,
"No tunnel available"
);
return
-
1
;
}
if
((
fd
=
open
(
"/dev/tun"
,
O_RDWR
))
<
0
)
{
...
...
@@ -111,9 +160,9 @@ int hn70ap_tun_initdevice(char ifname[IFNAMSIZ])
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
ifr
.
ifr_flags
=
IFF_TUN
;
if
(
if
name
[
0
])
if
(
name
[
0
])
{
strncpy
(
ifr
.
ifr_name
,
if
name
,
IFNAMSIZ
);
strncpy
(
ifr
.
ifr_name
,
name
,
IFNAMSIZ
);
}
if
((
errcode
=
ioctl
(
fd
,
TUNSETIFF
,
(
unsigned
long
)
&
ifr
))
<
0
)
...
...
@@ -121,8 +170,16 @@ int hn70ap_tun_initdevice(char ifname[IFNAMSIZ])
close
(
fd
);
return
errcode
;
}
tunnel
->
fd
=
fd
;
strncpy
(
tunnel
->
ifname
,
ifr
.
ifr_name
,
IFNAMSIZ
);
//Start RX thread
tunnel
->
alive
=
true
;
ret
=
pthread_create
(
&
tunnel
->
rxthread
,
NULL
,
hn70ap_tun_rxthread
,
NULL
);
if
(
ret
<
0
)
{
syslog
(
LOG_ERR
,
"Failed to start the receive thread
\n
"
);
}
return
fd
;
}
...
...
@@ -131,10 +188,15 @@ int hn70ap_tun_initdevice(char ifname[IFNAMSIZ])
* hn70ap_tun_addroute
****************************************************************************/
int
hn70ap_tun_addroute
(
int
fd
,
in_addr_t
destination
,
int
maskbits
)
int
hn70ap_tun_addroute
(
int
tunnel
,
in_addr_t
destination
,
int
maskbits
)
{
return
ERROR
;
}
/****************************************************************************
* hn70ap_tun_init
****************************************************************************/
int
hn70ap_tun_init
(
void
)
{
tunnels
[
0
].
fd
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment