PPP, CMUX, ldattach on Raspberry Pi with M95

Hi!

I am using an M95 from Quectel on a Raspberry Pi 3.

I have been able to successfully get access to the modem via /dev/serial0 and can throw AT commands at it. I was able to follow up and get a PPP connection using standard chat scripts. Fixed the default route and there was internet!

The next challenge was to be able to access the modem for grabbing status etc whilst a PPP connection is active.

obviously the m95 only has a single serial port, so this isnt possible as the PPP connection has ownership of the serial conenction. Reading the M95 docs though, it does support CMUX, so in theory I should be able to enable cmux, then create virtual serial devices to keep the PPP connection active on one and send AT commands on the other. (as an aside - I note that I can also send an escape sequence ‘+++’ to the modem when in data mode to temporarily switch to command mode without dropping the connection, though I suspect this doesn’t work when PPP is in use - can anyone confirm or deny this?)

Playing with various settings, options and reading - I was not able to get ldattach to work, and I soon discovered from google that the n_gsm module was not in the standard kernel. I found this guide (https://github.com/guowenxue/embedded_project/tree/master/program/ldattach_gsm0701) and performed step 1

Choose follow option when do "make menuconfig" before cross compile linux kernel:
       Device Drivers  --->
           Character devices  --->
                  <*> GSM MUX line discipline support (EXPERIMENTAL)

then followed the standard kernel building process to build a new kernel with n_gsm; on reboot everything came up as expected.

I then compiled this project for a cmux controller https://github.com/Rtone/cmux which worked fine (though I did have to modify the code to point to /dev/serial0 and also changed the mtu for cmux to 127 from 512 as that is what the M95 supports) - this works great and on running it shows

...
Line dicipline set
Created /dev/ttyGSM1
Created /dev/ttyGSM2
Created /dev/ttyGSM3
Created /dev/ttyGSM4
Going to background

and I get the expected 4 ttyGSM devices.

Modifying my original Python script to point to /dev/ttyGSM1 (instead of /dev/serial0) I can send AT commands still

OK
AT+IFC=2, 2
OK
AT+GMM
Quectel_M95
OK

But I can’t for the life of me get my PPP connection to run any more - If i change the peers file to point to /dev/ttyGSM1 then I see the following

Nov 25 06:54:27 68imgw01 chat[865]: abort on (+CGATT: 0)
Nov 25 06:54:27 68imgw01 chat[865]: send (AT^M)
Nov 25 06:54:27 68imgw01 chat[865]: timeout set to 12 
seconds
Nov 25 06:54:27 68imgw01 chat[865]: expect (OK)
Nov 25 06:54:39 68imgw01 chat[865]: alarm
Nov 25 06:54:39 68imgw01 chat[865]: Failed
Nov 25 06:54:40 68imgw01 pppd[859]: Hangup (SIGHUP)

If I reboot and don’t run the cmux code, and try to pon a ppp connection (using /dev/serial0) it fails

Nov 25 06:55:51 68imgw01 chat[920]: send (AT^M)
Nov 25 06:55:51 68imgw01 chat[920]: timeout set to 12 seconds
Nov 25 06:55:51 68imgw01 chat[920]: expect (OK)
Nov 25 06:55:51 68imgw01 chat[920]: Failed
Nov 25 06:55:59 68imgw01 pppd[917]: Terminating on signal 15
Nov 25 06:55:59 68imgw01 pppd[917]: Exit.

given where the pon fails, at the first AT command, I suspect it is not able to communicate with the serial device, but I can’t work out why. After all when I run the cmux code which points at /dev/serial0 it works just fine, but on a fresh reboot pon doesn’t…

any help is appreciated!

I have referred a lot to this StackOverflow post (https://stackoverflow.com/questions/28939656/sending-at-commands-to-sim900-whilst-pppd-is-active) which is a very simillar approach and use case - it also references the above cmux project and kernel building guide