From e1124668dbbaf376467207822e4a891d1a26180c Mon Sep 17 00:00:00 2001 From: Ari Parkkila Date: Mon, 5 Aug 2019 03:11:37 -0700 Subject: [PATCH] Cellular: Add DNS servers from PDP contexts to nsapi_dns --- .../AT/at_cellularcontext/unittest.cmake | 1 + UNITTESTS/stubs/AT_CellularContext_stub.cpp | 5 +++ .../framework/AT/AT_CellularContext.cpp | 35 ++++++++++++++++++- .../framework/AT/AT_CellularContext.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake index 761d1ee357..dae0f2e268 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake @@ -41,4 +41,5 @@ set(unittest-test-sources stubs/SerialBase_stub.cpp stubs/CellularContext_stub.cpp stubs/CellularUtil_stub.cpp + stubs/SocketAddress_stub.cpp ) diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index 87bc66765b..4f89449efa 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -287,3 +287,8 @@ void AT_CellularContext::do_connect_with_retry() { } + +char *AT_CellularContext::get_interface_name(char *interface_name) +{ + return NULL; +} diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index ec3b93d993..3342e006c6 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -239,6 +239,16 @@ const char *AT_CellularContext::get_ip_address() #endif } +char *AT_CellularContext::get_interface_name(char *interface_name) +{ + if (_cid < 0) { + return NULL; + } + MBED_ASSERT(interface_name); + sprintf(interface_name, "ce%02d", _cid); + return interface_name; +} + void AT_CellularContext::attach(Callback status_cb) { _status_cb = status_cb; @@ -458,7 +468,30 @@ nsapi_error_t AT_CellularContext::do_activate_context() nsapi_error_t AT_CellularContext::activate_ip_context() { - return find_and_activate_context(); + nsapi_error_t ret = find_and_activate_context(); +#if !NSAPI_PPP_AVAILABLE + if (ret == NSAPI_ERROR_OK) { + pdpContextList_t params_list; + if (get_pdpcontext_params(params_list) == NSAPI_ERROR_OK) { + pdpcontext_params_t *pdp = params_list.get_head(); + while (pdp) { + SocketAddress addr; + if (addr.set_ip_address(pdp->dns_secondary_addr)) { + tr_info("DNS secondary %s", pdp->dns_secondary_addr); + char ifn[5]; // "ce" + two digit _cid + zero + add_dns_server(addr, get_interface_name(ifn)); + } + if (addr.set_ip_address(pdp->dns_primary_addr)) { + tr_info("DNS primary %s", pdp->dns_primary_addr); + char ifn[5]; // "ce" + two digit _cid + zero + add_dns_server(addr, get_interface_name(ifn)); + } + pdp = pdp->next; + } + } + } +#endif + return ret; } nsapi_error_t AT_CellularContext::activate_non_ip_context() diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index a5da94daa9..9831d9b9fa 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -36,6 +36,7 @@ public: virtual nsapi_error_t set_blocking(bool blocking); virtual NetworkStack *get_stack(); virtual const char *get_ip_address(); + virtual char *get_interface_name(char *interface_name); virtual void attach(mbed::Callback status_cb); virtual nsapi_error_t connect(); virtual nsapi_error_t disconnect();