Sending AT commands to SIM900 whilst pppd is active

Okay I have almost solved this but stuck at the very last hurdle. Thought I would show what I have managed to do as it may help someone else.

I found this other post on stack overflow that lists 3 possible ways to achieve this. I didn't want to be controlling the gprs via AT commands when PPP (in my limited experience) handles this well and easily. The RPi only has one serial port so I couldn't multiplex over multiple serial interfaces.

So that left me with multiplexing over a single serial interface, let's hope the SIM900 supports this. I found here the User Manual on the SIM900 multiplexer which uses the GSM07.10 standard.

I couldn't find much information on how to set up multiplexing but eventually after digging around I found this document on an n_gsm module in the linux kernel. I can just about follow what it was talking about but not enough to write my own program to set up a number of virtual serial ports.

Thankfully after some more scouring of google I found that this extraordinary gentleman has created a C program to use the n_gsm module to set up the virtual serial ports for us.

I downloaded, configured and built the program as per the instructions and tried to load the n_gsm module. Unfortunately the RPi doesn't include the n_gsm module as default so I had to go and build a new kernel with n_gsm added as a module. I followed the instruction on the RPi website which are very good.

For the SIM900 I had to change line 322 to remove the &w of the end of the AT+IPR command. It should know look like:

if (send_at_command(serial_fd, "AT+IPR=115200\r") == -1) errx(EXIT_FAILURE, "AT+IPR=115200: bad response");

I also edited line 128 to sleep(1.5) before trying to read a response as it was sometimes returning an error because it hadn't got a response in time.

So I run the cmux program (with sudo as it needs to create the new /dev/ttyGSM* devices) and it runs through the AT commands, sets the line discipline and creates the new virtual serial devices but when I try and open a serial terminal with screen /dev/ttyGSM1 115200 screen just returns [screen is terminating].

I did sudo fuser /dev/ttyGSM1 which returned nothing so no other process is using it.

I then tried echo AT > /dev/ttyGSM1 which returned -bash: /dev/ttyGSM1: Level 2 halted.

I'm not sure what this is referring to and couldn't find any information on this message. Could it be talking about layer 2 of the OSI model a.k.a the data link layer?

Anyway this is how far I have got. I have decided to put it to one side for now and just use NTP but I hope this helps someone else out. If you do find a solution to this or can suggest something I may have missed please do say. Thanks