Cellular: Add DNS servers from PDP contexts to nsapi_dns

pull/11162/head
Ari Parkkila 2019-08-05 03:11:37 -07:00
parent 3f74a7f6f9
commit e1124668db
4 changed files with 41 additions and 1 deletions

View File

@ -41,4 +41,5 @@ set(unittest-test-sources
stubs/SerialBase_stub.cpp
stubs/CellularContext_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/SocketAddress_stub.cpp
)

View File

@ -287,3 +287,8 @@ void AT_CellularContext::do_connect_with_retry()
{
}
char *AT_CellularContext::get_interface_name(char *interface_name)
{
return NULL;
}

View File

@ -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<void(nsapi_event_t, intptr_t)> 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()

View File

@ -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<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_error_t connect();
virtual nsapi_error_t disconnect();