Skip to content
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
20 changes: 12 additions & 8 deletions features/cellular/framework/AT/AT_CellularNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,16 @@ nsapi_error_t AT_CellularNetwork::activate_context()
{
_at.lock();

nsapi_error_t err = set_context_to_be_activated();
nsapi_error_t err = NSAPI_ERROR_OK;

// try to find or create context with suitable stack
if(get_context()) {
// try to authenticate user before activating or modifying context
err = do_user_authentication();
} else {
err = NSAPI_ERROR_NO_CONNECTION;
}

if (err != NSAPI_ERROR_OK) {
_at.unlock();
tr_error("Failed to activate network context! (%d)", err);
Expand Down Expand Up @@ -420,13 +429,8 @@ void AT_CellularNetwork::ppp_status_cb(nsapi_event_t event, intptr_t parameter)
}
#endif

nsapi_error_t AT_CellularNetwork::set_context_to_be_activated()
nsapi_error_t AT_CellularNetwork::do_user_authentication()
{
// try to find or create context with suitable stack
if (!get_context()) {
return NSAPI_ERROR_NO_CONNECTION;
}

// if user has defined user name and password we need to call CGAUTH before activating or modifying context
if (_pwd && _uname) {
_at.cmd_start("AT+CGAUTH=");
Expand All @@ -442,7 +446,7 @@ nsapi_error_t AT_CellularNetwork::set_context_to_be_activated()
}
}

return _at.get_last_error();
return NSAPI_ERROR_OK;
}

bool AT_CellularNetwork::set_new_context(int cid)
Expand Down
2 changes: 1 addition & 1 deletion features/cellular/framework/AT/AT_CellularNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase
void urc_cereg();
void urc_cgreg();

nsapi_error_t set_context_to_be_activated();
nsapi_ip_stack_t string_to_stack_type(const char* pdp_type);

void free_credentials();
Expand Down Expand Up @@ -180,6 +179,7 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase
AuthenticationType _authentication_type;
int _cell_id;
nsapi_connection_status_t _connect_status;
virtual nsapi_error_t do_user_authentication();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for error value anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean no error return value? What about NSAPI_ERROR_AUTH_FAILURE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this topic is not about adding target, so I didn’t make any change about this. Please avoid this topic in this PR.

bool _new_context_set;
bool _is_context_active;
RegistrationStatus _reg_status;
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/common/CellularTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace mbed {
#ifndef CELLULAR_DEVICE
#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
#define CELLULAR_DEVICE QUECTEL_BC95
#elif TARGET_WIO_3G
#define CELLULAR_DEVICE QUECTEL_UG96
#elif TARGET_MTS_DRAGONFLY_F411RE
#define CELLULAR_DEVICE TELIT_HE910
#elif TARGET_MTB_MTS_DRAGONFLY
Expand Down
60 changes: 60 additions & 0 deletions features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QUECTEL/UG96/QUECTEL_UG96.h"
#include "QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h"
#include "QUECTEL/UG96/QUECTEL_UG96_CellularPower.h"

using namespace mbed;
using namespace events;

#define CONNECT_DELIM "\r\n"
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
#define CONNECT_TIMEOUT 8000

#define MAX_STARTUP_TRIALS 5
#define MAX_RESET_TRIALS 5

QUECTEL_UG96::QUECTEL_UG96(EventQueue &queue) : AT_CellularDevice(queue)
{
}

QUECTEL_UG96::~QUECTEL_UG96()
{
}

CellularNetwork *QUECTEL_UG96::open_network(FileHandle *fh)
{
if (!_network) {
_network = new QUECTEL_UG96_CellularNetwork(*get_at_handler(fh));
}
return _network;
}

CellularPower *QUECTEL_UG96::open_power(FileHandle *fh)
{
if (!_power) {
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
_power = new QUECTEL_UG96_CellularPower(*atHandler);
if (!_power) {
release_at_handler(atHandler);
}
}
}
return _power;
}
50 changes: 50 additions & 0 deletions features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef QUECTEL_UG96_H_
#define QUECTEL_UG96_H_

#include "AT_CellularDevice.h"

namespace mbed {

#ifdef TARGET_WIO_3G
#define CELLULAR_SERIAL_TX PA_2
#define CELLULAR_SERIAL_RX PA_3
#else
#define CELLULAR_SERIAL_TX PC_1
#define CELLULAR_SERIAL_RX PC_0
#endif

class QUECTEL_UG96 : public AT_CellularDevice
{
public:

QUECTEL_UG96(events::EventQueue &queue);
virtual ~QUECTEL_UG96();

public: // CellularDevice
virtual CellularNetwork *open_network(FileHandle *fh);
virtual CellularPower *open_power(FileHandle *fh);

public: // NetworkInterface
void handle_urc(FileHandle *fh);

};

} // namespace mbed
#endif // QUECTEL_UG96_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h"

using namespace mbed;

QUECTEL_UG96_CellularNetwork::QUECTEL_UG96_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
{
}

QUECTEL_UG96_CellularNetwork::~QUECTEL_UG96_CellularNetwork()
{
}

bool QUECTEL_UG96_CellularNetwork::get_modem_stack_type(nsapi_ip_stack_t requested_stack)
{
return requested_stack == IPV4_STACK ? true : false;
}

bool QUECTEL_UG96_CellularNetwork::has_registration(RegistrationType reg_type)
{
return (reg_type == C_REG || reg_type == C_GREG);
}

nsapi_error_t QUECTEL_UG96_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
{
_op_act = RAT_UNKNOWN;
return NSAPI_ERROR_UNSUPPORTED;
}

nsapi_error_t QUECTEL_UG96_CellularNetwork::do_user_authentication()
{
if (_pwd && _uname) {
_at.cmd_start("AT+QICSGP=");
_at.write_int(_cid);
_at.write_int(1); // context type 1=IPv4
_at.write_string(_apn);
_at.write_string(_uname);
_at.write_string(_pwd);
_at.write_int(_authentication_type);
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();
if (_at.get_last_error() != NSAPI_ERROR_OK) {
return NSAPI_ERROR_AUTH_FAILURE;
}
}

return NSAPI_ERROR_OK;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef QUECTEL_UG96_CELLULAR_NETWORK_H_
#define QUECTEL_UG96_CELLULAR_NETWORK_H_

#include "AT_CellularNetwork.h"

namespace mbed {

class QUECTEL_UG96_CellularNetwork : public AT_CellularNetwork
{
public:
QUECTEL_UG96_CellularNetwork(ATHandler &atHandler);
virtual ~QUECTEL_UG96_CellularNetwork();

protected:
virtual bool get_modem_stack_type(nsapi_ip_stack_t requested_stack);

virtual bool has_registration(RegistrationType rat);

virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);

virtual nsapi_error_t do_user_authentication();
};

} // namespace mbed

#endif // QUECTEL_UG96_CELLULAR_NETWORK_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QUECTEL_UG96_CellularPower.h"

#include "onboard_modem_api.h"

using namespace mbed;

QUECTEL_UG96_CellularPower::QUECTEL_UG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{

}

QUECTEL_UG96_CellularPower::~QUECTEL_UG96_CellularPower()
{

}

nsapi_error_t QUECTEL_UG96_CellularPower::on()
{
#if MODEM_ON_BOARD
::onboard_modem_init();
::onboard_modem_power_up();
#endif
return NSAPI_ERROR_OK;
}

nsapi_error_t QUECTEL_UG96_CellularPower::off()
{
#if MODEM_ON_BOARD
::onboard_modem_power_down();
#endif
return NSAPI_ERROR_OK;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef QUECTEL_UG96_CELLULARPOWER_H_
#define QUECTEL_UG96_CELLULARPOWER_H_

#include "AT_CellularPower.h"

namespace mbed {

class QUECTEL_UG96_CellularPower : public AT_CellularPower
{
public:
QUECTEL_UG96_CellularPower(ATHandler &atHandler);
virtual ~QUECTEL_UG96_CellularPower();

public: //from CellularPower

virtual nsapi_error_t on();

virtual nsapi_error_t off();
};

} // namespace mbed

#endif // QUECTEL_UG96_CELLULARPOWER_H_
Loading