lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Why LCP negotiation over PPPoS session doesn't start via LW


From: sarp
Subject: [lwip-users] Why LCP negotiation over PPPoS session doesn't start via LWIP, between STM32F7 and Telit GL865 GSM Modem?
Date: Thu, 10 May 2018 08:17:58 -0700 (MST)

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



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]