NuttX has PPP support to GSM/3G modems, then I decided to test it with UBlox Leon-G100 modem. As you can see on my previous post I was testing the SmartG100 board on Linux to verify if GSM modem is working, because it is working I can follow with NuttX test.
I connected the Leon-G100 to USART2: TX (PD5), RX (PD6), CTS (PD3) and RTS (PD4)
I used this NuttX default config:
CONFIG_ARCH="arm" CONFIG_ARCH_BOARD="stm32f4discovery" CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y CONFIG_ARCH_BUTTONS=y CONFIG_ARCH_CHIP_STM32F407VG=y CONFIG_ARCH_CHIP_STM32=y # CONFIG_ARCH_FPU is not set CONFIG_ARCH_STACKDUMP=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y CONFIG_CLOCK_MONOTONIC=y CONFIG_DEBUG_ERROR=y CONFIG_DEBUG_FEATURES=y CONFIG_DEBUG_INFO=y CONFIG_DEBUG_WARN=y CONFIG_EXAMPLES_NSH=y CONFIG_EXAMPLES_PPPD=y CONFIG_FS_PROCFS=y CONFIG_INTELHEX_BINARY=y CONFIG_MAX_TASKS=16 CONFIG_MAX_WDOGPARMS=2 CONFIG_MM_REGIONS=2 CONFIG_NETDEVICES=y CONFIG_NETDEV_LATEINIT=y CONFIG_NET_ICMP=y CONFIG_NET_UDP=y CONFIG_NETUTILS_PPPD_PAP=y CONFIG_NETUTILS_PPPD=y CONFIG_NET=y CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 # CONFIG_NSH_ARGCAT is not set CONFIG_NSH_BUILTIN_APPS=y # CONFIG_NSH_CMDOPT_HEXDUMP is not set # CONFIG_NSH_CMDPARMS is not set CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_LINELEN=64 CONFIG_NSH_READLINE=y CONFIG_PREALLOC_MQ_MSGS=4 CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_WDOGS=16 CONFIG_RAM_SIZE=114688 CONFIG_RAM_START=0x20000000 CONFIG_RAW_BINARY=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_LPWORK=y CONFIG_SCHED_WAITPID=y CONFIG_SDCLONE_DISABLE=y CONFIG_START_DAY=6 CONFIG_START_MONTH=12 CONFIG_START_YEAR=2011 CONFIG_STM32_JTAG_SW_ENABLE=y CONFIG_STM32_OTGFS=y CONFIG_STM32_PWR=y CONFIG_STM32_SPI1=y CONFIG_STM32_USART2=y CONFIG_STM32_USART3=y CONFIG_USART2_BAUD=19200 CONFIG_USART2_IFLOWCONTROL=y CONFIG_USART2_OFLOWCONTROL=y CONFIG_USART2_RXBUFSIZE=128 CONFIG_USART2_TXBUFSIZE=128 CONFIG_USART3_SERIAL_CONSOLE=y CONFIG_USER_ENTRYPOINT="nsh_main"
After compiling and flashing the firmware I tested it:
NuttShell (NSH) nsh> pppd tun fd:3 tty fd:4 ipcp init AHDLC_TX - transmit frame, protocol 0xc021, length 4 offline 0 0x05 0x01 0x00 0x04 AHDLC_TX - transmit frame, protocol 0xc021, length 4 offline 1 0x05 0x02 0x00 0x04 chat: char = ~ (0x7E) chat: char = � (0xFF) chat: char = } (0x7D) chat: char = ' (0x27) chat: char = � (0xC4) chat: char = % (0x25) chat: char = } (0x7D) chat: char = % (0x25) chat: char = } (0x7D) chat: char = % (0x25) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = = (0x3D) chat: char = � (0xC7) chat: char = ~ (0x7E) chat: char = ~ (0x7E) chat: char = � (0xFF) chat: char = } (0x7D) chat: char = ' (0x27) chat: char = � (0xC4) chat: char = % (0x25) chat: char = } (0x7D) chat: char = % (0x25) chat: char = } (0x7D) chat: char = & (0x26) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = ] (0x5D) chat: char = , (0x2C) chat: char = ~ (0x7E) chat: char = + (0x2B) chat: char = / (0x2F) chat: char = / (0x2F) chat: char = A (0x41) chat: char = T (0x54) chat: char = E (0x45) chat: char = 1 (0x31) (0x0D)har = chat: char = up_assert: Assertion failed at file:armv7-m/up_hardfault.c line: 183 up_dumpstate: sp: 10001b70 up_dumpstate: stack base: 10001d30 up_dumpstate: stack size: 000007e4 up_stackdump: 10001b60: 08000ea9 080129b8 08012938 000007e4 08000ea9 080129b8 08012938 000007e4 up_stackdump: 10001b80: 08000ea9 080129b8 08012938 000007e4 00000000 08000e0b 20002840 080019bb up_stackdump: 10001ba0: 08012afc 08000c81 00000000 3e656d61 08013c7e 00000000 08013c8b 0800047f up_stackdump: 10001bc0: 10001c08 00000000 3e656d61 08013c7e 00000000 08013c8b 10001c50 10001c84 up_stackdump: 10001be0: 00000000 00000000 3e656d61 00000073 3e656d61 3e656d62 10001c28 080032c9 up_stackdump: 10001c00: 08002c30 01000000 080010fd 00000000 10001c68 10001c3c 00000000 00000000 up_stackdump: 10001c20: 20002854 08001e09 ffffffff 100012e4 08013c7e 10001c84 10001d40 10001d3c up_stackdump: 10001c40: 00000000 00000001 00000000 0800f0c9 0800f0e5 0800f0dd 0000000c 100012e4 up_stackdump: 10001c60: 08013c7e 00000004 d3ff7700 0800ebd7 08013c7e 10001c84 3e656d61 08008fdd up_stackdump: 10001c80: 08013c7e 3e656d61 00007fff 00000000 00000004 0a001d3c 10001d60 00000004 up_stackdump: 10001ca0: 10001d00 10001d00 00000000 00000000 00000000 08008c6f 10001d60 00000004 up_stackdump: 10001cc0: 00000000 08008e55 00000003 00000000 00000001 00000000 00000004 00000000 up_stackdump: 10001ce0: 8768ca01 16f7c8df 10001d10 08013ba4 00000000 00000000 00000000 08008bd3 up_stackdump: 10001d00: 7665642f 7974742f 00003153 00000000 200000e8 200000d4 00000000 00000000 up_stackdump: 10001d20: 00000000 08001d81 00000000 00000000 07ac4948 10001d3c 00000000 6e6f6e3c up_registerdump: R0: 3e656d61 00000073 3e656d61 3e656d62 3e656d61 08013c7e 00000000 08013c8b up_registerdump: R8: 10001c50 10001c84 00000000 00000000 10001c28 10001c08 080032c9 08002c30 up_registerdump: xPSR: 01000000 PRIMASK: 00000000 CONTROL: 00000000
Too bad, it crashed!
Looking at PC15 position (0x08002c30) at System.map file I noticed it was crashing at “strlen” function.
Immediately the pap_username and pap_password variables came to my mind.
Then I opened “apps/examples/pppd/pppd_main.c” and noticed there is not an initialization to pap_username and pap_password, I added it:
@@ -87,6 +88,8 @@ int pppd_main(int argc, char *argv[]) .disconnect_script = &disconnect_script, .connect_script = &connect_script, .ttyname = "/dev/ttyS2", + .pap_username = "tim", + .pap_password = "tim", }; return pppd(&pppd_settings); }
But the compiler said it don’t know about pap_username and pap_password, after inspecting “apps/include/netutils/pppd.h” I noticed it depends on NETUTILS_PPPD_PAP to include them to struct. Then I enabled the “PPP PAP Authentication Support” in the NuttX menu config.
This time “pppd” worked as expected:
nsh> pppd tun fd:3 tty fd:4 ipcp init AHDLC_TX - transmit frame, protocol 0xc021, length 4 offline 0 0x05 0x01 0x00 0x04 AHDLC_TX - transmit frame, protocol 0xc021, length 4 offline 1 0x05 0x02 0x00 0x04 chat: char = ~ (0x7E) chat: char = � (0xFF) chat: char = } (0x7D) chat: char = ' (0x27) chat: char = � (0xC4) chat: char = % (0x25) chat: char = } (0x7D) chat: char = % (0x25) chat: char = } (0x7D) chat: char = % (0x25) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = = (0x3D) chat: char = � (0xC7) chat: char = ~ (0x7E) chat: char = ~ (0x7E) chat: char = � (0xFF) chat: char = } (0x7D) chat: char = ' (0x27) chat: char = � (0xC4) chat: char = % (0x25) chat: char = } (0x7D) chat: char = % (0x25) chat: char = } (0x7D) chat: char = & (0x26) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = } (0x7D) chat: char = $ (0x24) chat: char = ] (0x5D) chat: char = , (0x2C) chat: char = ~ (0x7E) chat: char = + (0x2B) chat: char = / (0x2F) chat: char = / (0x2F) chat: char = A (0x41) chat: char = T (0x54) chat: char = E (0x45) chat: char = 1 (0x31) (0x0D)har = (0x0D)har = chat: char = (0x0A) chat: char = O (0x4F) chat: char = K (0x4B) (0x0D)har = chat: char = (0x0A) chat: send 'ATZ` chat: char = A (0x41) chat: char = T (0x54) chat: char = Z (0x5A) chat: wait for 'OK` (0x0D)har = (0x0D)har = chat: char = (0x0A) chat: char = O (0x4F) chat: char = K (0x4B) chat: got it! (0x0D)har = chat: char = (0x0A) chat: send 'AT` chat: char = A (0x41) chat: char = T (0x54) chat: wait for 'OK` (0x0D)har = (0x0D)har = chat: char = (0x0A) chat: char = O (0x4F) chat: char = K (0x4B) chat: got it! (0x0D)har = chat: char = (0x0A) chat: send 'AT+IFC=0,0` chat: char = A (0x41) chat: char = T (0x54) chat: char = + (0x2B) chat: char = I (0x49) chat: char = F (0x46) chat: char = C (0x43) chat: char = = (0x3D) chat: char = 0 (0x30) chat: char = , (0x2C) chat: char = 0 (0x30) chat: wait for 'OK` (0x0D)har = (0x0D)har = chat: char = (0x0A) chat: char = O (0x4F) chat: char = K (0x4B) chat: got it! (0x0D)har = chat: char = (0x0A) chat: send 'AT+CGDCONT = 1,"IP","tim.br"` chat: char = A (0x41) chat: char = T (0x54) chat: char = + (0x2B) chat: char = C (0x43) chat: char = G (0x47) chat: char = D (0x44) chat: char = C (0x43) chat: char = O (0x4F) chat: char = N (0x4E) chat: char = T (0x54) chat: char = (0x20) chat: char = = (0x3D) chat: char = (0x20) chat: char = 1 (0x31) chat: char = , (0x2C) chat: char = " (0x22) chat: char = I (0x49) chat: char = P (0x50) chat: char = " (0x22) chat: char = , (0x2C) chat: char = " (0x22) chat: char = t (0x74) chat: char = i (0x69) chat: char = m (0x6D) chat: char = . (0x2E) chat: char = b (0x62) chat: char = r (0x72) chat: char = " (0x22) chat: wait for 'OK` (0x0D)har = (0x0D)har = chat: char = (0x0A) chat: char = O (0x4F) chat: char = K (0x4B) chat: got it! (0x0D)har = chat: char = (0x0A) chat: send 'ATD*99***1#` chat: char = A (0x41) chat: char = T (0x54) chat: char = D (0x44) chat: char = * (0x2A) chat: char = 9 (0x39) chat: char = 9 (0x39) chat: char = * (0x2A) chat: char = * (0x2A) chat: char = * (0x2A) chat: char = 1 (0x31) chat: char = # (0x23) chat: wait for 'CONNECT` (0x0D)har = (0x0D)har = chat: char = (0x0A) chat: char = C (0x43) chat: char = O (0x4F) chat: char = N (0x4E) chat: char = N (0x4E) chat: char = E (0x45) chat: char = C (0x43) chat: char = T (0x54) chat: got it! ipcp init ipcp init Sending LCP request packet - len 10 AHDLC_TX - transmit frame, protocol 0xc021, length 10 offline 0 0x01 0x00 0x00 0x0a 0x02 0x06 0xff 0xff 0xff 0xff Receiving packet with good crc value, len 24 0x01 0x01 0x00 0x14 0x02 0x06 0x00 0x00 0x00 0x00 0x05 0x06 0xed 0xb6 0x5b 0x05 0x07 0x02 0x08 0x02 LCP Packet - ipcp init received [LCP Config Request id 1 Send ACK! Writing ACK frame AHDLC_TX - transmit frame, protocol 0xc021, length 20 offline 1 0x02 0x01 0x00 0x14 0x02 0x06 0x00 0x00 0x00 0x00 0x05 0x06 0xed 0xb6 0x5b 0x05 0x07 0x02 0x08 0x02 - end ACK Write frame Receiving packet with good crc value, len 14 0x02 0x00 0x00 0x0a 0x02 0x06 0xff 0xff 0xff 0xff LCP Packet - LCP-ACK - >>>>>>>> good ACK id up! 0 **Sending IPCP Request packet AHDLC_TX - transmit frame, protocol 0x8021, length 10 offline 0 0x01 0x00 0x00 0x0a 0x03 0x06 0x00 0x00 0x00 0x00 Receiving packet with good crc value, len 14 0x01 0x01 0x00 0x0a 0x03 0x06 0xb3 0x4e 0xef 0x1a IPCP Packet - IPCP len 10 check lcplist IPCP options are good Peer IP Send IPCP ACK! SET- stuff -- are we up? c=10 dif=2 Writing ACK frame AHDLC_TX - transmit frame, protocol 0x8021, length 10 offline 1 0x02 0x01 0x00 0x0a 0x03 0x06 0xb3 0x4e 0xef 0x1a - End ACK Write frame Receiving packet with good crc value, len 14 0x03 0x00 0x00 0x0a 0x03 0x06 0xb3 0x4e 0xef 0x1a IPCP Packet - IPCP len 10 CONF NAK **Sending IPCP Request packet AHDLC_TX - transmit frame, protocol 0x8021, length 10 offline 0 0x01 0x01 0x00 0x0a 0x03 0x06 0xb3 0x4e 0xef 0x1a Receiving packet with good crc value, len 14 0x02 0x01 0x00 0x0a 0x03 0x06 0xb3 0x4e 0xef 0x1a IPCP Packet - IPCP len 10 CONF ACK were up! len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x01 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x01 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x02 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x02 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x03 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x03 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x04 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x04 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x05 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x05 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x06 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x06 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x07 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x07 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x08 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x08 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x09 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x09 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x0a 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x0a 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x0b 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x0b 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY len 8 Writing ECHO-REQUEST frame AHDLC_TX - transmit frame, protocol 0xc021, length 8 offline 0 0x09 0x0c 0x00 0x08 0x00 0x00 0x00 0x00 - end ECHO-REQUEST Write frame Receiving packet with good crc value, len 12 0x0a 0x0c 0x00 0x08 0xed 0xb6 0x5b 0x05 LCP Packet - LCP-ECHO REPLY
Now let see the IP we got:
nsh> ifconfig tun0 Link encap:TUN at UP inet addr:100.96.114.232 DRaddr:100.96.114.232 Mask:0.0.0.0
Hello Acassis,
Thank you for your nice post.. I have got this up and running but the problem is that the pppd app has taken over the nsh shell. How do you configure the app to release the nsh?
Thank you.
Geoff
Hi Geoffrey,
Just execute this way:
nsh> pppd &
BR,
Alan
HI Alan,
Thanks that worked. I created a client socket on nuttx and successfully connected to a server. however I am only able to write data once then the program is stuck to in a continuous loop printing “read from tun : 49” the data is received by the server while the number 49 varies depending on the length of data sent in this case 9 bytes. Before getting into this loop I noticed that ppp chat is restarted. I am using sim900 modem
Geoff
Hi Geoffrey,
I am fighting this same issue. I supposed everything was fine and today when I create a connection to traccar server to send tracking positions I got stuck with this issue.
I can transmit few packages putting a delay after connect() and before send() and increasing the AHDLC_TX_OFFLINE to 500 ou even put it as 0 (never timeout until the int overflow).
When I got it working I will let you know. BR, Alan
Hi Geoffrey,
I found an ugly workaround, but it is working!
Just put a delay 3 seconds after the ppp_send, this way the ACK will return before TCP try to send a new package:
apps/netutils/pppd/pppd.c
ctx->ip_len = ret;
ppp_send(ctx);
ctx->ip_len = 0;
+ sleep(3); /* wait 3s */
}
}
I hope it helps you!
Hi Alan,
Yes! the workaround around is working. My connection seems to be solid with a delay of approx. 800 ms.
Thank you,
Geoff
Hi Acassis,
These configuration is not there in nuttx, so how to do this.
/*****************************************************************/
CONFIG_NET_MULTILINK=y
# CONFIG_NET_USER_DEVFMT is not set
CONFIG_NET_ETHERNET=y
# CONFIG_NET_LOOPBACK is not set
CONFIG_NET_TUN=y
CONFIG_TUN_NINTERFACES=1
#
# Internet Protocol Selection
#
CONFIG_NET_IPv4=y
# CONFIG_NET_IPv6 is not set
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_ICMP=y
CONFIG_NET_ARP=y
CONFIG_EXAMPLES_NSH=y
CONFIG_EXAMPLES_PPPD=y
CONFIG_NETUTILS_NETLIB=y
CONFIG_NETUTILS_PPPD=y
CONFIG_NETUTILS_PPPD_STACKSIZE=2048
CONFIG_NETUTILS_PPPD_PAP=y
These CONFIG_ are dependent from other configurations be enabled, just like it work in the Linux kernel as well.
You need to enable first the Network Support, and then you press “/” inside the menuconfig and search for the CONFIG_name_that_you_want. It will return the information about this config and will show what is “depends on”, then you need to enable first the symbol needed by this config. I hope this tips help you. BR, Alan
Thanks acassis,
Its working fine.
hi Acassis,
i getting one problem in that after few sec it is getting disconnect and again it is trying to connect.
read from tun :44
AHDLC_TX – transmit frame, protocol 0x0021, length 44 offline 6
AHDLC_TX to many outstanding TX packets => ppp_reconnect()
AHDLC_TX – transmit frame, protocol 0xc021, length 4 offline 0
0x05 0x02 0x00 0x04
Hi Raj,
I have no idea why you connection is dropping. You need to debug to discover what is going on. Probably the modem is finding some issue. BR, Alan
Hi assis,
We did as per your instructions,and we are connected with PPPD.But not able to ping any ip addrss,its getting connection timed out.As well as we are not able to get the dr adress in ifconfig.
draddress is 0.0.0.0.
Manualy i tried to change its getiing same issue.
help me thanks in advance.
Hi Selva,
What modem are you using?
I think it is caused by some configuration missing. Could you please subscribe to NuttX google group and post it there, then more people could help to solve this issue. Please send an email with more information as you can share.
Hello All,
I wanted test PPPD on RX65N.
Can I test using some virtual Linux modem instead of actual hardware modem?
Regards,
Surya
Hi Surya,
I never used the virtual modem, but if it emulates a GSM modem with the default AT command over UART (USB/Serial 3.3V), I think it could work.
I discovered that tcpser could be used to emulate modem on Linux: https://manned.org/tcpser/e8754729