Skip to content

Commit 97362f2

Browse files
committed
BG96: Add correct get_ip_address implementation
The default get_ip_address implementation was not working for BG9x. Furthermore the cellular connect routine tries to get the address multiple times, which added around 2 seconds of unnecessary delay to the connection. This commit adds the correct implementation using the AT+QIACT? command.
1 parent 5aaf3a3 commit 97362f2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

connectivity/drivers/cellular/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "QUECTEL/BG96/QUECTEL_BG96_CellularStack.h"
2121
#include "CellularLog.h"
2222
#include "netsocket/TLSSocket.h"
23+
#include "CellularUtil.h"
2324

2425
// Ref: Quectel_BG96_SSL_AT_Commands_Manual, ch 2.1.1 AT+QSSLCFG
2526
static const int BG96_SUPPORTED_SSL_VERSION = 4; // All
@@ -157,6 +158,40 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
157158
return err;
158159
}
159160

161+
nsapi_error_t QUECTEL_BG96_CellularStack::get_ip_address(SocketAddress *address)
162+
{
163+
if (!address) {
164+
return NSAPI_ERROR_PARAMETER;
165+
}
166+
_at.lock();
167+
168+
_at.cmd_start_stop("+QIACT", "?");
169+
_at.resp_start("+QIACT:");
170+
171+
int32_t context_type = 0;
172+
173+
if (_at.info_resp()) {
174+
_at.skip_param(); // ID
175+
_at.skip_param(); // State
176+
177+
context_type = _at.read_int();
178+
if (context_type == 1) {
179+
_stack_type = IPV4_STACK;
180+
} else if (context_type == 2) {
181+
_stack_type = IPV6_STACK;
182+
}
183+
184+
if (_at.read_string(_ip, PDP_IPV6_SIZE) != -1) {
185+
mbed_cellular_util::convert_ipv6(_ip);
186+
address->set_ip_address(_ip);
187+
}
188+
}
189+
_at.resp_stop();
190+
_at.unlock();
191+
192+
return (context_type > 0) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS;
193+
}
194+
160195
void QUECTEL_BG96_CellularStack::urc_qiurc_recv()
161196
{
162197
urc_qiurc(URC_RECV);

connectivity/drivers/cellular/QUECTEL/BG96/QUECTEL_BG96_CellularStack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class QUECTEL_BG96_CellularStack : public AT_CellularStack {
4747

4848
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
4949

50+
virtual nsapi_error_t get_ip_address(SocketAddress *address);
51+
5052
#ifdef MBED_CONF_CELLULAR_OFFLOAD_DNS_QUERIES
5153
virtual nsapi_error_t gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version, const char *interface_name);
5254
virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version = NSAPI_UNSPEC,

0 commit comments

Comments
 (0)