Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
85d6292b
Commit
85d6292b
authored
Oct 19, 2016
by
Dmitry Frank
Committed by
Cesanta Bot
Oct 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add nRF port for Mongoose
Example is not yet added PUBLISHED_FROM=2732386091a0d4cd8d4c6e64dc16467780ec72a5
parent
98ab0950
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
15 deletions
+76
-15
mongoose.c
mongoose.c
+44
-15
mongoose.h
mongoose.h
+32
-0
No files found.
mongoose.c
View file @
85d6292b
...
@@ -11327,6 +11327,35 @@ void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr);
...
@@ -11327,6 +11327,35 @@ void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr);
/* Amalgamated: #include "common/cs_dbg.h" */
/* Amalgamated: #include "common/cs_dbg.h" */
/*
* Depending on whether Mongoose is compiled with ipv6 support, use right
* lwip functions
*/
#if MG_ENABLE_IPV6
# define TCP_NEW tcp_new_ip6
# define TCP_BIND tcp_bind_ip6
# define UDP_BIND udp_bind_ip6
# define IPADDR_NTOA ip6addr_ntoa
# define SET_ADDR(dst, src) \
memcpy((dst)->sin6.sin6_addr.s6_addr, (src)->ip6.addr, \
sizeof((dst)->sin6.sin6_addr.s6_addr))
#else
# define TCP_NEW tcp_new
# define TCP_BIND tcp_bind
# define UDP_BIND udp_bind
# define IPADDR_NTOA ipaddr_ntoa
# define SET_ADDR(dst, src) (dst)->sin.sin_addr.s_addr = GET_IPV4(src)
#endif
/*
* If lwip is compiled with ipv6 support, then API changes even for ipv4
*/
#if !defined(LWIP_IPV6) || !LWIP_IPV6
# define GET_IPV4(ipX_addr) ((ipX_addr)->addr)
#else
# define GET_IPV4(ipX_addr) ((ipX_addr)->ip4.addr)
#endif
void
mg_lwip_ssl_do_hs
(
struct
mg_connection
*
nc
);
void
mg_lwip_ssl_do_hs
(
struct
mg_connection
*
nc
);
void
mg_lwip_ssl_send
(
struct
mg_connection
*
nc
);
void
mg_lwip_ssl_send
(
struct
mg_connection
*
nc
);
void
mg_lwip_ssl_recv
(
struct
mg_connection
*
nc
);
void
mg_lwip_ssl_recv
(
struct
mg_connection
*
nc
);
...
@@ -11354,7 +11383,7 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
...
@@ -11354,7 +11383,7 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
static
err_t
mg_lwip_tcp_conn_cb
(
void
*
arg
,
struct
tcp_pcb
*
tpcb
,
err_t
err
)
{
static
err_t
mg_lwip_tcp_conn_cb
(
void
*
arg
,
struct
tcp_pcb
*
tpcb
,
err_t
err
)
{
struct
mg_connection
*
nc
=
(
struct
mg_connection
*
)
arg
;
struct
mg_connection
*
nc
=
(
struct
mg_connection
*
)
arg
;
DBG
((
"%p connect to %s:%u = %d"
,
nc
,
ipaddr_ntoa
(
&
tpcb
->
remote_ip
),
DBG
((
"%p connect to %s:%u = %d"
,
nc
,
IPADDR_NTOA
(
&
tpcb
->
remote_ip
),
tpcb
->
remote_port
,
err
));
tpcb
->
remote_port
,
err
));
if
(
nc
==
NULL
)
{
if
(
nc
==
NULL
)
{
tcp_abort
(
tpcb
);
tcp_abort
(
tpcb
);
...
@@ -11486,7 +11515,7 @@ static err_t mg_lwip_tcp_sent_cb(void *arg, struct tcp_pcb *tpcb,
...
@@ -11486,7 +11515,7 @@ static err_t mg_lwip_tcp_sent_cb(void *arg, struct tcp_pcb *tpcb,
void
mg_if_connect_tcp
(
struct
mg_connection
*
nc
,
void
mg_if_connect_tcp
(
struct
mg_connection
*
nc
,
const
union
socket_address
*
sa
)
{
const
union
socket_address
*
sa
)
{
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
struct
tcp_pcb
*
tpcb
=
tcp_new
();
struct
tcp_pcb
*
tpcb
=
TCP_NEW
();
cs
->
pcb
.
tcp
=
tpcb
;
cs
->
pcb
.
tcp
=
tpcb
;
ip_addr_t
*
ip
=
(
ip_addr_t
*
)
&
sa
->
sin
.
sin_addr
.
s_addr
;
ip_addr_t
*
ip
=
(
ip_addr_t
*
)
&
sa
->
sin
.
sin_addr
.
s_addr
;
u16_t
port
=
ntohs
(
sa
->
sin
.
sin_port
);
u16_t
port
=
ntohs
(
sa
->
sin
.
sin_port
);
...
@@ -11494,7 +11523,7 @@ void mg_if_connect_tcp(struct mg_connection *nc,
...
@@ -11494,7 +11523,7 @@ void mg_if_connect_tcp(struct mg_connection *nc,
tcp_err
(
tpcb
,
mg_lwip_tcp_error_cb
);
tcp_err
(
tpcb
,
mg_lwip_tcp_error_cb
);
tcp_sent
(
tpcb
,
mg_lwip_tcp_sent_cb
);
tcp_sent
(
tpcb
,
mg_lwip_tcp_sent_cb
);
tcp_recv
(
tpcb
,
mg_lwip_tcp_recv_cb
);
tcp_recv
(
tpcb
,
mg_lwip_tcp_recv_cb
);
cs
->
err
=
tcp_bind
(
tpcb
,
IP_ADDR_ANY
,
0
/* any port */
);
cs
->
err
=
TCP_BIND
(
tpcb
,
IP_ADDR_ANY
,
0
/* any port */
);
DBG
((
"%p tcp_bind = %d"
,
nc
,
cs
->
err
));
DBG
((
"%p tcp_bind = %d"
,
nc
,
cs
->
err
));
if
(
cs
->
err
!=
ERR_OK
)
{
if
(
cs
->
err
!=
ERR_OK
)
{
mg_lwip_post_signal
(
MG_SIG_CONNECT_RESULT
,
nc
);
mg_lwip_post_signal
(
MG_SIG_CONNECT_RESULT
,
nc
);
...
@@ -11515,7 +11544,7 @@ static void mg_lwip_udp_recv_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p,
...
@@ -11515,7 +11544,7 @@ static void mg_lwip_udp_recv_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p,
char
*
data
=
(
char
*
)
malloc
(
len
);
char
*
data
=
(
char
*
)
malloc
(
len
);
union
socket_address
sa
;
union
socket_address
sa
;
(
void
)
pcb
;
(
void
)
pcb
;
DBG
((
"%p %s:%u %u"
,
nc
,
ipaddr_ntoa
(
addr
),
port
,
p
->
len
));
DBG
((
"%p %s:%u %u"
,
nc
,
IPADDR_NTOA
(
addr
),
port
,
p
->
len
));
if
(
data
==
NULL
)
{
if
(
data
==
NULL
)
{
DBG
((
"OOM"
));
DBG
((
"OOM"
));
pbuf_free
(
p
);
pbuf_free
(
p
);
...
@@ -11531,7 +11560,7 @@ static void mg_lwip_udp_recv_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p,
...
@@ -11531,7 +11560,7 @@ static void mg_lwip_udp_recv_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p,
void
mg_if_connect_udp
(
struct
mg_connection
*
nc
)
{
void
mg_if_connect_udp
(
struct
mg_connection
*
nc
)
{
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
struct
udp_pcb
*
upcb
=
udp_new
();
struct
udp_pcb
*
upcb
=
udp_new
();
cs
->
err
=
udp_bind
(
upcb
,
IP_ADDR_ANY
,
0
/* any port */
);
cs
->
err
=
UDP_BIND
(
upcb
,
IP_ADDR_ANY
,
0
/* any port */
);
DBG
((
"%p udp_bind %p = %d"
,
nc
,
upcb
,
cs
->
err
));
DBG
((
"%p udp_bind %p = %d"
,
nc
,
upcb
,
cs
->
err
));
if
(
cs
->
err
==
ERR_OK
)
{
if
(
cs
->
err
==
ERR_OK
)
{
udp_recv
(
upcb
,
mg_lwip_udp_recv_cb
,
nc
);
udp_recv
(
upcb
,
mg_lwip_udp_recv_cb
,
nc
);
...
@@ -11544,7 +11573,7 @@ void mg_if_connect_udp(struct mg_connection *nc) {
...
@@ -11544,7 +11573,7 @@ void mg_if_connect_udp(struct mg_connection *nc) {
void
mg_lwip_accept_conn
(
struct
mg_connection
*
nc
,
struct
tcp_pcb
*
tpcb
)
{
void
mg_lwip_accept_conn
(
struct
mg_connection
*
nc
,
struct
tcp_pcb
*
tpcb
)
{
union
socket_address
sa
;
union
socket_address
sa
;
sa
.
sin
.
sin_addr
.
s_addr
=
tpcb
->
remote_ip
.
addr
;
SET_ADDR
(
&
sa
,
&
tpcb
->
remote_ip
)
;
sa
.
sin
.
sin_port
=
htons
(
tpcb
->
remote_port
);
sa
.
sin
.
sin_port
=
htons
(
tpcb
->
remote_port
);
mg_if_accept_tcp_cb
(
nc
,
&
sa
,
sizeof
(
sa
.
sin
));
mg_if_accept_tcp_cb
(
nc
,
&
sa
,
sizeof
(
sa
.
sin
));
}
}
...
@@ -11552,7 +11581,7 @@ void mg_lwip_accept_conn(struct mg_connection *nc, struct tcp_pcb *tpcb) {
...
@@ -11552,7 +11581,7 @@ void mg_lwip_accept_conn(struct mg_connection *nc, struct tcp_pcb *tpcb) {
static
err_t
mg_lwip_accept_cb
(
void
*
arg
,
struct
tcp_pcb
*
newtpcb
,
err_t
err
)
{
static
err_t
mg_lwip_accept_cb
(
void
*
arg
,
struct
tcp_pcb
*
newtpcb
,
err_t
err
)
{
struct
mg_connection
*
lc
=
(
struct
mg_connection
*
)
arg
;
struct
mg_connection
*
lc
=
(
struct
mg_connection
*
)
arg
;
(
void
)
err
;
(
void
)
err
;
DBG
((
"%p conn %p from %s:%u"
,
lc
,
newtpcb
,
ipaddr_ntoa
(
&
newtpcb
->
remote_ip
),
DBG
((
"%p conn %p from %s:%u"
,
lc
,
newtpcb
,
IPADDR_NTOA
(
&
newtpcb
->
remote_ip
),
newtpcb
->
remote_port
));
newtpcb
->
remote_port
));
struct
mg_connection
*
nc
=
mg_if_accept_new_conn
(
lc
);
struct
mg_connection
*
nc
=
mg_if_accept_new_conn
(
lc
);
if
(
nc
==
NULL
)
{
if
(
nc
==
NULL
)
{
...
@@ -11585,11 +11614,11 @@ static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) {
...
@@ -11585,11 +11614,11 @@ static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) {
int
mg_if_listen_tcp
(
struct
mg_connection
*
nc
,
union
socket_address
*
sa
)
{
int
mg_if_listen_tcp
(
struct
mg_connection
*
nc
,
union
socket_address
*
sa
)
{
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
struct
tcp_pcb
*
tpcb
=
tcp_new
();
struct
tcp_pcb
*
tpcb
=
TCP_NEW
();
ip_addr_t
*
ip
=
(
ip_addr_t
*
)
&
sa
->
sin
.
sin_addr
.
s_addr
;
ip_addr_t
*
ip
=
(
ip_addr_t
*
)
&
sa
->
sin
.
sin_addr
.
s_addr
;
u16_t
port
=
ntohs
(
sa
->
sin
.
sin_port
);
u16_t
port
=
ntohs
(
sa
->
sin
.
sin_port
);
cs
->
err
=
tcp_bind
(
tpcb
,
ip
,
port
);
cs
->
err
=
TCP_BIND
(
tpcb
,
ip
,
port
);
DBG
((
"%p tcp_bind(%s:%u) = %d"
,
nc
,
ipaddr_ntoa
(
ip
),
port
,
cs
->
err
));
DBG
((
"%p tcp_bind(%s:%u) = %d"
,
nc
,
IPADDR_NTOA
(
ip
),
port
,
cs
->
err
));
if
(
cs
->
err
!=
ERR_OK
)
{
if
(
cs
->
err
!=
ERR_OK
)
{
tcp_close
(
tpcb
);
tcp_close
(
tpcb
);
return
-
1
;
return
-
1
;
...
@@ -11606,8 +11635,8 @@ int mg_if_listen_udp(struct mg_connection *nc, union socket_address *sa) {
...
@@ -11606,8 +11635,8 @@ int mg_if_listen_udp(struct mg_connection *nc, union socket_address *sa) {
struct
udp_pcb
*
upcb
=
udp_new
();
struct
udp_pcb
*
upcb
=
udp_new
();
ip_addr_t
*
ip
=
(
ip_addr_t
*
)
&
sa
->
sin
.
sin_addr
.
s_addr
;
ip_addr_t
*
ip
=
(
ip_addr_t
*
)
&
sa
->
sin
.
sin_addr
.
s_addr
;
u16_t
port
=
ntohs
(
sa
->
sin
.
sin_port
);
u16_t
port
=
ntohs
(
sa
->
sin
.
sin_port
);
cs
->
err
=
udp_bind
(
upcb
,
ip
,
port
);
cs
->
err
=
UDP_BIND
(
upcb
,
ip
,
port
);
DBG
((
"%p udb_bind(%s:%u) = %d"
,
nc
,
ipaddr_ntoa
(
ip
),
port
,
cs
->
err
));
DBG
((
"%p udb_bind(%s:%u) = %d"
,
nc
,
IPADDR_NTOA
(
ip
),
port
,
cs
->
err
));
if
(
cs
->
err
!=
ERR_OK
)
{
if
(
cs
->
err
!=
ERR_OK
)
{
udp_remove
(
upcb
);
udp_remove
(
upcb
);
return
-
1
;
return
-
1
;
...
@@ -11759,16 +11788,16 @@ void mg_if_get_conn_addr(struct mg_connection *nc, int remote,
...
@@ -11759,16 +11788,16 @@ void mg_if_get_conn_addr(struct mg_connection *nc, int remote,
memcpy
(
sa
,
&
nc
->
sa
,
sizeof
(
*
sa
));
memcpy
(
sa
,
&
nc
->
sa
,
sizeof
(
*
sa
));
}
else
{
}
else
{
sa
->
sin
.
sin_port
=
htons
(
upcb
->
local_port
);
sa
->
sin
.
sin_port
=
htons
(
upcb
->
local_port
);
sa
->
sin
.
sin_addr
.
s_addr
=
upcb
->
local_ip
.
addr
;
SET_ADDR
(
sa
,
&
upcb
->
local_ip
)
;
}
}
}
else
{
}
else
{
struct
tcp_pcb
*
tpcb
=
cs
->
pcb
.
tcp
;
struct
tcp_pcb
*
tpcb
=
cs
->
pcb
.
tcp
;
if
(
remote
)
{
if
(
remote
)
{
sa
->
sin
.
sin_port
=
htons
(
tpcb
->
remote_port
);
sa
->
sin
.
sin_port
=
htons
(
tpcb
->
remote_port
);
sa
->
sin
.
sin_addr
.
s_addr
=
tpcb
->
remote_ip
.
addr
;
SET_ADDR
(
sa
,
&
tpcb
->
remote_ip
)
;
}
else
{
}
else
{
sa
->
sin
.
sin_port
=
htons
(
tpcb
->
local_port
);
sa
->
sin
.
sin_port
=
htons
(
tpcb
->
local_port
);
sa
->
sin
.
sin_addr
.
s_addr
=
tpcb
->
local_ip
.
addr
;
SET_ADDR
(
sa
,
&
tpcb
->
local_ip
)
;
}
}
}
}
}
}
...
...
mongoose.h
View file @
85d6292b
...
@@ -51,6 +51,7 @@
...
@@ -51,6 +51,7 @@
#define CS_P_MBED 7
#define CS_P_MBED 7
#define CS_P_WINCE 8
#define CS_P_WINCE 8
#define CS_P_NXP_KINETIS 9
#define CS_P_NXP_KINETIS 9
#define CS_P_NRF52 10
/* If not specified explicitly, we guess platform by defines. */
/* If not specified explicitly, we guess platform by defines. */
#ifndef CS_PLATFORM
#ifndef CS_PLATFORM
...
@@ -88,6 +89,7 @@
...
@@ -88,6 +89,7 @@
/* Amalgamated: #include "common/platforms/platform_cc3200.h" */
/* Amalgamated: #include "common/platforms/platform_cc3200.h" */
/* Amalgamated: #include "common/platforms/platform_cc3100.h" */
/* Amalgamated: #include "common/platforms/platform_cc3100.h" */
/* Amalgamated: #include "common/platforms/platform_mbed.h" */
/* Amalgamated: #include "common/platforms/platform_mbed.h" */
/* Amalgamated: #include "common/platforms/platform_nrf52.h" */
/* Amalgamated: #include "common/platforms/platform_wince.h" */
/* Amalgamated: #include "common/platforms/platform_wince.h" */
/* Amalgamated: #include "common/platforms/platform_nxp_kinetis.h" */
/* Amalgamated: #include "common/platforms/platform_nxp_kinetis.h" */
...
@@ -766,6 +768,36 @@ int _stat(const char *pathname, struct stat *st);
...
@@ -766,6 +768,36 @@ int _stat(const char *pathname, struct stat *st);
#endif
/* CS_PLATFORM == CS_P_MBED */
#endif
/* CS_PLATFORM == CS_P_MBED */
#endif
/* CS_COMMON_PLATFORMS_PLATFORM_MBED_H_ */
#endif
/* CS_COMMON_PLATFORMS_PLATFORM_MBED_H_ */
#ifdef MG_MODULE_LINES
#ifdef MG_MODULE_LINES
#line 1 "common/platforms/platform_nrf52.h"
#endif
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_COMMON_PLATFORMS_PLATFORM_NRF52_H_
#define CS_COMMON_PLATFORMS_PLATFORM_NRF52_H_
#if CS_PLATFORM == CS_P_NRF52
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
#define LWIP_TIMEVAL_PRIVATE 0
#define LWIP_PROVIDE_ERRNO 1
#define MG_LWIP 1
#define MG_ENABLE_IPV6 1
#define INT64_FMT PRId64
#define SIZE_T_FMT "u"
#endif
/* CS_PLATFORM == CS_P_NRF52 */
#endif
/* CS_COMMON_PLATFORMS_PLATFORM_NRF52_H_ */
#ifdef MG_MODULE_LINES
#line 1 "common/platforms/simplelink/cs_simplelink.h"
#line 1 "common/platforms/simplelink/cs_simplelink.h"
#endif
#endif
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment