Skip to content

Commit 84cd5c1

Browse files
author
Mirela Chirica
committed
Use of APN lookup decision logic fixed
1 parent 9f6454a commit 84cd5c1

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

features/cellular/easy_cellular/EasyCellularConnection.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "CellularLog.h"
3030
#include "mbed_wait_api.h"
3131

32-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
32+
#if USE_APN_LOOKUP
3333
#include "APN_db.h"
34-
#endif //MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
34+
#endif //USE_APN_LOOKUP
3535

3636
namespace mbed {
3737

@@ -59,9 +59,9 @@ EasyCellularConnection::EasyCellularConnection(bool debug) :
5959
NSAPI_ERROR_OK)
6060
{
6161
tr_info("EasyCellularConnection()");
62-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
62+
#if USE_APN_LOOKUP
6363
_credentials_set = false;
64-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
64+
#endif // #if USE_APN_LOOKUP
6565
modem_debug_on(debug);
6666
}
6767

@@ -102,11 +102,11 @@ void EasyCellularConnection::set_credentials(const char *apn, const char *uname,
102102
CellularNetwork * network = _cellularConnectionFSM.get_network();
103103
if (network) {
104104
_credentials_err = network->set_credentials(apn, uname, pwd);
105-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
105+
#if USE_APN_LOOKUP
106106
if (_credentials_err == NSAPI_ERROR_OK) {
107107
_credentials_set = true;
108108
}
109-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
109+
#endif // #if USE_APN_LOOKUP
110110
} else {
111111
tr_error("NO Network...");
112112
}
@@ -163,7 +163,7 @@ nsapi_error_t EasyCellularConnection::connect()
163163
if (err) {
164164
return err;
165165
}
166-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
166+
#if USE_APN_LOOKUP
167167
if (!_credentials_set) {
168168
_target_state = CellularConnectionFSM::STATE_SIM_PIN;
169169
err = _cellularConnectionFSM.continue_to_state(_target_state);
@@ -193,7 +193,7 @@ nsapi_error_t EasyCellularConnection::connect()
193193
return err;
194194
}
195195
}
196-
#endif // MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
196+
#endif // USE_APN_LOOKUP
197197

198198
_target_state = CellularConnectionFSM::STATE_CONNECTED;
199199
err = _cellularConnectionFSM.continue_to_state(_target_state);
@@ -212,9 +212,9 @@ nsapi_error_t EasyCellularConnection::disconnect()
212212
{
213213
_credentials_err = NSAPI_ERROR_OK;
214214
_is_connected = false;
215-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
215+
#if USE_APN_LOOKUP
216216
_credentials_set = false;
217-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
217+
#endif // #if USE_APN_LOOKUP
218218
if (!_cellularConnectionFSM.get_network()) {
219219
return NSAPI_ERROR_NO_CONNECTION;
220220
}

features/cellular/easy_cellular/EasyCellularConnection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include "netsocket/CellularBase.h"
2626

27+
#define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP))
28+
2729
namespace mbed
2830
{
2931

@@ -145,9 +147,9 @@ class EasyCellularConnection: public CellularBase
145147

146148
bool _is_connected;
147149
bool _is_initialized;
148-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
150+
#if USE_APN_LOOKUP
149151
bool _credentials_set;
150-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
152+
#endif // #if USE_APN_LOOKUP
151153
CellularConnectionFSM::CellularState _target_state;
152154

153155
UARTSerial _cellularSerial;

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ nsapi_error_t AT_CellularNetwork::connect(const char *apn,
133133

134134
nsapi_error_t AT_CellularNetwork::delete_current_context()
135135
{
136+
tr_info("Delete context %d", _cid);
136137
_at.clear_error();
137138
_at.cmd_start("AT+CGDCONT=");
138139
_at.write_int(_cid);
@@ -236,12 +237,14 @@ nsapi_error_t AT_CellularNetwork::open_data_channel()
236237
int context_activation_state = _at.read_int();
237238
if (context_id == _cid && context_activation_state == 1) {
238239
is_context_active = true;
240+
tr_debug("PDP context %d is active.", _cid);
241+
break;
239242
}
240243
}
241244
_at.resp_stop();
242245

243246
if (!is_context_active) {
244-
tr_info("Activate PDP context");
247+
tr_info("Activate PDP context %d", _cid);
245248
_at.cmd_start("AT+CGACT=1,");
246249
_at.write_int(_cid);
247250
_at.cmd_stop();
@@ -401,13 +404,20 @@ bool AT_CellularNetwork::set_new_context(int cid)
401404
_ip_stack_type = tmp_stack;
402405
_cid = cid;
403406
_new_context_set = true;
407+
tr_info("New PDP context id %d was created", _cid);
404408
}
405409

406410
return success;
407411
}
408412

409413
bool AT_CellularNetwork::get_context()
410414
{
415+
if (_apn) {
416+
tr_debug("APN in use: %s", _apn);
417+
} else {
418+
tr_debug("NO APN");
419+
}
420+
411421
_at.cmd_start("AT+CGDCONT?");
412422
_at.cmd_stop();
413423
_at.resp_start("+CGDCONT:");
@@ -429,7 +439,7 @@ bool AT_CellularNetwork::get_context()
429439
if (pdp_type_len > 0) {
430440
apn_len = _at.read_string(apn, sizeof(apn) - 1);
431441
if (apn_len >= 0) {
432-
if (_apn && strcmp(apn, _apn) != 0 ) {
442+
if (_apn && (strcmp(apn, _apn) != 0) ) {
433443
continue;
434444
}
435445
nsapi_ip_stack_t pdp_stack = string_to_stack_type(pdp_type_from_context);

0 commit comments

Comments
 (0)