Hello,
I’m testing a simple connection program, in general everything works fine, but I have a problem with terminating the connection (stopping the session). The le_mdc_StopSession function always returns LE_BAD_PARAMETER.
I’m using Legato from official Sierra website without custom changes (16.10.1.m3) and terminal FX30S.
Test code below:
#include "legato.h"
#include "interfaces.h"
#include "le_print.h"
// *********************************************************************************************************
void set_network_parameters(le_mdc_ProfileRef_t profileRef)
{
char ipAddr1[64] = {0};
char ipAddr2[64] = {0};
char cmd[LINE_MAX];
mode_t oldMask;
FILE* resolvFilePtr;
sleep(5);
// set default gateway
le_mdc_GetIPv4GatewayAddress(profileRef, ipAddr1, sizeof(ipAddr1));
snprintf(cmd, sizeof(cmd), "/sbin/route add default gw %s", ipAddr1);
LE_INFO("set default gateway %s\n", ipAddr1);
system(cmd);
// set dns
le_mdc_GetIPv4DNSAddresses(profileRef, ipAddr1, sizeof(ipAddr1), ipAddr2, sizeof(ipAddr2));
LE_INFO("set dns %s, %s\n", ipAddr1, ipAddr2);
// allow fopen to create file with mode=644
oldMask = umask(022);
// open the resolver configuration
resolvFilePtr = fopen("/etc/resolv.conf", "w+");
if (resolvFilePtr)
{
if (strlen(ipAddr1))
{
fprintf(resolvFilePtr, "nameserver %s\n", ipAddr1);
}
if (strlen(ipAddr2))
{
fprintf(resolvFilePtr, "nameserver %s\n", ipAddr2);
}
fclose(resolvFilePtr);
}
// restore old mask
umask(oldMask);
}
// *********************************************************************************************************
void ping_target_host(void)
{
char cmd[LINE_MAX];
sprintf(cmd, "ping %s -c 4", "8.8.8.8");
if (system(cmd) == 0)
{
// ping ok
LE_INFO("ping ok\n");
}
else
{
// ping fail
LE_INFO("ping fail\n");
}
}
// *********************************************************************************************************
COMPONENT_INIT
{
le_sim_Id_t simId;
le_sim_States_t simState;
le_mdc_ProfileRef_t profileRef = NULL;
simId = le_sim_GetSelectedCard();
profileRef = le_mdc_GetProfile(1);
while (1)
{
simState = le_sim_GetState(simId);
if (simState == LE_SIM_INSERTED)
{
le_result_t result;
LE_INFO("SIM inserted and locked\n");
result = le_sim_EnterPIN(simId, "3769");
if (result == LE_BAD_PARAMETER)
{
LE_INFO("The parameters are invalid\n");
break;
}
else if (result == LE_NOT_FOUND)
{
LE_INFO("The function failed to select the SIM card for this operation\n");
break;
}
else if (result == LE_UNDERFLOW)
{
LE_INFO("The PIN code is not long enough (min 4 digits)\n");
break;
}
else if (result == LE_FAULT)
{
LE_INFO("Failed to enter the PIN code\n");
break;
}
else if (result == LE_OK)
{
LE_INFO("PIN ok\n");
continue;
}
}
else if (simState == LE_SIM_ABSENT)
{
LE_INFO("SIM absent\n");
break;
}
else if (simState == LE_SIM_READY)
{
le_mdc_ConState_t sessionState;
le_mdc_GetSessionState(profileRef, &sessionState);
if (sessionState == LE_MDC_CONNECTED)
{
set_network_parameters(profileRef);
ping_target_host();
le_result_t result;
result = le_mdc_StopSession(profileRef);
if (result == LE_OK)
{
LE_INFO("stop session ok\n");
}
else if (result == LE_BAD_PARAMETER)
{
LE_INFO("stop session bad parameter\n");
}
else if (result == LE_FAULT)
{
LE_INFO("stop session fault\n");
}
break;
}
else if (sessionState == LE_MDC_DISCONNECTED)
{
if (le_mdc_SetPDP(profileRef, LE_MDC_PDP_IPV4) == LE_OK)
{
if (le_mdc_SetAPN(profileRef, "eradata") == LE_OK)
{
LE_INFO("start connection\n");
le_mdc_StartSession(profileRef);
sleep(1);
continue;
}
else
{
LE_INFO("set apn error\n");
break;
}
}
else
{
LE_INFO("set pdp error\n");
break;
}
}
else
{
sleep(1);
continue;
}
}
else if (simState == LE_SIM_BLOCKED)
{
LE_INFO("sim blocked\n");
break;
}
else if (simState == LE_SIM_BUSY)
{
LE_INFO("sim busy\n");
sleep(1);
continue;
}
else if (simState == LE_SIM_STATE_UNKNOWN)
{
LE_INFO("sim unknown state\n");
sleep(1);
continue;
}
}
LE_INFO("stopped\n");
}
// *********************************************************************************************************
Log:
root@fx30s:~# logread | grep air
Jan 6 00:00:26 fx30s user.info Legato: INFO | supervisor[516]/supervisor T=main | proc.c proc_Start() 1190 | Starting process 'air' with pid 577
Jan 6 00:00:26 fx30s user.info Legato: INFO | supervisor[577]/supervisor T=main | proc.c proc_Start() 1155 | Execing 'air'
Jan 6 00:00:31 fx30s user.info Legato: INFO | air[577]/air T=main | air.c _air_COMPONENT_INIT() 95 | SIM inserted and locked
Jan 6 00:00:31 fx30s user.info Legato: INFO | air[577]/air T=main | air.c _air_COMPONENT_INIT() 121 | PIN ok
Jan 6 00:00:32 fx30s user.info Legato: INFO | air[577]/air T=main | air.c _air_COMPONENT_INIT() 168 | start connection
Jan 6 00:00:33 fx30s user.info Legato: INFO | avcDaemon[564]/avcDaemon T=main | assetData.c assetData_CreateInstanceById() 2982 | Creating asset instance for air/0
Jan 6 00:00:33 fx30s user.info Legato: INFO | avcDaemon[564]/avcDaemon T=main | assetData.c assetData_CreateInstanceById() 3079 | Finished creating instance 0 for air/0
Jan 6 00:00:33 fx30s user.info Legato: INFO | avcDaemon[564]/avcDaemon T=main | assetData.c assetData_CreateInstanceById() 2982 | Creating asset instance for air/1
Jan 6 00:00:33 fx30s user.info Legato: INFO | avcDaemon[564]/avcDaemon T=main | assetData.c assetData_CreateInstanceById() 3079 | Finished creating instance 0 for air/1
May 11 06:40:34 fx30s user.info Legato: INFO | air[577]/air T=main | air.c set_network_parameters() 21 | set default gateway 178.***********
May 11 06:40:34 fx30s user.info Legato: INFO | air[577]/air T=main | air.c set_network_parameters() 26 | set dns 213.158.199.1, 213.158.199.5
May 11 06:40:35 fx30s user.info Legato: INFO | air[577] | PING 8.8.8.8 (8.8.8.8): 56 data bytes 64 bytes from 8.8.8.8: seq=0 ttl=57 time=1356.447 ms
May 11 06:40:35 fx30s user.info Legato: INFO | air[577] | 64 bytes from 8.8.8.8: seq=1 ttl=57 time=645.292 ms
May 11 06:40:36 fx30s user.info Legato: INFO | air[577] | 64 bytes from 8.8.8.8: seq=2 ttl=57 time=364.657 ms
May 11 06:40:37 fx30s user.info Legato: INFO | air[577] | 64 bytes from 8.8.8.8: seq=3 ttl=57 time=353.853 ms
May 11 06:40:37 fx30s user.info Legato: INFO | air[577] | --- 8.8.8.8 ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max = 353.853/680.062/1356.447 ms
May 11 06:40:37 fx30s user.info Legato: INFO | air[577]/air T=main | air.c ping_target_host() 66 | ping ok
May 11 06:40:37 fx30s user.info Legato: INFO | air[577]/air T=main | air.c _air_COMPONENT_INIT() 153 | stop session bad parameter
May 11 06:40:37 fx30s user.info Legato: INFO | air[577]/air T=main | air.c _air_COMPONENT_INIT() 219 | stopped
fulllog between le_mdc_StopSession calls:
May 11 06:40:37 fx30s user.info Legato: INFO | air[577]/air T=main | air.c ping_target_host() 66 | ping ok
May 11 06:40:37 fx30s user.err Legato: =ERR= | modemDaemon[571]/le_pa T=main | pa_mdc_qmi.c pa_mdc_StopSession() 2809 | Bad input parameter
May 11 06:40:37 fx30s user.info Legato: INFO | air[577]/air T=main | air.c _air_COMPONENT_INIT() 153 | stop session bad parameter
May 11 06:40:37 fx30s user.info Legato: INFO | air[577]/air T=main | air.c _air_COMPONENT_INIT() 219 | stopped
I don’t know why I can’t stop the session. Am I doing everything right?