Skip to content

Commit 84f01d3

Browse files
author
Cruz Monrreal
authored
Merge pull request #9261 from tz-arm/merge_quectel_m26
Initial version for Quectel M26 GSM/GPRS Module.
2 parents bfc4646 + bf08cf7 commit 84f01d3

12 files changed

+1090
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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_M26_CellularNetwork.h"
19+
#include "QUECTEL_M26_CellularPower.h"
20+
#include "QUECTEL_M26_CellularSIM.h"
21+
#include "QUECTEL_M26_CellularContext.h"
22+
#include "QUECTEL_M26.h"
23+
24+
using namespace events;
25+
using namespace mbed;
26+
27+
#define CONNECT_DELIM "\r\n"
28+
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
29+
#define CONNECT_TIMEOUT 8000
30+
31+
#define MAX_STARTUP_TRIALS 5
32+
#define MAX_RESET_TRIALS 5
33+
34+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
35+
AT_CellularBase::AT_CGSN_WITH_TYPE,
36+
AT_CellularBase::AT_CGAUTH,
37+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
38+
};
39+
40+
QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh)
41+
{
42+
AT_CellularBase::set_unsupported_features(unsupported_features);
43+
}
44+
45+
QUECTEL_M26::~QUECTEL_M26()
46+
{
47+
}
48+
49+
AT_CellularNetwork *QUECTEL_M26::open_network_impl(ATHandler &at)
50+
{
51+
return new QUECTEL_M26_CellularNetwork(at);
52+
}
53+
54+
AT_CellularPower *QUECTEL_M26::open_power_impl(ATHandler &at)
55+
{
56+
return new QUECTEL_M26_CellularPower(at);
57+
}
58+
59+
AT_CellularSIM *QUECTEL_M26::open_sim_impl(ATHandler &at)
60+
{
61+
return new QUECTEL_M26_CellularSIM(at);
62+
}
63+
64+
AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn)
65+
{
66+
return new QUECTEL_M26_CellularContext(at, this, apn);
67+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_M26_H_
19+
#define QUECTEL_M26_H_
20+
21+
#include "AT_CellularDevice.h"
22+
23+
namespace mbed {
24+
25+
class QUECTEL_M26 : public AT_CellularDevice {
26+
public:
27+
QUECTEL_M26(FileHandle *fh);
28+
virtual ~QUECTEL_M26();
29+
30+
protected: // AT_CellularDevice
31+
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
32+
virtual AT_CellularPower *open_power_impl(ATHandler &at);
33+
virtual AT_CellularSIM *open_sim_impl(ATHandler &at);
34+
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
35+
36+
public: // NetworkInterface
37+
void handle_urc(FileHandle *fh);
38+
};
39+
} // namespace mbed
40+
41+
#endif // QUECTEL_M26_H_
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
#include "QUECTEL_M26_CellularContext.h"
18+
#include "QUECTEL_M26_CellularStack.h"
19+
20+
namespace mbed {
21+
22+
QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
23+
AT_CellularContext(at, device, apn)
24+
{
25+
}
26+
27+
QUECTEL_M26_CellularContext::~QUECTEL_M26_CellularContext()
28+
{
29+
}
30+
31+
bool QUECTEL_M26_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
32+
{
33+
return stack_type == IPV4_STACK ? true : false;
34+
}
35+
36+
#if !NSAPI_PPP_AVAILABLE
37+
NetworkStack *QUECTEL_M26_CellularContext::get_stack()
38+
{
39+
if (!_stack) {
40+
_stack = new QUECTEL_M26_CellularStack(_at, _cid, _ip_stack_type);
41+
}
42+
return _stack;
43+
}
44+
#endif // #if !NSAPI_PPP_AVAILABLE
45+
46+
nsapi_error_t QUECTEL_M26_CellularContext::do_user_authentication()
47+
{
48+
49+
_at.cmd_start("AT+QICSGP=");
50+
_at.write_int(1); /*GPRS MODE = 1, CSD MODE = 0*/
51+
_at.write_string(_apn);
52+
if (_pwd && _uname) {
53+
_at.write_string(_uname);
54+
_at.write_string(_pwd);
55+
}
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+
return NSAPI_ERROR_OK;
64+
}
65+
66+
} /* namespace mbed */
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
#ifndef QUECTEL_M26_CELLULARCONTEXT_H_
18+
#define QUECTEL_M26_CELLULARCONTEXT_H_
19+
20+
#include "AT_CellularContext.h"
21+
22+
namespace mbed {
23+
24+
class QUECTEL_M26_CellularContext: public AT_CellularContext {
25+
public:
26+
QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
27+
virtual ~QUECTEL_M26_CellularContext();
28+
29+
protected:
30+
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type);
31+
#if !NSAPI_PPP_AVAILABLE
32+
virtual NetworkStack *get_stack();
33+
#endif // #if !NSAPI_PPP_AVAILABLE
34+
virtual nsapi_error_t do_user_authentication();
35+
};
36+
37+
} /* namespace mbed */
38+
39+
#endif // QUECTEL_M26_CELLULARCONTEXT_H_
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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_M26_CellularNetwork.h"
19+
20+
using namespace mbed;
21+
22+
QUECTEL_M26_CellularNetwork::QUECTEL_M26_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
23+
{
24+
_op_act = RAT_EGPRS;
25+
}
26+
27+
QUECTEL_M26_CellularNetwork::~QUECTEL_M26_CellularNetwork()
28+
{
29+
}
30+
31+
AT_CellularNetwork::RegistrationMode QUECTEL_M26_CellularNetwork::has_registration(RegistrationType reg_type)
32+
{
33+
return (reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable;
34+
}
35+
36+
nsapi_error_t QUECTEL_M26_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
37+
{
38+
if (opRat != RAT_EGPRS) {
39+
// only GPRS support in the driver.
40+
_op_act = RAT_EGPRS;
41+
return NSAPI_ERROR_UNSUPPORTED;
42+
}
43+
44+
return NSAPI_ERROR_OK;
45+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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_M26_CELLULAR_NETWORK_H_
19+
#define QUECTEL_M26_CELLULAR_NETWORK_H_
20+
21+
#include "AT_CellularNetwork.h"
22+
23+
namespace mbed {
24+
25+
class QUECTEL_M26_CellularNetwork : public AT_CellularNetwork {
26+
public:
27+
QUECTEL_M26_CellularNetwork(ATHandler &atHandler);
28+
virtual ~QUECTEL_M26_CellularNetwork();
29+
30+
protected:
31+
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
32+
virtual RegistrationMode has_registration(RegistrationType reg_type);
33+
};
34+
} // namespace mbed
35+
#endif // QUECTEL_M26_CELLULAR_NETWORK_H_
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_M26_CellularPower.h"
19+
20+
using namespace mbed;
21+
22+
QUECTEL_M26_CellularPower::QUECTEL_M26_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
23+
{
24+
25+
}
26+
27+
QUECTEL_M26_CellularPower::~QUECTEL_M26_CellularPower()
28+
{
29+
30+
}
31+
32+
nsapi_error_t QUECTEL_M26_CellularPower::set_at_mode()
33+
{
34+
_at.lock();
35+
_at.cmd_start("AT");
36+
_at.cmd_stop_read_resp();
37+
38+
_at.cmd_start("AT+CMEE="); // verbose responses
39+
_at.write_int(1);
40+
_at.cmd_stop_read_resp();
41+
42+
return _at.unlock_return_error();
43+
}
44+
45+
nsapi_error_t QUECTEL_M26_CellularPower::on()
46+
{
47+
48+
return NSAPI_ERROR_OK;
49+
}
50+
51+
nsapi_error_t QUECTEL_M26_CellularPower::off()
52+
{
53+
_at.lock();
54+
_at.cmd_start("AT+QPOWD=0");
55+
_at.cmd_stop();
56+
_at.resp_start();
57+
_at.resp_stop();
58+
59+
return _at.unlock_return_error();;
60+
}

0 commit comments

Comments
 (0)