mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Merge pull request #11162 from AriParkkila/cell-dns
Add DNS servers from cellular PDP to nsapipull/11179/head
						commit
						976c30c52b
					
				| 
						 | 
				
			
			@ -41,4 +41,5 @@ set(unittest-test-sources
 | 
			
		|||
  stubs/SerialBase_stub.cpp
 | 
			
		||||
  stubs/CellularContext_stub.cpp
 | 
			
		||||
  stubs/CellularUtil_stub.cpp
 | 
			
		||||
  stubs/SocketAddress_stub.cpp
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -287,3 +287,8 @@ void AT_CellularContext::do_connect_with_retry()
 | 
			
		|||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char *AT_CellularContext::get_interface_name(char *interface_name)
 | 
			
		||||
{
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -451,7 +461,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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -131,6 +131,13 @@ static bool dns_timer_running = false;
 | 
			
		|||
// DNS server configuration
 | 
			
		||||
extern "C" nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr, const char *interface_name)
 | 
			
		||||
{
 | 
			
		||||
    // check if addr was already added
 | 
			
		||||
    for (int i = 0; i < DNS_SERVERS_SIZE; i++) {
 | 
			
		||||
        if (memcmp(&addr, &dns_servers[i], sizeof(nsapi_addr_t)) == 0) {
 | 
			
		||||
            return NSAPI_ERROR_OK;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    memmove(&dns_servers[1], &dns_servers[0],
 | 
			
		||||
            (DNS_SERVERS_SIZE - 1)*sizeof(nsapi_addr_t));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue