@@ -404,36 +404,95 @@ 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
{
409
410
_at.lock ();
410
- _at.cmd_start_stop (" +UPSND" , " =" , " %d%d" , PROFILE, 0 );
411
411
412
+ bool ipv4 = false , ipv6 = false ;
413
+
414
+ _at.cmd_start_stop (" +UPSND" , " =" , " %d%d" , PROFILE, 0 );
412
415
_at.resp_start (" +UPSND:" );
416
+
413
417
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 ;
418
+ _at.skip_param (2 );
419
+
420
+ if (_at.read_string (_ip, PDP_IPV6_SIZE) != -1 ) {
421
+ convert_ipv6 (_ip);
422
+ SocketAddress address;
423
+ address.set_ip_address (_ip);
424
+
425
+ ipv4 = (address.get_ip_version () == NSAPI_IPv4);
426
+ ipv6 = (address.get_ip_version () == NSAPI_IPv6);
427
+
428
+ // Try to look for second address ONLY if modem has support for dual stack(can handle both IPv4 and IPv6 simultaneously).
429
+ // Otherwise assumption is that second address is not reliable, even if network provides one.
430
+ if ((_device.get_property (AT_CellularDevice::PROPERTY_IPV4V6_PDP_TYPE) && (_at.read_string (_ip, PDP_IPV6_SIZE) != -1 ))) {
431
+ convert_ipv6 (_ip);
432
+ address.set_ip_address (_ip);
433
+ ipv6 = (address.get_ip_version () == NSAPI_IPv6);
434
+ }
422
435
}
436
+ }
437
+ _at.resp_stop ();
438
+ _at.unlock ();
439
+
440
+ if (ipv4 && ipv6) {
441
+ _stack_type = IPV4V6_STACK;
442
+ } else if (ipv4) {
443
+ _stack_type = IPV4_STACK;
444
+ } else if (ipv6) {
445
+ _stack_type = IPV6_STACK;
446
+ }
423
447
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);
448
+ return (ipv4 || ipv6) ? _ip : NULL ;
449
+ }
450
+
451
+ nsapi_error_t UBLOX_AT_CellularStack::get_ip_address (SocketAddress *address)
452
+ {
453
+ if (!address) {
454
+ return NSAPI_ERROR_PARAMETER;
455
+ }
456
+ _at.lock ();
457
+
458
+ bool ipv4 = false , ipv6 = false ;
459
+
460
+ _at.cmd_start_stop (" +UPSND" , " =" , " %d%d" , PROFILE, 0 );
461
+ _at.resp_start (" +UPSND:" );
462
+
463
+ if (_at.info_resp ()) {
464
+ _at.skip_param (2 );
465
+
466
+ if (_at.read_string (_ip, PDP_IPV6_SIZE) != -1 ) {
467
+ convert_ipv6 (_ip);
468
+ address->set_ip_address (_ip);
469
+
470
+ ipv4 = (address->get_ip_version () == NSAPI_IPv4);
471
+ ipv6 = (address->get_ip_version () == NSAPI_IPv6);
472
+
473
+ // Try to look for second address ONLY if modem has support for dual stack(can handle both IPv4 and IPv6 simultaneously).
474
+ // Otherwise assumption is that second address is not reliable, even if network provides one.
475
+ if ((_device.get_property (AT_CellularDevice::PROPERTY_IPV4V6_PDP_TYPE) && (_at.read_string (_ip, PDP_IPV6_SIZE) != -1 ))) {
476
+ convert_ipv6 (_ip);
477
+ address->set_ip_address (_ip);
478
+ ipv6 = (address->get_ip_version () == NSAPI_IPv6);
479
+ }
427
480
}
428
481
}
429
482
_at.resp_stop ();
430
483
_at.unlock ();
431
484
432
- // we have at least IPV4 address
433
- convert_ipv6 (_ip);
485
+ if (ipv4 && ipv6) {
486
+ _stack_type = IPV4V6_STACK;
487
+ } else if (ipv4) {
488
+ _stack_type = IPV4_STACK;
489
+ } else if (ipv6) {
490
+ _stack_type = IPV6_STACK;
491
+ }
434
492
435
- return _ip ;
493
+ return (ipv4 || ipv6) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS ;
436
494
}
495
+ #endif
437
496
438
497
nsapi_error_t UBLOX_AT_CellularStack::gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version, const char *interface_name)
439
498
{
0 commit comments