Skip to content

Commit 658ddf7

Browse files
author
Hasnain Virk
committed
ARMCC link errors fixed, nsapi_ppp glue layer changed
GCC have not been capable enough to catch some linker errors which arose when ethernet support for LWIP was disabled. Checks have been added to make sure that unrefrenced code is not linked in. nsapi_ppp glue layer is made more transparent to public cellular API. Storage of IP addresses is removed. PPP layer already stores the addresses, so we pass the pointer back to the upper layers. If PPP is not used, we provide dummy functions.
1 parent 0108864 commit 658ddf7

File tree

8 files changed

+205
-65
lines changed

8 files changed

+205
-65
lines changed

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_NXP/lpc_phy_dp83848.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "lpc_phy.h"
3232
#include "lpc17xx_emac.h"
3333

34+
#if LWIP_ARP || LWIP_ETHERNET
35+
3436
/** @defgroup dp83848_phy PHY status and control for the DP83848.
3537
* @ingroup lwip_phy
3638
*
@@ -431,6 +433,8 @@ s32_t lpc_phy_sts_sm(struct netif *netif)
431433
return changed;
432434
}
433435

436+
#endif /* LWIP_ARP || LWIP_ETHERNET */
437+
434438
/**
435439
* @}
436440
*/

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_STM/stm32xx_emac.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "cmsis_os.h"
88
#include "mbed_interface.h"
99

10+
// Check for LWIP having Ethernet enabled
11+
#if LWIP_ARP || LWIP_ETHERNET
12+
1013
// Check for Ethernet HAL being present
1114
#ifdef ETH_SUCCESS
1215

@@ -518,3 +521,4 @@ void mbed_default_mac_address(char *mac) {
518521

519522
#endif //ETH_SUCCESS
520523

524+
#endif // LWIP_ARP || LWIP_ETHERNET

features/FEATURE_LWIP/lwip-interface/lwip_stack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "lwip/mld6.h"
3434
#include "lwip/dns.h"
3535
#include "lwip/udp.h"
36+
#include "netif/lwip_ethernet.h"
3637
#include "emac_api.h"
3738
#include "ppp_lwip.h"
3839
#include "lwip_tcp_isn.h"

features/FEATURE_LWIP/lwip-interface/lwipopts.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@
102102
#define MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE 512
103103
#endif
104104

105+
// Thread stack size for private PPP thread
106+
#ifndef MBED_CONF_LWIP_PPP_THREAD_STACKSIZE
107+
#define MBED_CONF_LWIP_PPP_THREAD_STACKSIZE 300
108+
#endif
109+
105110
#if LWIP_DEBUG
106111
#define DEFAULT_THREAD_STACKSIZE MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2
112+
#define PPP_THREAD_STACK_SIZE MBED_CONF_LWIP_PPP_THREAD_STACKSIZE*4
107113
#else
108114
#define DEFAULT_THREAD_STACKSIZE MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE
115+
#define PPP_THREAD_STACK_SIZE MBED_CONF_LWIP_PPP_THREAD_STACKSIZE
109116
#endif
110117

111118
#define MEMP_NUM_SYS_TIMEOUT 16
@@ -260,6 +267,10 @@
260267
#define LWIP_ETHERNET 1
261268
#define LWIP_CHECKSUM_ON_COPY 1
262269
#define LWIP_DHCP LWIP_IPV4
270+
#else
271+
#define LWIP_ARP 0
272+
#define LWIP_ETHERNET 0
273+
#define LWIP_CHECKSUM_ON_COPY 0
263274
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
264275

265276
#if MBED_CONF_LWIP_PPP_ENABLED

features/FEATURE_LWIP/lwip-interface/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
"default-thread-stacksize": {
6565
"help": "Stack size for lwip system threads",
6666
"value": 512
67+
},
68+
"ppp-thread-stacksize": {
69+
"help": "Thread stack size for PPP",
70+
"value": 300
6771
}
6872
}
6973
}

features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp

Lines changed: 75 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ static nsapi_error_t connect_error_code;
5555
// Just one interface for now
5656
static FileHandle *my_stream;
5757
static ppp_pcb *my_ppp_pcb;
58-
static bool ppp_link_up = false;
5958
static bool ppp_active = false;
6059
static const char *login;
6160
static const char *pwd;
6261
static sys_sem_t ppp_close_sem;
63-
static void (*notify_ppp_link_down)(nsapi_error_t) = 0;
62+
static Callback<void(nsapi_error_t)> connection_status_cb;
6463

6564
static EventQueue *prepare_event_queue()
6665
{
@@ -71,13 +70,9 @@ static EventQueue *prepare_event_queue()
7170
// Should be trying to get a global shared event queue here!
7271
// Shouldn't have to be making a private thread!
7372

74-
// Only need to queue 1 event. new blows on failure.
73+
// Only need to queue 2 events. new blows on failure.
7574
event_queue = new EventQueue(2 * EVENTS_EVENT_SIZE, NULL);
76-
#if LWIP_DEBUG
77-
event_thread = new Thread(osPriorityNormal, 900*2);
78-
#else
79-
event_thread = new Thread(osPriorityNormal, 900*1);
80-
#endif
75+
event_thread = new Thread(osPriorityNormal, PPP_THREAD_STACK_SIZE);
8176

8277
if (event_thread->start(callback(event_queue, &EventQueue::dispatch_forever)) != osOK) {
8378
delete event_thread;
@@ -130,7 +125,7 @@ static void ppp_link_status(ppp_pcb *pcb, int err_code, void *ctx)
130125
nsapi_error_t mapped_err_code = NSAPI_ERROR_NO_CONNECTION;
131126

132127
switch(err_code) {
133-
case PPPERR_NONE: {
128+
case PPPERR_NONE:
134129
mapped_err_code = NSAPI_ERROR_OK;
135130
tr_info("status_cb: Connected");
136131
#if PPP_IPV4_SUPPORT
@@ -153,81 +148,88 @@ static void ppp_link_status(ppp_pcb *pcb, int err_code, void *ctx)
153148
tr_debug(" our6_ipaddr = %s", ip6addr_ntoa(netif_ip6_addr(ppp_netif(pcb), 0)));
154149
#endif /* PPP_IPV6_SUPPORT */
155150
break;
156-
}
157-
case PPPERR_PARAM: {
151+
152+
case PPPERR_PARAM:
158153
tr_info("status_cb: Invalid parameter");
159154
break;
160-
}
161-
case PPPERR_OPEN: {
155+
156+
case PPPERR_OPEN:
162157
tr_info("status_cb: Unable to open PPP session");
163158
break;
164-
}
165-
case PPPERR_DEVICE: {
159+
160+
case PPPERR_DEVICE:
166161
tr_info("status_cb: Invalid I/O device for PPP");
167162
break;
168-
}
169-
case PPPERR_ALLOC: {
163+
164+
case PPPERR_ALLOC:
170165
tr_info("status_cb: Unable to allocate resources");
171166
break;
172-
}
173-
case PPPERR_USER: {
167+
168+
case PPPERR_USER:
174169
tr_info("status_cb: User interrupt");
175170
break;
176-
}
177-
case PPPERR_CONNECT: {
171+
172+
case PPPERR_CONNECT:
178173
tr_info("status_cb: Connection lost");
179174
mapped_err_code = NSAPI_ERROR_CONNECTION_LOST;
180175
break;
181-
}
182-
case PPPERR_AUTHFAIL: {
176+
177+
case PPPERR_AUTHFAIL:
183178
tr_info("status_cb: Failed authentication challenge");
184179
mapped_err_code = NSAPI_ERROR_AUTH_FAILURE;
185180
break;
186-
}
187-
case PPPERR_PROTOCOL: {
181+
182+
case PPPERR_PROTOCOL:
188183
tr_info("status_cb: Failed to meet protocol");
189184
break;
190-
}
191-
case PPPERR_PEERDEAD: {
185+
186+
case PPPERR_PEERDEAD:
192187
tr_info("status_cb: Connection timeout");
193188
mapped_err_code = NSAPI_ERROR_CONNECTION_TIMEOUT;
194189
break;
195-
}
196-
case PPPERR_IDLETIMEOUT: {
190+
191+
case PPPERR_IDLETIMEOUT:
197192
tr_info("status_cb: Idle Timeout");
198193
break;
199-
}
200-
case PPPERR_CONNECTTIME: {
194+
195+
case PPPERR_CONNECTTIME:
201196
tr_info("status_cb: Max connect time reached");
202197
break;
203-
}
204-
case PPPERR_LOOPBACK: {
198+
199+
case PPPERR_LOOPBACK:
205200
tr_info("status_cb: Loopback detected");
206201
break;
207-
}
208-
default: {
202+
203+
default:
209204
tr_info("status_cb: Unknown error code %d", err_code);
210205
break;
211-
}
206+
212207
}
213208

214209
if (err_code == PPPERR_NONE) {
215-
ppp_link_up = true;
216210
/* suppress generating a callback event for connection up
217211
* Because connect() call is blocking, why wait for a callback */
218212
return;
219213
}
220214

221215
/* If some error happened, we need to properly shutdown the PPP interface */
222216
if (ppp_active) {
223-
ppp_link_up = false;
224217
ppp_active = false;
225218
connect_error_code = mapped_err_code;
226219
sys_sem_signal(&ppp_close_sem);
227220
}
228221

229222
/* Alright, PPP interface is down, we need to notify upper layer */
230-
notify_ppp_link_down(mapped_err_code);
223+
if (connection_status_cb) {
224+
connection_status_cb(mapped_err_code);
225+
}
226+
}
227+
228+
static void handle_modem_hangup()
229+
{
230+
if (my_ppp_pcb->phase != PPP_PHASE_DEAD) {
231+
ppp_close(my_ppp_pcb, 1);
232+
}
231233
}
232234

233235
#if !PPP_INPROC_IRQ_SAFE
@@ -248,7 +250,8 @@ static void ppp_input()
248250
fhs.events = POLLIN;
249251
poll(&fhs, 1, 0);
250252
if (fhs.revents & (POLLHUP|POLLERR|POLLNVAL)) {
251-
goto hup;
253+
handle_modem_hangup();
254+
return;
252255
}
253256

254257
// Infinite loop, but we assume that we can read faster than the
@@ -259,17 +262,12 @@ static void ppp_input()
259262
if (len == -EAGAIN) {
260263
break;
261264
} else if (len <= 0) {
262-
goto hup;
265+
handle_modem_hangup();
266+
return;
263267
}
264268
pppos_input(my_ppp_pcb, buffer, len);
265269
}
266270
return;
267-
268-
hup:
269-
if (my_ppp_pcb->phase != PPP_PHASE_DEAD) {
270-
ppp_close(my_ppp_pcb, 1);
271-
}
272-
return;
273271
}
274272

275273
static void stream_cb() {
@@ -343,14 +341,14 @@ nsapi_error_t nsapi_ppp_error_code()
343341
return connect_error_code;
344342
}
345343

346-
nsapi_error_t nsapi_ppp_connect(FileHandle *stream, void (*ppp_link_down_cb)(int), const char *uname, const char *password)
344+
nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_error_t)> cb, const char *uname, const char *password)
347345
{
348346
if (my_stream) {
349347
return NSAPI_ERROR_PARAMETER;
350348
}
351349
my_stream = stream;
352350
stream->set_blocking(false);
353-
notify_ppp_link_down = ppp_link_down_cb;
351+
connection_status_cb = cb;
354352
login = uname;
355353
pwd = password;
356354

@@ -375,26 +373,45 @@ NetworkStack *nsapi_ppp_get_stack()
375373
return nsapi_create_stack(&lwip_stack);
376374
}
377375

378-
char *nsapi_ppp_get_ip_addr(char *ip_addr, nsapi_size_t buflen)
376+
const char *nsapi_ppp_get_ip_addr(FileHandle *stream)
379377
{
380-
if (mbed_lwip_get_ip_address(ip_addr, buflen)) {
381-
return ip_addr;
378+
static char ip_addr[IPADDR_STRLEN_MAX];
379+
380+
if (stream == my_stream) {
381+
382+
if (mbed_lwip_get_ip_address(ip_addr, IPADDR_STRLEN_MAX)) {
383+
return ip_addr;
384+
}
382385
}
383386

384387
return NULL;
385388
}
386-
char *nsapi_ppp_get_netmask(char *netmask, nsapi_size_t buflen)
389+
const char *nsapi_ppp_get_netmask(FileHandle *stream)
387390
{
388-
if (mbed_lwip_get_netmask(netmask, buflen)) {
389-
return netmask;
391+
#if LWIP_IPV6
392+
return NULL;
393+
#endif
394+
395+
static char netmask[IPADDR_STRLEN_MAX];
396+
if (stream == my_stream) {
397+
if (mbed_lwip_get_netmask(netmask, IPADDR_STRLEN_MAX)) {
398+
return netmask;
399+
}
390400
}
391401

392402
return NULL;
393403
}
394-
char *nsapi_ppp_get_gw_addr(char *default_gw_addr)
404+
const char *nsapi_ppp_get_gw_addr(FileHandle *stream)
395405
{
396-
if (mbed_lwip_get_gateway(default_gw_addr, sizeof default_gw_addr)) {
397-
return default_gw_addr;
406+
#if LWIP_IPV6
407+
return NULL;
408+
#endif
409+
410+
static char gwaddr[IPADDR_STRLEN_MAX];
411+
if (stream == my_stream) {
412+
if (mbed_lwip_get_gateway(gwaddr, IPADDR_STRLEN_MAX)) {
413+
return gwaddr;
414+
}
398415
}
399416

400417
return NULL;

0 commit comments

Comments
 (0)