[Top][All Lists]

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

Re: [lwip-users] ppp_new gprs

From: Sylvain Rochet
Subject: Re: [lwip-users] ppp_new gprs
Date: Mon, 3 Jun 2013 21:09:58 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

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.


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) {
  } 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", 
                        fprintf(stderr, "   his_ipaddr  = %s\n\r", 
                        fprintf(stderr, "   netmask     = %s\n\r", 
                        fprintf(stderr, "   dns1        = %s\n\r", 
                        fprintf(stderr, "   dns2        = %s\n\r", 
                        fprintf(stderr, "   our6_ipaddr = %s\n\r", 
                        fprintf(stderr, "   his6_ipaddr = %s\n\r", 
#endif /* PPP_IPV6_SUPPORT */

                default: {
                        fprintf(stderr, "ppp_link_status_cb: err code %d\n\r", 
                        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 */


> 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.


Attachment: signature.asc
Description: Digital signature

reply via email to

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