Skip to content

Cellular: Ublox cellular context activation updated for C030_R412M #10877

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 1 commit into from
Aug 2, 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
3 changes: 2 additions & 1 deletion features/cellular/framework/API/CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class CellularContext : public CellularInterface {
enum AuthenticationType {
NOAUTH = 0,
PAP,
CHAP
CHAP,
AUTOMATIC
};

/* whether the additional exception reports are allowed to be sent when the maximum uplink rate is reached */
Expand Down
129 changes: 126 additions & 3 deletions features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/

#include "UBLOX_AT.h"
#include "UBLOX_AT_CellularNetwork.h"
#include "UBLOX_AT_CellularContext.h"

using namespace mbed;
using namespace events;
Expand Down Expand Up @@ -72,7 +70,8 @@ AT_CellularNetwork *UBLOX_AT::open_network_impl(ATHandler &at)

AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
{
return new UBLOX_AT_CellularContext(at, this, apn, cp_req, nonip_req);
ubx_context = new UBLOX_AT_CellularContext(at, this, apn, cp_req, nonip_req);
return ubx_context;
}

#if MBED_CONF_UBLOX_AT_PROVIDE_DEFAULT
Expand All @@ -89,3 +88,127 @@ CellularDevice *CellularDevice::get_default_instance()
}
#endif

nsapi_error_t UBLOX_AT::init()
{
_at->lock();
_at->flush();
_at->cmd_start("AT");
_at->cmd_stop_read_resp();

#ifdef TARGET_UBLOX_C027
_at->cmd_start("AT+CFUN=0");
_at->cmd_stop_read_resp();
if (_at->get_last_error() == NSAPI_ERROR_OK) {
_at->cmd_start("ATE0"); // echo off
_at->cmd_stop_read_resp();
_at->cmd_start("AT+CMEE=1"); // verbose responses
_at->cmd_stop_read_resp();
config_authentication_parameters();
_at->cmd_start("AT+CFUN=1"); // set full functionality
_at->cmd_stop_read_resp();
}
#else
_at->cmd_start("AT+CFUN=4");
_at->cmd_stop_read_resp();
if (_at->get_last_error() == NSAPI_ERROR_OK) {
_at->cmd_start("ATE0"); // echo off
_at->cmd_stop_read_resp();
_at->cmd_start("AT+CMEE=1"); // verbose responses
_at->cmd_stop_read_resp();
config_authentication_parameters();
_at->cmd_start("AT+CFUN=1"); // set full functionality
_at->cmd_stop_read_resp();
}
#endif

return _at->unlock_return_error();
}

nsapi_error_t UBLOX_AT::config_authentication_parameters()
{
char *config = NULL;
nsapi_error_t err;
char imsi[MAX_IMSI_LENGTH + 1];

if (apn == NULL) {
err = get_imsi(imsi);
if (err == NSAPI_ERROR_OK) {
config = (char *)apnconfig(imsi);
}
}

ubx_context->get_next_credentials(&config);
apn = ubx_context->get_apn();
pwd = ubx_context->get_pwd();
uname = ubx_context->get_uname();
auth = ubx_context->get_auth();

auth = (*uname && *pwd) ? auth : CellularContext::NOAUTH;
err = set_authentication_parameters(apn, uname, pwd, auth);

return err;
}

nsapi_error_t UBLOX_AT::set_authentication_parameters(const char *apn,
const char *username,
const char *password,
CellularContext::AuthenticationType auth)
{
int modem_security = ubx_context->nsapi_security_to_modem_security(auth);

_at->cmd_start("AT+CGDCONT=1,\"IP\",");
_at->write_string(apn);
_at->cmd_stop();
_at->resp_start();
_at->resp_stop();

if (_at->get_last_error() == NSAPI_ERROR_OK) {
#ifdef TARGET_UBLOX_C030_R41XM
if (modem_security == CellularContext::CHAP) {
_at->cmd_start("AT+UAUTHREQ=1,");
_at->write_int(modem_security);
_at->write_string(password);
_at->write_string(username);
_at->cmd_stop();
_at->resp_start();
_at->resp_stop();
} else if (modem_security == CellularContext::NOAUTH) {
_at->cmd_start("AT+UAUTHREQ=1,");
_at->write_int(modem_security);
_at->cmd_stop();
_at->resp_start();
_at->resp_stop();
} else {
_at->cmd_start("AT+UAUTHREQ=1,");
_at->write_int(modem_security);
_at->write_string(username);
_at->write_string(password);
_at->cmd_stop();
_at->resp_start();
_at->resp_stop();
}
#else
_at->cmd_start("AT+UAUTHREQ=1,");
_at->write_int(modem_security);
_at->write_string(username);
_at->write_string(password);
_at->cmd_stop();
_at->resp_start();
_at->resp_stop();
#endif
}

return _at->get_last_error();
}

nsapi_error_t UBLOX_AT::get_imsi(char *imsi)
{
_at->lock();
_at->cmd_start("AT+CIMI");
_at->cmd_stop();
_at->resp_start();
_at->read_string(imsi, MAX_IMSI_LENGTH + 1);
_at->resp_stop();

return _at->unlock_return_error();
}
30 changes: 30 additions & 0 deletions features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
#endif
#endif /* TARGET_FF_ARDUINO */

#include "APN_db.h"
#include "AT_CellularDevice.h"
#include "AT_CellularContext.h"
#include "UBLOX_AT_CellularNetwork.h"
#include "UBLOX_AT_CellularContext.h"

namespace mbed {

Expand All @@ -40,6 +44,32 @@ class UBLOX_AT : public AT_CellularDevice {
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
public: // NetworkInterface
void handle_urc(FileHandle *fh);

virtual nsapi_error_t init();

private:

UBLOX_AT_CellularContext *ubx_context;

/** Length of IMSI buffer.
*/
static const int MAX_IMSI_LENGTH = 15;

const char *apn;
const char *uname;
const char *pwd;

/** The type of authentication to use.
*/
CellularContext::AuthenticationType auth;

nsapi_error_t config_authentication_parameters();

nsapi_error_t set_authentication_parameters(const char *apn, const char *username, const char *password, CellularContext::AuthenticationType auth);

/** Read IMSI of modem.
*/
nsapi_error_t get_imsi(char *imsi);
};

} // namespace mbed
Expand Down
Loading