lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] ppp over serial using gsm modem getting config acknowle


From: Sylvain Rochet
Subject: Re: [lwip-users] ppp over serial using gsm modem getting config acknowledgement reject packet.
Date: Wed, 18 Feb 2015 16:28:17 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

Hello Rohan,


On Wed, Feb 18, 2015 at 06:56:35AM -0700, rohanm wrote:
> hii,
> i am trying to implement ppp over serial using lwip version 1.4.1 for our
> project.i am working on this from last 15 to 20 days.i have first
> initialized gsm modem SIM900D and dial using ATD*99# command and once it
> gets connected call below code .
> 
> 
> 
> 
>  tcpip_init(lwIPInit,NULL);
> xTaskCreate(vPPPApplication, "vPPPApplication", configMINIMAL_STACK_SIZE,
> NULL, tskIDLE_PRIORITY, NULL );

You should wait lwIP is initialised before starting vPPPApplication() 
which is calling pppapi_* functions, please use the tcp_init_done 
callback with a semaphore here, or start vPPPApplication() in 
lwIPInit().

You can also use non-thread safe functions in your lwIPInit(), this is 
always better than using heavyweight pppapi_ calls.


> i am confuse about gsm_init function call so i have made dummy function .
> err_t GSM_init( struct netif *pxNetIf )
> {
> 
>     return ERR_OK;
> }
> 
> 
> void lwIPInit( void *pvArgument )
> {
> 
> ip_addr_t xIPAddr, xNetMask, xGateway;
> static struct netif xNetIf;

Looks like you added static modifier here to prevent a hard fault 
instead of understanding why you should do that :-)


> 
>       ( void ) pvArgument;
> 
>       SysConfigGetLocalIPAddress(&ipAddr1, &ipAddr2, &ipAddr3, &ipAddr4);
> 
> //     Set up the network interface.
>       ip_addr_set_zero( &xGateway );
>       ip_addr_set_zero( &xIPAddr );
>       ip_addr_set_zero( &xNetMask );
> 
>       LWIP_PORT_INIT_GW(&xGateway);
>       LWIP_PORT_INIT_IPADDR(&xIPAddr);
>       LWIP_PORT_INIT_NETMASK(&xNetMask);
> 
>       netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway,
> NULL,GSM_init, tcpip_input ) );//ethernetif_init
>       netif_set_up( &xNetIf );

xNetIf is not your PPPoS interface, the PPP code you are using is still 
using an internal netif. Note that master HEAD is now using a user 
provided netif for PPP, which should prevent the confusion you are 
having.


> 
> }
> 
> vPPPApplication code is as follows:
> 
> u8_t buffer[PPPOS_RX_BUFSIZE];
>     
> void vPPPApplication(void)
> {
>   ppp_pcb *ppps;
>   char *username = "test";
>   char *password = "test";
> 
>   int connected = 0;
>   int pd;
> 
>   ppps = pppapi_new();
> 
>   /* set the method of authentication. Use PPPAUTHTYPE_PAP, or
>    * PPPAUTHTYPE_CHAP for more security .
>    * If this is not called, the default is PPPAUTHTYPE_NONE.
>    */
>   pppapi_set_auth(ppps, PPPAUTHTYPE_NONE, username,
> password);//PPPAUTHTYPE_PAP
> 
>   pppapi_over_serial_create(ppps, 0, linkStatusCB, NULL);

The serial port 0 here is confusing, but I guess this is ok, you
probably need to check the stack is able to handle a nul serial fd :-)


> 
>   pppapi_open(ppps, 0);
>   while(1)
>   {
>     int len;
>     memset(ppp_rcvbuffer,0,sizeof(ppp_rcvbuffer));

zeroing the recv buffer is stupid here.


>     len = sio_read(0, ppp_rcvbuffer, PPPOS_RX_BUFSIZE);
>     if(len <= 0) {
>           vTaskDelay(10/portTICK_RATE_MS);

Oh god, please make sio_read() blocking or timeouting after a while 
without rx data in your port.


>     } else {
>       pppos_input(ppps, ppp_rcvbuffer, len);
>     }
> 
>   }
> }
> 
> 
> u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
> {
> #if 1
>     int ret;
>     u8_t* Rec_Buf1 = (u8_t*)data;
>     unsigned int Val = 0;
>     u32_t k = 0;
>     // latch the Queue count
>     Val = UART_Queue[GSM_QUEUE].QCount;
>     //        Total = Total + Val;
>     for(k=0;k<Val;k++){
>         // cannot copy more than the input buffer size
>         if(k >= len){
>                 break;
>         }
>         Rec_Buf1[k] =
> UART_Queue[GSM_QUEUE].QBuf[UART_Queue[GSM_QUEUE].QGet];
> //    Print_Byte(ptr_Rec->Rec_Buf[i]);
>         UART_Queue[GSM_QUEUE].QGet++;
>         if(UART_Queue[GSM_QUEUE].QGet >= MAX_SERIAL_Q_SIZE){
>                 UART_Queue[GSM_QUEUE].QGet = 0;
>         }
>     }
>     //RM
> fd=(sio_fd_t)UART_Queue[GSM_QUEUE].QBuf[UART_Queue[GSM_QUEUE].QGet];
>     //No of bytes read = i;
>     if(k > 0){
>         // the count value should not be changed during decrementing it's
> value as below
>         // the count value is expected to change only when there is some
> data entry - serial port
>         // therefore the interrupt is disabled which will not allow the
> serial port to read the data
>         // and hence the count will not be SET
> 
>         // TBD : user enter critical section
>         INTDisableInterrupts();
>     //                DisableSerialInterrupt2();
>         UART_Queue[GSM_QUEUE].QCount -= k;
>         // after decrement, again enable the interrupts to receive the data
> from serial port
>         INTEnableInterrupts();
>     ///               EnableSerialInterrupt2();
>   }
>     return k;//RM For testing
> #endif
> }
> 
> linkStatusCB code ...
> void linkStatusCB(void *arg, int errCode, void *ctx)
> {
>    
>    int *connected = (int *) ctx;
> 
>    struct ppp_addrs *addrs = arg;
> 
> 
>    if (errCode == PPPERR_NONE) {
>        /* We are connected */
>        *connected = 1;
> 
>    } else {
>        switch(errCode)
>        {
>                
>            case PPPERR_PARAM:
> 
> 
>            break;
>            case PPPERR_OPEN:
>            break;
>            case PPPERR_DEVICE:
>            break;
>            case PPPERR_ALLOC:
>            break;
>            case PPPERR_USER:
>            break;
>            case PPPERR_CONNECT:
>            break;
>            case PPPERR_AUTHFAIL:
>            break;
>            case PPPERR_PROTOCOL:
>            break;
> 
> 
> 
>        }
>       
> 
>    }
> }
> 
> using this code i have  getting Config reject packet continuously.
> is there any thing wrong with the code or i need to do some initlaization
> before calling tcp thread and ppp serial thread.or there is any thing wrong
> with gsm modem dialing.??


Please enable debug trace support in lwiP, then add/change the following 
in your lwipopts.h:

#define PPP_DEBUG LWIP_DBG_ON
#define PRINTPKT_SUPPORT 1
#define PPP_PROTOCOLNAME 1

Then send the full PPP trace here.


Sylvain

Attachment: signature.asc
Description: Digital signature


reply via email to

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