@@ -404,36 +404,61 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
404
404
}
405
405
}
406
406
407
+ #ifndef UBX_MDM_SARA_R41XM
407
408
const char *UBLOX_AT_CellularStack::get_ip_address ()
408
409
{
410
+ SocketAddress address;
411
+
412
+ get_ip_address (&address);
413
+
414
+ return (address.get_ip_version ()) ? (address.get_ip_address ()) : NULL ;
415
+ }
416
+
417
+ nsapi_error_t UBLOX_AT_CellularStack::get_ip_address (SocketAddress *address)
418
+ {
419
+ if (!address) {
420
+ return NSAPI_ERROR_PARAMETER;
421
+ }
409
422
_at.lock ();
410
- _at.cmd_start_stop (" +UPSND" , " =" , " %d%d" , PROFILE, 0 );
411
423
424
+ bool ipv4 = false , ipv6 = false ;
425
+
426
+ _at.cmd_start_stop (" +UPSND" , " =" , " %d%d" , PROFILE, 0 );
412
427
_at.resp_start (" +UPSND:" );
428
+
413
429
if (_at.info_resp ()) {
414
- _at.skip_param ();
415
- _at.skip_param ();
416
- int len = _at.read_string (_ip, NSAPI_IPv4_SIZE);
417
- if (len == -1 ) {
418
- _ip[0 ] = ' \0 ' ;
419
- _at.unlock ();
420
- // no IPV4 address, return
421
- return NULL ;
422
- }
430
+ _at.skip_param (2 );
431
+
432
+ if (_at.read_string (_ip, PDP_IPV6_SIZE) != -1 ) {
433
+ convert_ipv6 (_ip);
434
+ address->set_ip_address (_ip);
423
435
424
- // in case stack type is not IPV4 only, try to look also for IPV6 address
425
- if (_stack_type != IPV4_STACK) {
426
- len = _at.read_string (_ip, PDP_IPV6_SIZE);
436
+ ipv4 = (address->get_ip_version () == NSAPI_IPv4);
437
+ ipv6 = (address->get_ip_version () == NSAPI_IPv6);
438
+
439
+ // Try to look for second address ONLY if modem has support for dual stack(can handle both IPv4 and IPv6 simultaneously).
440
+ // Otherwise assumption is that second address is not reliable, even if network provides one.
441
+ if ((_device.get_property (AT_CellularDevice::PROPERTY_IPV4V6_PDP_TYPE) && (_at.read_string (_ip, PDP_IPV6_SIZE) != -1 ))) {
442
+ convert_ipv6 (_ip);
443
+ address->set_ip_address (_ip);
444
+ ipv6 = (address->get_ip_version () == NSAPI_IPv6);
445
+ }
427
446
}
428
447
}
429
448
_at.resp_stop ();
430
449
_at.unlock ();
431
450
432
- // we have at least IPV4 address
433
- convert_ipv6 (_ip);
451
+ if (ipv4 && ipv6) {
452
+ _stack_type = IPV4V6_STACK;
453
+ } else if (ipv4) {
454
+ _stack_type = IPV4_STACK;
455
+ } else if (ipv6) {
456
+ _stack_type = IPV6_STACK;
457
+ }
434
458
435
- return _ip ;
459
+ return (ipv4 || ipv6) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS ;
436
460
}
461
+ #endif
437
462
438
463
nsapi_error_t UBLOX_AT_CellularStack::gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version, const char *interface_name)
439
464
{
0 commit comments