0

I am using Telit GL865 GSM Modem with STM32F7 nucleo development board. I make them communicate via USART1. Firstly, I configure the modem with AT commands as below; after that, modem starts to send LCP packages and since I cannot handle them, NO CARRIER message occurs at the end. What I am not sure is that am I applying the right AT commands since it is different than the link I am sharing: https://github.com/espressif/esp-idf/blob/master/examples/protocols/pppos_client/main/pppos_client_main.c

The second thing is, when I callpppos_create(&ppp_netif, output_cb, status_cb, 0), I observe that it actually does not call status_cb(ppp_pcb *pcb, int err_code, void *ctx).

main code and required callbacks:

/////////////////////////// Includes
#include "main.h"
#include "stm32f7xx_hal.h"
#include "lwip.h"
#include "usart.h"
#include "gpio.h"
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include "string.h"
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/timeouts.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/init.h"
#include "lwip/tcpip.h"
#include "lwip/netif.h"
#include "lwip/api.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/dns.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/etharp.h"
#include "netif/ethernet.h"
#include "lwip/apps/netbiosns.h"
#include "lwip/apps/httpd.h"
#include "netif/ppp/pppos.h"
#include "ppp/ppp.h"
#include "lwip/sio.h"
#include "netif/ppp/pppapi.h"
#include "netif/ppp/pppos.h"
#include "netif/ppp/pppoe.h"
#include "netif/ppp/ppp_opts.h"
///////////////////////////////////////////// ///End of Includes
void SystemClock_Config(void);
#define RX_SIZE 64
///////////////////////////////////////////////////////Variables
uint32_t sysTickCounter = 0;
uint8_t sendData[50] = "                    \n";
uint8_t recData;
uint8_t receivedValue, connected = 0;
uint32_t recIndex = 0;
uint8_t recBuffer[RX_SIZE];
uint8_t pppLinkStatusCallbackArray[RX_SIZE];
uint8_t sent,sendMeToPPPoS = 0;
ppp_pcb *ppp;
struct netif ppp_netif;
u8_t sio_idx = 0;
sio_fd_t ppp_sio;
uint8_t ATconnected,lcpCame,length = 0;
uint8_t lcpStartIndex, lcpStopIndex,lcpStartOld,lcpStart,lcpStop = 0;
////////////////////////////////////////////////////////////End of Variables

////////////////////////////////////////////////////////////PPP Functions
static void status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
//this function is never called; however, it must have been called in the main with ppp = pppos_create(&ppp_netif, output_cb, status_cb, 0); 
  struct netif *pppif = ppp_netif(pcb);
  LWIP_UNUSED_ARG(ctx);

  switch(err_code) {
    case PPPERR_NONE: {
      printf("status_cb: Connected\n");
      printf("   our_ipaddr  = %s\r\n", ipaddr_ntoa(&pppif->ip_addr));
      printf("   his_ipaddr  = %s\r\n", ipaddr_ntoa(&pppif->gw));
      printf("   netmask     = %s\r\n", ipaddr_ntoa(&pppif->netmask));
      connected = 1; //
      break;
    }
    case PPPERR_PARAM: {
      printf("status_cb: Invalid parameter\r\n");
      break;
    }
    case PPPERR_OPEN: {
      printf("status_cb: Unable to open PPP session\r\n");
      break;
    }
    case PPPERR_DEVICE: {
      printf("status_cb: Invalid I/O device for PPP\r\n");
      break;
    }
    case PPPERR_ALLOC: {
      printf("status_cb: Unable to allocate resources\r\n");
      break;
    }
    case PPPERR_USER: {
      ppp_free();
      printf("status_cb: User interrupt\r\n");
      break;
    }
    case PPPERR_CONNECT: {
      printf("status_cb: Connection lost\r\n");
      break;
    }
    case PPPERR_AUTHFAIL: {
      printf("status_cb: Failed authentication challenge\r\n");
      break;
    }
    case PPPERR_PROTOCOL: {
      printf("status_cb: Failed to meet protocol\r\n");
      break;
    }
    case PPPERR_PEERDEAD: {
      printf("status_cb: Connection timeout\r\n");
      break;
    }
    case PPPERR_IDLETIMEOUT: {
      printf("status_cb: Idle Timeout\r\n");
      break;
    }
    case PPPERR_CONNECTTIME: {
      printf("status_cb: Max connect time reached\r\n");
      break;
    }
    case PPPERR_LOOPBACK: {
      printf("status_cb: Loopback detected\r\n");
      break;
    }
    default: {
      printf("status_cb: Unknown error code %d\r\n", err_code);
      break;
    }
  }
  ppp_connect(pcb, 30);//Try to reconnect in 30 seconds
}

static u32_t output_cb(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx)
{
    //UART output callback for PPPoS
    return HAL_UART_Transmit_IT(&huart1, data, sizeof(data));
}
/////////////////////////////////////////////////////////End of PPP Functions

/////////////////////////////////////////////////////////////////////////Main
int main(void)
{
    HAL_Init();
    SystemClock_Config();
    MX_GPIO_Init();
    MX_USART1_UART_Init();
    MX_LWIP_Init();
    HAL_UART_Receive_IT(&huart1, &recData, 1);
    SysTick_Config(SystemCoreClock/1000); 

    HAL_Delay(300);//delay 300ms
    memset(recBuffer, 0, sizeof(recBuffer));//UART receive buffer
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT\r\n", strlen("AT\r\n"));//send this AT command over UART to GSM module
    HAL_Delay(300);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT&K0\r\n", strlen("AT&K0\r\n"));
    HAL_Delay(300);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT#SCFG=3,1,300,600,300,10\r\n", strlen("AT#SCFG=3,1,300,600,300,10\r\n"));
    HAL_Delay(300);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT+CGDCONT=1,\"IP\",\"mgbs\",\"0.0.0.0\",0,0\r\n", strlen("AT+CGDCONT=1,\"IP\",\"mgbs\",\"0.0.0.0\",0,0\r\n"));
    HAL_Delay(300);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT+CGSN\r\n", strlen("AT+CGSN\r\n"));
    HAL_Delay(300);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT#ICMP=2\r\n", strlen("AT#ICMP=2\r\n"));
    HAL_Delay(300);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT#GPPPCFG=\"000.000.000.000\",25,1\r\n", strlen("AT#GPPPCFG=\"000.000.000.000\",25,1\r\n"));
    HAL_Delay(300);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT#GPPPCFGEXT=0\r\n", strlen("AT#GPPPCFGEXT=0\r\n"));
    HAL_Delay(300);

    HAL_Delay(3000);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"AT#GAUTH=0\r\n", strlen("AT#GAUTH=0\r\n"));
    HAL_Delay(3000);

    HAL_Delay(300);
    memset(recBuffer, 0, sizeof(recBuffer));
    HAL_UART_Transmit_IT(&huart1, (uint8_t*)"ATDT*99#\r\n", strlen("AATDT*99#\r\n"));

    ppp = pppos_create(&ppp_netif, output_cb, status_cb, 0);
    ppp_set_auth(ppp, PPPAUTHTYPE_NONE, "", "");
    ppp_set_default(ppp);

    u16_t holdoff = 0;
    err_t err = ppp_connect(ppp, holdoff);
    while(err!=ERR_OK)
    {
        HAL_Delay(100);
    }

    while (1)
    {
    }
}

/////////////////////////////////////////////////////////////UART callbacks

//////////////Fill the buffer with UART data unless 300ms past
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
    if (UartHandle->Instance == USART1)
    {
        //HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);/* Toggle LED2 on: Transfer in reception process is correct */
        sysTickCounter = 0;//reset the timeout if data is received --> for more info, go to systick_handler
        HAL_UART_Receive_IT(&huart1, &recData, 1);
        if(recIndex >= RX_SIZE){
            recIndex = 0;
        }   
        recBuffer[recIndex++] = recData;
    }
}
/////////////////////////////////////////////End of UART callbacks

//////////////below; store the received LCP packages from UART buffer to pppos_input by 
//////////////dicriminating the LCP packages with starting and ending indicators 0x7E.
void SysTick_Handler(void)
{
    sysTickCounter++;
    if(sysTickCounter == 300){   //Check the UART buffer over 300ms
        sysTickCounter = 0;
        recIndex = 0;

        for (int i = 0; i < RX_SIZE; i++){
            if(recBuffer[i] == 0x7E){
                if(lcpStart == 0){
                    lcpStart = 1;
                }else if(lcpStart == 1){
                    lcpStart = 0;
                }
            }
            if(lcpStart == 1){
                lcpBuffer[lcpBufferIndex] = recBuffer[i];
                lcpBufferIndex++;
            }
            if(lcpStart == 0){
                if(lcpStartOld == 1){
                    quantityOfPackages++;

                    lcpBuffer[lcpBufferIndex] = 0x7E;
                    length = lcpBufferIndex;
                    lcpBufferIndex = 0;

                    pppos_input(ppp, lcpBuffer, length);
                    memset(recBuffer, 0, sizeof(recBuffer));
                    memset(lcpBuffer, 0, sizeof(lcpBuffer));
                }
            }
            lcpStartOld = lcpStart;
        }
    }
  HAL_IncTick();
  HAL_SYSTICK_IRQHandler();
}

I want the PPPoS handle the static IP assignment for LwIP. However, I could not even handle the LCP messages coming from the GSM Module since I could not properly create PPPoS via pppos_create(&ppp_netif, output_cb, status_cb, 0);.

what modem sends all including LCP is below:

AT
AT

OK

AT&K0
AT&K0

OK
AT#SCFG=3,1,300,600,300,10
AT#SCFG=3,1,300,600,300,10

OK
AT+CGDCONT=1,"IP","mgbs","0.0.0.0",0,0
AT+CGDCONT=1,"IP","mgbs","0.0.0.0",0,0

OK
AT+CGSN
AT+CGSN

356308046338494

OK
AT#ICMP=2
AT#ICMP=2

OK
AT#GPPPCFG="000.000.000.000",25,1
AT#GPPPCFG="000.000.000.000",25,1

OK
AT#GPPPCFGEXT=0
AT#GPPPCFGEXT=0

OK
ATD*99***1
ATD*99***1

NO CARRIER
ATDT*99#
ATDT*99#

CONNECT

~ÿ}#À!}!}!} }0}"}&} } } } }%}&þQ}-} z'~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&à[}-} ã9~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&Ôe}-} H‘~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&Ío}-} ðØ~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&½y}-} ùÑ~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&­ƒ}-} }6í~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&¡}-} 9j~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&š—}-} 1}0~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&¡¡}-} ¡Ì~
~ÿ}#À!}!}!} }0}"}&} } } } }%}&Ÿ«}-} k]~
~ÿ}#À!}%}!} }*} } } } } } }*ø~
~ÿ}#À!}%}!} }*} } } } } } }*ø~
~ÿ}#À!}%}!} }*} } } } } } }*ø~

NO CARRIER
  • The no carrier response from the modem is valid, just that it was unable to set up the data connection. You should check the response to check if they all respond OK, if not what do you want to happen? For example if the AT+CGDCONT failed because there are already contexts enable how are you going to handle that? – Dean May 11 '18 at 07:18
  • Sir, they all return OK, and the modem connects after `ATDT*99#`; however, `NO CARRIER` comes out after 13 LCP packages received. I think I cannot initiate pppos_create and, that's why pppos_input cannot handle/response LCP requests. I know how to assign static IP by using AT commands; however, my purpose is to do it with LCP negotiation over PPPoS. – Sarp Engin Daltaban May 11 '18 at 08:06
  • 1
    That's correct, I've seen the same happen when I was working on a modem over PPP. After `ATD...` it starts talking to you over PPP and you must establish a session. It looks somewhat like this: https://imgur.com/WNxJITc (Wireshark is pretty poor when it comes to packet direction for PPP). Here's the same from Quectel M66 PPP Application note: https://imgur.com/a/agNTSex. If MCU doesn't respond to any requests sent by the modem after `ATD...` it'll eventually stop trying and send `NO CARRIER`. As for static IP - I'm not sure if you can do that (it's likely enforced by the provider). – J_S May 11 '18 at 15:53
  • 1
    Further comment on the static, public IP - we've had a requirement at one point to have a static IP over GPRS network and to do that, we had to order a special SIM card from the provider. During IPCP negotiation this card always returned same IP which could be accessed from the public Internet (e.g. you could ping it). As for other cards - from my experience those are generally dynamic IP and are also behind provider's NAT. You can even deduce that from the IP SIM card returns during IPCP negotiation being from local IP range, e.g. 10.x.x.x. It'd be very helpful to have your transmission log. – J_S May 11 '18 at 15:58
  • @JacekŚlimok Thank you very much for replies and sorry for not replying as quick as you did. Firstly, I am sure that the mcu supports PPPoS(STM32F7 with stm cube and keil) and, we have the special SIM card that only static IP can be assigned. I can assign its IP over AT(SGACT 1,1...) commands. However, AT commands let the mcu set IP of GSM modem over internal TCP/IP stack and, my purpose is to make it by using LwIP PPPoS, which is the external stack. Therefore, as a start, I check the PPPoS status callback to see if mcu can reply the LCP packets that modem sends and it is never called.. – Sarp Engin Daltaban May 14 '18 at 05:51
  • `return HAL_UART_Transmit_IT(&huart1, data, sizeof(data));` - the use of `sizeof(data)` is an extremely serious mistake here and this code just cannot work correctly, as `sizeof(data)` is a constant expression in your case, equal to 4 bytes - this is the size of pointer, not the size of data (passed as `len`). Don't ignore warnings, as if you do, this is what you get. – Freddie Chopin Mar 12 '19 at 11:08

0 Answers0