Getting started with PPPD on NuttX

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) then I enabled flow control in the NuttX config:

#
# USART Configuration
#

CONFIG_USART2_ISUART=y
CONFIG_USART6_ISUART=y
CONFIG_MCU_SERIAL=y
CONFIG_STANDARD_SERIAL=y
CONFIG_SERIAL_NPOLLWAITERS=2
CONFIG_SERIAL_IFLOWCONTROL=y
CONFIG_SERIAL_OFLOWCONTROL=y

Also I need to enable some other features:

CONFIG_CLOCK_MONOTONIC=y
CONFIG_NETDEVICES=y
CONFIG_NETDEV_MULTINIC=y
CONFIG_NETDEV_LATEINIT=y

#
# Device Drivers
#

# CONFIG_DISABLE_POLL is not set

#
# Networking Support
#
CONFIG_ARCH_HAVE_NET=y
CONFIG_NET=y

#
# Driver buffer configuration
#
CONFIG_NET_MULTIBUFFER=y
CONFIG_NET_ETH_MTU=590
CONFIG_NET_ETH_TCP_RECVWNDO=536
CONFIG_NET_TUN_MTU=296
CONFIG_NET_TUN_TCP_RECVWNDO=256
CONFIG_NET_GUARDSIZE=2

#
# Data link support
#
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

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

6 thoughts on “Getting started with PPPD on NuttX

  1. 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

      1. 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

  2. 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

  3. 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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s