lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] ppp_new gprs


From: Ahmed Fayek
Subject: Re: [lwip-users] ppp_new gprs
Date: Tue, 4 Jun 2013 10:52:23 -0700 (PDT)

Hi Sylvain,

thank you very much for your help.
I'll try that.

 just a question regarding 2nd part about sio.
In my application as I said I route data from ethernet.
do IP forwarding do the job automatically or I need to create TX thread and handle that some way.

Best Regards,
Ahmed

From: Sylvain Rochet <address@hidden>
To: address@hidden
Sent: Monday, June 3, 2013 9:09 PM
Subject: Re: [lwip-users] ppp_new gprs

Hi Ahmed,


On Sat, Jun 01, 2013 at 04:22:56AM -0700, Ahmed Fayek wrote:
> Hi,
>
> My application is a GPRS router that route data to/from eathernet
> interface and serial GPRS module usin ti stellaris LM3S6918.
>
> I try to use the ppp_new code, I need to know the sequence to start
> the pppos using the new functions. I am asking if there is an example
> project.

This is quite easy, ppp.h is well documented about that.

Basically:


ppp_pcb *ppps;
int fd;

fd = open_serial_port();

ppps = ppp_new();
ppp_set_auth(ppps, PPPAUTHTYPE_PAP, "login", "password");
ppp_over_serial_create(ppps, fd, ppp_link_status_cb, NULL);

your_chatscript(fd) {
  [ ... ]
  ppp_open(ppps, 0);
}

while(1) {
  u8_t buffer[128];
  int len;
  len = sio_read(fd, buffer, 128);
  if(len < 0) {
    pppapi_sighup(ppps);
  } else {
    pppos_input(ppps, buffer, len);
  }
}


You have to use pppapi_ functions if lwIP is already started, ppp_
functions are not thread safe.


Closing a running session:

ppp_close(ppps);  /* or pppapi_close(ppps);, as usual */
/* --- wait for callback, do NOT destroy the PPP PCB until PPP finished
* the cleaning job
*/


Dummy callback, called from the lwIP thread, should be non-blocking:

void ppp_link_status_cb(ppp_pcb *pcb, int err_code, void *ctx) {

    switch(err_code) {
        case PPPERR_NONE: {
            struct ppp_addrs *ppp_addrs = ppp_addrs(pcb);
            fprintf(stderr, "ppp_link_status_cb: PPPERR_NONE\n\r");
            fprintf(stderr, "  our_ipaddr  = %s\n\r", ip_ntoa(&ppp_addrs->our_ipaddr));
            fprintf(stderr, "  his_ipaddr  = %s\n\r", ip_ntoa(&ppp_addrs->his_ipaddr));
            fprintf(stderr, "  netmask    = %s\n\r", ip_ntoa(&ppp_addrs->netmask));
            fprintf(stderr, "  dns1        = %s\n\r", ip_ntoa(&ppp_addrs->dns1));
            fprintf(stderr, "  dns2        = %s\n\r", ip_ntoa(&ppp_addrs->dns2));
#if PPP_IPV6_SUPPORT
            fprintf(stderr, "  our6_ipaddr = %s\n\r", ip6addr_ntoa(&ppp_addrs->our6_ipaddr));
            fprintf(stderr, "  his6_ipaddr = %s\n\r", ip6addr_ntoa(&ppp_addrs->his6_ipaddr));
#endif /* PPP_IPV6_SUPPORT */
            break;
        }

        default: {
            fprintf(stderr, "ppp_link_status_cb: err code %d\n\r", err_code);
            restart_chatscript(pcb, 5);  /* Should trigger chatscript, in another thread for example, so that you are not locking the lwIP thread */

            /* You can also use ppp_delete() here */

            break;
        }
    }
}

> another question about sio.c specially reading data, what is the
> criteria to end reading? length or a certain character received? As I
> found an application dealing with fixed max. length data passed to
> sio_read()

In ppp-new branch, you have to call pppos_input() when you get new data
from your serial port. This function is thread safe and can be called
from a dedicated RX-thread or from a main-loop.


Sylvain
_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users


reply via email to

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