Skip to content

Commit 276588f

Browse files
author
Cruz Monrreal
authored
Merge pull request #7098 from SeeedJP/feature-cellular-mux
[Wio 3G] Adding platform
2 parents c82af3d + 0751dd7 commit 276588f

File tree

16 files changed

+1365
-9
lines changed

16 files changed

+1365
-9
lines changed

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,16 @@ nsapi_error_t AT_CellularNetwork::activate_context()
243243
{
244244
_at.lock();
245245

246-
nsapi_error_t err = set_context_to_be_activated();
246+
nsapi_error_t err = NSAPI_ERROR_OK;
247+
248+
// try to find or create context with suitable stack
249+
if(get_context()) {
250+
// try to authenticate user before activating or modifying context
251+
err = do_user_authentication();
252+
} else {
253+
err = NSAPI_ERROR_NO_CONNECTION;
254+
}
255+
247256
if (err != NSAPI_ERROR_OK) {
248257
_at.unlock();
249258
tr_error("Failed to activate network context! (%d)", err);
@@ -426,13 +435,8 @@ void AT_CellularNetwork::ppp_status_cb(nsapi_event_t event, intptr_t parameter)
426435
}
427436
#endif
428437

429-
nsapi_error_t AT_CellularNetwork::set_context_to_be_activated()
438+
nsapi_error_t AT_CellularNetwork::do_user_authentication()
430439
{
431-
// try to find or create context with suitable stack
432-
if (!get_context()) {
433-
return NSAPI_ERROR_NO_CONNECTION;
434-
}
435-
436440
// if user has defined user name and password we need to call CGAUTH before activating or modifying context
437441
if (_pwd && _uname) {
438442
_at.cmd_start("AT+CGAUTH=");
@@ -448,7 +452,7 @@ nsapi_error_t AT_CellularNetwork::set_context_to_be_activated()
448452
}
449453
}
450454

451-
return _at.get_last_error();
455+
return NSAPI_ERROR_OK;
452456
}
453457

454458
bool AT_CellularNetwork::set_new_context(int cid)

features/cellular/framework/AT/AT_CellularNetwork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase
149149
void urc_cereg();
150150
void urc_cgreg();
151151

152-
nsapi_error_t set_context_to_be_activated();
153152
nsapi_ip_stack_t string_to_stack_type(const char* pdp_type);
154153

155154
void free_credentials();
@@ -180,6 +179,7 @@ class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase
180179
AuthenticationType _authentication_type;
181180
int _cell_id;
182181
nsapi_connection_status_t _connect_status;
182+
virtual nsapi_error_t do_user_authentication();
183183
bool _new_context_set;
184184
bool _is_context_active;
185185
RegistrationStatus _reg_status;

features/cellular/framework/common/CellularTargets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace mbed {
2323
#ifndef CELLULAR_DEVICE
2424
#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
2525
#define CELLULAR_DEVICE QUECTEL_BC95
26+
#elif TARGET_WIO_3G
27+
#define CELLULAR_DEVICE QUECTEL_UG96
2628
#elif TARGET_MTS_DRAGONFLY_F411RE
2729
#define CELLULAR_DEVICE TELIT_HE910
2830
#elif TARGET_MTB_MTS_DRAGONFLY
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "QUECTEL/UG96/QUECTEL_UG96.h"
19+
#include "QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h"
20+
#include "QUECTEL/UG96/QUECTEL_UG96_CellularPower.h"
21+
22+
using namespace mbed;
23+
using namespace events;
24+
25+
#define CONNECT_DELIM "\r\n"
26+
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
27+
#define CONNECT_TIMEOUT 8000
28+
29+
#define MAX_STARTUP_TRIALS 5
30+
#define MAX_RESET_TRIALS 5
31+
32+
QUECTEL_UG96::QUECTEL_UG96(EventQueue &queue) : AT_CellularDevice(queue)
33+
{
34+
}
35+
36+
QUECTEL_UG96::~QUECTEL_UG96()
37+
{
38+
}
39+
40+
CellularNetwork *QUECTEL_UG96::open_network(FileHandle *fh)
41+
{
42+
if (!_network) {
43+
_network = new QUECTEL_UG96_CellularNetwork(*get_at_handler(fh));
44+
}
45+
return _network;
46+
}
47+
48+
CellularPower *QUECTEL_UG96::open_power(FileHandle *fh)
49+
{
50+
if (!_power) {
51+
ATHandler *atHandler = get_at_handler(fh);
52+
if (atHandler) {
53+
_power = new QUECTEL_UG96_CellularPower(*atHandler);
54+
if (!_power) {
55+
release_at_handler(atHandler);
56+
}
57+
}
58+
}
59+
return _power;
60+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef QUECTEL_UG96_H_
19+
#define QUECTEL_UG96_H_
20+
21+
#include "AT_CellularDevice.h"
22+
23+
namespace mbed {
24+
25+
#ifdef TARGET_WIO_3G
26+
#define CELLULAR_SERIAL_TX PA_2
27+
#define CELLULAR_SERIAL_RX PA_3
28+
#else
29+
#define CELLULAR_SERIAL_TX PC_1
30+
#define CELLULAR_SERIAL_RX PC_0
31+
#endif
32+
33+
class QUECTEL_UG96 : public AT_CellularDevice
34+
{
35+
public:
36+
37+
QUECTEL_UG96(events::EventQueue &queue);
38+
virtual ~QUECTEL_UG96();
39+
40+
public: // CellularDevice
41+
virtual CellularNetwork *open_network(FileHandle *fh);
42+
virtual CellularPower *open_power(FileHandle *fh);
43+
44+
public: // NetworkInterface
45+
void handle_urc(FileHandle *fh);
46+
47+
};
48+
49+
} // namespace mbed
50+
#endif // QUECTEL_UG96_H_
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h"
19+
20+
using namespace mbed;
21+
22+
QUECTEL_UG96_CellularNetwork::QUECTEL_UG96_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
23+
{
24+
}
25+
26+
QUECTEL_UG96_CellularNetwork::~QUECTEL_UG96_CellularNetwork()
27+
{
28+
}
29+
30+
bool QUECTEL_UG96_CellularNetwork::get_modem_stack_type(nsapi_ip_stack_t requested_stack)
31+
{
32+
return requested_stack == IPV4_STACK ? true : false;
33+
}
34+
35+
bool QUECTEL_UG96_CellularNetwork::has_registration(RegistrationType reg_type)
36+
{
37+
return (reg_type == C_REG || reg_type == C_GREG);
38+
}
39+
40+
nsapi_error_t QUECTEL_UG96_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
41+
{
42+
_op_act = RAT_UNKNOWN;
43+
return NSAPI_ERROR_UNSUPPORTED;
44+
}
45+
46+
nsapi_error_t QUECTEL_UG96_CellularNetwork::do_user_authentication()
47+
{
48+
if (_pwd && _uname) {
49+
_at.cmd_start("AT+QICSGP=");
50+
_at.write_int(_cid);
51+
_at.write_int(1); // context type 1=IPv4
52+
_at.write_string(_apn);
53+
_at.write_string(_uname);
54+
_at.write_string(_pwd);
55+
_at.write_int(_authentication_type);
56+
_at.cmd_stop();
57+
_at.resp_start();
58+
_at.resp_stop();
59+
if (_at.get_last_error() != NSAPI_ERROR_OK) {
60+
return NSAPI_ERROR_AUTH_FAILURE;
61+
}
62+
}
63+
64+
return NSAPI_ERROR_OK;
65+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef QUECTEL_UG96_CELLULAR_NETWORK_H_
19+
#define QUECTEL_UG96_CELLULAR_NETWORK_H_
20+
21+
#include "AT_CellularNetwork.h"
22+
23+
namespace mbed {
24+
25+
class QUECTEL_UG96_CellularNetwork : public AT_CellularNetwork
26+
{
27+
public:
28+
QUECTEL_UG96_CellularNetwork(ATHandler &atHandler);
29+
virtual ~QUECTEL_UG96_CellularNetwork();
30+
31+
protected:
32+
virtual bool get_modem_stack_type(nsapi_ip_stack_t requested_stack);
33+
34+
virtual bool has_registration(RegistrationType rat);
35+
36+
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
37+
38+
virtual nsapi_error_t do_user_authentication();
39+
};
40+
41+
} // namespace mbed
42+
43+
#endif // QUECTEL_UG96_CELLULAR_NETWORK_H_
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "QUECTEL_UG96_CellularPower.h"
19+
20+
#include "onboard_modem_api.h"
21+
22+
using namespace mbed;
23+
24+
QUECTEL_UG96_CellularPower::QUECTEL_UG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
25+
{
26+
27+
}
28+
29+
QUECTEL_UG96_CellularPower::~QUECTEL_UG96_CellularPower()
30+
{
31+
32+
}
33+
34+
nsapi_error_t QUECTEL_UG96_CellularPower::on()
35+
{
36+
#if MODEM_ON_BOARD
37+
::onboard_modem_init();
38+
::onboard_modem_power_up();
39+
#endif
40+
return NSAPI_ERROR_OK;
41+
}
42+
43+
nsapi_error_t QUECTEL_UG96_CellularPower::off()
44+
{
45+
#if MODEM_ON_BOARD
46+
::onboard_modem_power_down();
47+
#endif
48+
return NSAPI_ERROR_OK;
49+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef QUECTEL_UG96_CELLULARPOWER_H_
19+
#define QUECTEL_UG96_CELLULARPOWER_H_
20+
21+
#include "AT_CellularPower.h"
22+
23+
namespace mbed {
24+
25+
class QUECTEL_UG96_CellularPower : public AT_CellularPower
26+
{
27+
public:
28+
QUECTEL_UG96_CellularPower(ATHandler &atHandler);
29+
virtual ~QUECTEL_UG96_CellularPower();
30+
31+
public: //from CellularPower
32+
33+
virtual nsapi_error_t on();
34+
35+
virtual nsapi_error_t off();
36+
};
37+
38+
} // namespace mbed
39+
40+
#endif // QUECTEL_UG96_CELLULARPOWER_H_

0 commit comments

Comments
 (0)