Legato platform service MDC - stop session problem

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?

I don’t see problem with WP85 on legato 16.10.1 on the modemdemo application.
Can you use le_data_Release()?

root@swi-mdm9x15:~# cat /legato/systems/current/appsWriteable/modemDemo_wp85/sms
Chat.txt

root@swi-mdm9x15:~#
root@swi-mdm9x15:~# app runProc modemDemo_wp85 send --exe=send – 1234567 “Onlin
e”
root@swi-mdm9x15:~#
root@swi-mdm9x15:~# [ 67.735510] NOHZ: local_softirq_pending 08
[ 67.815656] NOHZ: local_softirq_pending 08

root@swi-mdm9x15:~#
root@swi-mdm9x15:~# ifconfig
eth0 Link encap:Ethernet HWaddr E2:37:AB:42:35:72
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

rmnet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.73.199.134 Mask:255.255.255.252
inet6 addr: fe80::cf1b:86b2:984f:2a56/64 Scope:Link
UP RUNNING MTU:1430 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:612 (612.0 B) TX bytes:1192 (1.1 KiB)

usb0 Link encap:Ethernet HWaddr 06:98:B6:83:86:8A
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::498:b6ff:fe83:868a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:197 errors:0 dropped:4 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:29026 (28.3 KiB) TX bytes:1839 (1.7 KiB)

root@swi-mdm9x15:~#
root@swi-mdm9x15:~# cat /legato/systems/current/appsWriteable/modemDemo_wp85/sms
Chat.txt

Requesting data connection.

root@swi-mdm9x15:~#
root@swi-mdm9x15:~# cm data
Index: 1
APN: hkcsl
PDP Type: IPV4V6
Connected: yes

root@swi-mdm9x15:~#
root@swi-mdm9x15:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
[ 87.542682] NOHZ: local_softirq_pending 08
64 bytes from 8.8.8.8: seq=0 ttl=56 time=161.086 ms
^C
— 8.8.8.8 ping statistics —
4 packets transmitted, 1 packets received, 75% packet loss
round-trip min/avg/max = 161.086/161.086/161.086 ms
root@swi-mdm9x15:~# [ 90.685304] NOHZ: local_softirq_pending 08
root@swi-mdm9x15:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
[ 93.445780] NOHZ: local_softirq_pending 08
64 bytes from 8.8.8.8: seq=0 ttl=56 time=181.657 ms
[ 94.424202] NOHZ: local_softirq_pending 08
64 bytes from 8.8.8.8: seq=1 ttl=56 time=159.530 ms
^C
— 8.8.8.8 ping statistics —
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 159.530/170.593/181.657 ms
root@swi-mdm9x15:~# app runProc modemDemo_wp85 send --exe=send – 1234567 “Offli
ne”
root@swi-mdm9x15:~#
root@swi-mdm9x15:~# cm data
^C
root@swi-mdm9x15:~# cm data
Index: 1
APN: hkcsl
PDP Type: IPV4V6
Connected: no

root@swi-mdm9x15:~#
root@swi-mdm9x15:~#
root@swi-mdm9x15:~# legato version
16.10.1_a6a25fbda05738774857dccb9fd76a99_modified
root@swi-mdm9x15:~#
root@swi-mdm9x15:~# cm info
Device: WP8548
IMEI: 359377060004735
FSN: LL537500110203
Firmware: SWI9X15Y_07.11.22.00 r33729 CARMD-EV-FRMWR1 2017/01/11 18:04:06
Bootloader: SWI9X15Y_07.11.22.00 r33729 CARMD-EV-FRMWR1 2017/01/11 18:04:06
priIdPn: 9904889
priIdRev: 01.11
skuId: 1102621
root@swi-mdm9x15:~#

Hi, I don’t use le_data_Release() call, I using only Modem Data Control API:
https://docs.legato.io/16_10/c_mdc.html

It seems that I can also handle the connection on this layer.
I checked if instead of le_mdc_StartSession (profileRef) I call le_data_Request (), the session also starts and then le_mdc_StopSession works correctly.
The demo program you mention does not call le_mdc_StartSession (profileRef), it works on the Data Connection API layer.
All code examples in docs show that they call le_mdc_StartSession (profileRef) and then le_mdc_StopSession:
https://docs.legato.io/16_10/c_mdcDataProfiles.html
so it should work, but I have a problem with it.

Do you mean you must use le_mdc_StartSession()?

No, I don’t have to use le_mdc_StartSession().
I just get to know the Legato framework.
From what I can see, the correct practice is to use the Data Connection API, and use the Modem Data Control API only to configure the profile, although it would seem that the code I wrote should work properly.

OK, then please use le_data_Release() as it is proven to be working fine.

I’m a bit stubborn. I tested different versions of the code. It turns out that the call to the asynchronous function le_mdc_StopSessionAsync is working correctly. At the same time, I had to rebuild the code for full event driven. I suspect there was a problem here. Framework Legato works a bit differently than the classic process on Linux. It resembles the old OpenAT I used to use.