Skip to content

Cellular: Fix Gemalto/Cinterion driver #12131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ void GEMALTO_CINTERION::init_module_els61()
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1, // AT_CGAUTH
1, // AT_CNMI
1, // AT_CSMP
1, // AT_CMGF
1, // AT_CSDH
1, // PROPERTY_IPV4_STACK
1, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
Expand All @@ -147,6 +151,10 @@ void GEMALTO_CINTERION::init_module_ems31()
1, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
1, // AT_CGAUTH
1, // AT_CNMI
1, // AT_CSMP
1, // AT_CMGF
1, // AT_CSDH
1, // PROPERTY_IPV4_STACK
1, // PROPERTY_IPV6_STACK
1, // PROPERTY_IPV4V6_STACK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
#define UDP_PACKET_SIZE 1460
#define FAILURE_TIMEOUT (30*1000) // failure timeout in milliseconds on modem side

/*
* Use connection profile 0 and Internet service profiles starting from 0 for sockets.
*/
#define CONNECTION_PROFILE_ID 0

using namespace mbed;

GEMALTO_CINTERION_CellularStack::GEMALTO_CINTERION_CellularStack(ATHandler &atHandler, const char *apn, const char *user, const char *password,
Expand Down Expand Up @@ -60,6 +55,17 @@ void GEMALTO_CINTERION_CellularStack::urc_sis()
sock->_cb(sock->_data);
}
}
if (urc_code == 0) {
int urc_info_id = _at.read_int();
if (urc_info_id == 48) {
tr_info("Socket closed %d", sock_id);
sock->closed = true;
if (sock->_cb) {
sock->_cb(sock->_data);
}

}
}
}
}

Expand Down Expand Up @@ -109,8 +115,7 @@ void GEMALTO_CINTERION_CellularStack::sisr_urc_handler(int sock_id, int urc_code
nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init()
{
_at.lock();
int connection_profile_id = CONNECTION_PROFILE_ID;
nsapi_error_t err = create_connection_profile(connection_profile_id);
nsapi_error_t err = create_connection_profile(_cid);
if (!err) {
_at.set_urc_handler("^SIS:", mbed::Callback<void()>(this, &GEMALTO_CINTERION_CellularStack::urc_sis));
_at.set_urc_handler("^SISW:", mbed::Callback<void()>(this, &GEMALTO_CINTERION_CellularStack::urc_sisw));
Expand All @@ -122,7 +127,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init()
socket_close_impl(i);
}
_at.clear_error();
close_connection_profile(connection_profile_id);
close_connection_profile(_cid);
}
_at.unlock();
return err;
Expand Down Expand Up @@ -157,8 +162,6 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_close_impl(int sock_id)

nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket *socket, const SocketAddress *address)
{
int connection_profile_id = CONNECTION_PROFILE_ID;

int retry_open = 1;
retry_open:
// setup internet session profile
Expand Down Expand Up @@ -193,7 +196,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
}
if (strcmp(paramTag, "conId") == 0) {
char buf[10];
std::sprintf(buf, "%d", connection_profile_id);
std::sprintf(buf, "%d", _cid);
if (strcmp(paramValue, buf) == 0) {
foundConIdType = true;
}
Expand All @@ -209,7 +212,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
}

if (!foundConIdType) {
_at.at_cmd_discard("^SISS", "=", "%d%s%d", internet_service_id, "conId", connection_profile_id);
_at.at_cmd_discard("^SISS", "=", "%d%s%d", internet_service_id, "conId", _cid);
}

// host address (IPv4) and local+remote port is needed only for BGS2 which does not support UDP server socket
Expand Down Expand Up @@ -238,7 +241,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
_at.at_cmd_discard("^SISO", "=", "%d", internet_service_id);

if (_at.get_last_error()) {
tr_error("Socket %d open failed!", socket->id);
tr_error("Socket %d open failed!", internet_service_id);
_at.clear_error();
socket_close_impl(internet_service_id); // socket may already be open on modem if app and modem are not in sync, as a recovery, try to close the socket so open succeeds the next time
if (retry_open--) {
Expand Down Expand Up @@ -390,7 +393,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
if (!socket->pending_bytes) {
_at.process_oob(); // check for ^SISR URC
if (!socket->pending_bytes) {
tr_debug("Socekt %d recv would block", socket->id);
tr_debug("Socket %d recv would block", socket->id);
return NSAPI_ERROR_WOULD_BLOCK;
}
}
Expand Down