Skip to content

Commit

Permalink
Linux change only: add PPP support. (#1117)
Browse files Browse the repository at this point in the history
Support for PPP connectivity via a cellular module is now added to the Linux platform.
  • Loading branch information
RobMeades committed Mar 15, 2024
1 parent dc6bd40 commit f62f008
Show file tree
Hide file tree
Showing 19 changed files with 2,094 additions and 50 deletions.
5 changes: 5 additions & 0 deletions cell/api/u_cell_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ typedef struct {
* then it cannot also be used for CellTime and hence an error may be
* returned if cellTimeOnly is set to false.
*
* If you have compiled with U_CFG_PPP_ENABLE then calling this function,
* which necessarily disconnects from the network, will disconnect PPP
* and it will not be re-enabled until a new network connection is made,
* e.g. by calling uCellNetConnect().
*
* @param cellHandle the handle of the cellular instance.
* @param mode the mode that CellTime should operate in,
* must be one of #U_CELL_TIME_MODE_PULSE,
Expand Down
8 changes: 8 additions & 0 deletions cell/src/u_cell_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,14 @@ int32_t uCellPrivateCFunGet(const uCellPrivateInstance_t *pInstance);
* uCellPrivateCFunMode() can be called subseqently to put it
* back again.
*
* Note: if you are calling this with a mode that powers the
* module down (e.g. 0 or 4) then make sure that the calling
* function calls uPortPppDisconnect(), _before_ it locks the
* cellular API mutex, in order to bring any PPP connections
* down first; must be before the API mutex is locked as the
* process of bringing down a PPP connection will call into the
* cellular API.
*
* @param pInstance pointer to the cellular instance.
* @return the previous mode or negative error code.
*/
Expand Down
2 changes: 2 additions & 0 deletions cell/src/u_cell_pwr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,8 @@ static int32_t moduleConfigure(uCellPrivateInstance_t *pInstance,
uPortTaskBlock(1000);
}
uAtClientLock(atHandle);
// This can sometimes take a little longer than the norm
uAtClientTimeoutSet(atHandle, 15000);
uAtClientCommandStart(atHandle, "AT+CFUN=");
uAtClientWriteInt(atHandle,
pInstance->pModule->radioOffCfun);
Expand Down
7 changes: 7 additions & 0 deletions cell/src/u_cell_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "u_port_os.h"
#include "u_port_heap.h"
#include "u_port_uart.h"
#include "u_port_ppp.h"

#include "u_time.h"

Expand Down Expand Up @@ -684,6 +685,12 @@ int32_t uCellTimeSyncCellEnable(uDeviceHandle_t cellHandle,

if (gUCellPrivateMutex != NULL) {

// Since this function requires the normal radio
// operation of the module to be disabled, take any
// PPP connection down first (since we can't do so
// while the cellular API mutex is locked)
uPortPppDisconnect(cellHandle);

U_PORT_MUTEX_LOCK(gUCellPrivateMutex);

errorCode = (int32_t) U_ERROR_COMMON_INVALID_PARAMETER;
Expand Down
15 changes: 12 additions & 3 deletions common/security/test/u_security_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ static uNetworkTestList_t *pStdPreamble()
{
uNetworkTestList_t *pList;

// In case a previous test failed
uNetworkTestCleanUp();

U_PORT_TEST_ASSERT(uPortInit() == 0);
U_PORT_TEST_ASSERT(uDeviceInit() == 0);

Expand Down Expand Up @@ -262,6 +259,10 @@ U_PORT_TEST_FUNCTION("[security]", "securitySeal")
// Close the devices once more and free the list
for (uNetworkTestList_t *pTmp = pList; pTmp != NULL; pTmp = pTmp->pNext) {
if (*pTmp->pDevHandle != NULL) {
U_TEST_PRINT_LINE("taking down %s...",
gpUNetworkTestTypeName[pTmp->networkType]);
U_PORT_TEST_ASSERT(uNetworkInterfaceDown(*pTmp->pDevHandle,
pTmp->networkType) == 0);
U_TEST_PRINT_LINE("closing device %s...",
gpUNetworkTestDeviceTypeName[pTmp->pDeviceCfg->deviceType]);
U_PORT_TEST_ASSERT(uDeviceClose(*pTmp->pDevHandle, false) == 0);
Expand Down Expand Up @@ -400,6 +401,10 @@ U_PORT_TEST_FUNCTION("[security]", "securityPskGeneration")
// Close the devices once more and free the list
for (uNetworkTestList_t *pTmp = pList; pTmp != NULL; pTmp = pTmp->pNext) {
if (*pTmp->pDevHandle != NULL) {
U_TEST_PRINT_LINE("taking down %s...",
gpUNetworkTestTypeName[pTmp->networkType]);
U_PORT_TEST_ASSERT(uNetworkInterfaceDown(*pTmp->pDevHandle,
pTmp->networkType) == 0);
U_TEST_PRINT_LINE("closing device %s...",
gpUNetworkTestDeviceTypeName[pTmp->pDeviceCfg->deviceType]);
U_PORT_TEST_ASSERT(uDeviceClose(*pTmp->pDevHandle, false) == 0);
Expand Down Expand Up @@ -526,6 +531,10 @@ U_PORT_TEST_FUNCTION("[security]", "securityZtp")
// Close the devices once more and free the list
for (uNetworkTestList_t *pTmp = pList; pTmp != NULL; pTmp = pTmp->pNext) {
if (*pTmp->pDevHandle != NULL) {
U_TEST_PRINT_LINE("taking down %s...",
gpUNetworkTestTypeName[pTmp->networkType]);
U_PORT_TEST_ASSERT(uNetworkInterfaceDown(*pTmp->pDevHandle,
pTmp->networkType) == 0);
U_TEST_PRINT_LINE("closing device %s...",
gpUNetworkTestDeviceTypeName[pTmp->pDeviceCfg->deviceType]);
U_PORT_TEST_ASSERT(uDeviceClose(*pTmp->pDevHandle, false) == 0);
Expand Down
3 changes: 1 addition & 2 deletions example/sockets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ For the remainder of the \#defines (see "Using A xxx Module" below) you may eith
Follow the instructions in the [port/platform/arduino](/port/platform/arduino) directory to create the Arduino library version of `ubxlib`, which will include the example here.

# Using A Cellular Module

`U_CFG_TEST_CELL_MODULE_TYPE`: consult [u_cell_module_type.h](/cell/api/u_cell_module_type.h) to determine the type name for the cellular module you intend to use. For instance, to use SARA-R5 you would set `U_CFG_TEST_CELL_MODULE_TYPE` to `U_CELL_MODULE_TYPE_SARA_R5`.

`U_CFG_APP_PIN_CELL_xxx`: the default values for the MCU pins connecting your cellular module to your MCU are \#defined in the file [port/platform](/port/platform)`/<platform>/mcu/<mcu>/cfg/cfg_app_platform_specific.h`. You should check if these are correct for your board and, if not, override the values of the \#defines (where -1 means "not connected").
Expand All @@ -31,7 +30,6 @@ Follow the instructions in the [port/platform/arduino](/port/platform/arduino) d
Obviously you will need a SIM in your board, an antenna connected and you may need to know the APN associated with the SIM (though accepting the network default often works).

# Using A Wi-Fi Module

`U_CFG_TEST_SHORT_RANGE_MODULE_TYPE`: consult [u_short_range_module_type.h](/common/short_range/api/u_short_range_module_type.h) to determine the type name for the short range module module you intend to use. For instance, to use NINA-W13 you would set `U_CFG_TEST_SHORT_RANGE_MODULE_TYPE` to `U_SHORT_RANGE_MODULE_TYPE_NINA_W13`.

`U_CFG_APP_PIN_SHORT_RANGE_xxx`: the default values for the MCU pins connecting your short range module to your MCU are \#defined in the file [port/platform](/port/platform)`/<platform>/mcu/<mcu>/cfg/cfg_app_platform_specific.h`. You should check if these are correct for your board and, if not, override the values of the \#defines (where -1 means "not connected").
Expand All @@ -43,6 +41,7 @@ On the following platforms:

- [ESP-IDF](/port/platform/esp-idf)
- [Zephyr](/port/platform/zephyr)
- [Linux](/port/platform/linux)

...and with following \[cellular\] modules:

Expand Down
Loading

0 comments on commit f62f008

Please sign in to comment.