WIP and UDP

Hello,

I’m new with WIP library and I’m developing an application on Q2686 using UDP via GPRS. The system must connect and disconnect many times for day.
To check how WIP works I wrote this simple application, based on udp client example included in development system.
In this example with AT+GPRS=1 you can start GPRS and send UDP packets and receive them, AT+GPRS=0, close UDP channel and GPRS.

After I close (AT+GPRS=0) and then open again connection, I don’t receive any UDP packets but I can send… I close and open connection for about 4-5 times and I receive an error from WIP because the handle of created UDP channel is 0.
It looks like that the UDP channel’s never closed although I used wip_close() command before closing GPRS.
I tried to use a delay between wip_close and bearer_stop but no success.

I attach the code, hoping it can be useful and any advice is appreciate.

Thanx

Raff

void adl_main ( adl_InitType_e InitType )
{
  int r;

  TRACE (( 1, "Embedded Application : Main" ));

  /* Initialize the stack */
  r = wip_netInitOpts( 
      WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1, /* WIP traces on UART1 */
      //WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART2,
      //WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_TRACE,
      WIP_NET_OPT_END);

  cfg_gprs(appli_entry_point);
}

void cfg_gprs ( void (* entry_point)(void)) {
  appli_entry_point = entry_point;
  adl_simSubscribe( evh_sim, GPRS_PINCODE);
}

 void evh_bearer( wip_bearer_t b, s8 event, void *ctx) {
  	int tmr_handler;
	ascii IpAddr[16]; 
	wip_in_addr_t appIpAddr; 
	s8 ret;	
	ascii string[100];
	s8 bearer_ans;

	switch(event)
	{
		case WIP_BEV_IP_CONNECTED:
			adl_atSendResponse ( ADL_AT_UNS, "WIP: connected\r\n"); 
			wip_bearerGetOpts(b, WIP_BOPT_IP_ADDR, &appIpAddr, WIP_BOPT_END); //This API provides IP in network format (i.e u32 number) 
			wip_inet_ntoa(appIpAddr , IpAddr, 16); //This API converts the u32 IP address to a dotted notation IP address.

			wm_sprintf(string,"WIP: IP %s\r\n",IpAddr);
			adl_atSendResponse ( ADL_AT_UNS, string); 

			appli_entry_point();
			break;
		case WIP_BEV_IP_DISCONNECTED:
			adl_atSendResponse ( ADL_AT_UNS, "WIP: disconnesso\r\n"); 
			break;
		case WIP_BEV_CONN_FAILED:
			adl_atSendResponse ( ADL_AT_UNS, "WIP: WIP_BEV_CONN_FAILED\r\n"); 

			break;
		case WIP_BEV_STOPPED:
			adl_atSendResponse ( ADL_AT_UNS, "WIP: WIP_BEV_STOPPED\r\n"); 

			bearer_ans = wip_bearerClose(bearer_handle);		   
			
			break;
		default:
			adl_atSendResponse ( ADL_AT_UNS, "WIP: altri errori\r\n"); 
		   
			break;
	}
}

static void evh_sim( u8 event) {
  int r;

  if( ADL_SIM_EVENT_FULL_INIT != event) return;
  adl_atCmdSubscribe("AT+GPRS", GPRSCmdHandler, ADL_CMD_TYPE_PARA | 0x11); 
}

void GPRSCmdHandler(adl_atCmdPreParser_t *parser) 
{ 
   s8 returnValue; 
   char *parameter; 
   int startStop; 
  int r;
  wip_bearer_t b;
  s8 bearer_ans;
    
   parameter = wm_lstGetItem(parser->ParaList, 0); 
   startStop = atoi(parameter); 
   if (startStop == 1) 
   { 
	r = wip_bearerOpen( &bearer_handle, "GPRS", evh_bearer, NULL);
  
	r = wip_bearerSetOpts( bearer_handle, WIP_BOPT_GPRS_APN, GPRS_APN,
                         WIP_BOPT_LOGIN,       GPRS_USER,
                         WIP_BOPT_PASSWORD,    GPRS_PASSWORD,
                         WIP_BOPT_END);
	r = wip_bearerStart( bearer_handle);
   } 
   else 

   if (startStop == 0) 
   {
   adl_tmrUnSubscribe(tmr_handler,evh_timer,ADL_TMR_TYPE_100MS);
    wip_close(socket);
   bearer_ans = wip_bearerStop(&bearer_handle);
	} 
   else 
   { 
      adl_atSendResponse ( ADL_AT_RSP, "\r\nERROR\r\n" ); 
      return; 
   } 

   adl_atSendResponse ( ADL_AT_RSP, "\r\nOK\r\n" );    
}

static void evh_timer( u8 tmr_id) {
  wip_debug("write MESSAGE\n");
  wip_write( socket, MESSAGE, sizeof(MESSAGE));
}

static void evh_udp( wip_event_t *ev, void *ctx) {
  wip_in_addr_t addr;
  int nread;
  ascii string[100];
  ascii ipd[15]="";
  u16 port;
  u8 buffer [30];
  u16 len;
  

  switch( ev->kind) {

  case WIP_CEV_OPEN: 
    wip_debug( "[SAMPLE] UDP socket ready, starting the timer");
    tmr_handler = adl_tmrSubscribe( TRUE, 10*INTERVAL, 
                                    ADL_TMR_TYPE_100MS, evh_timer);
    break; 

  case WIP_CEV_READ: 

    wip_debug ("[SAMPLE] A datagram arrived\r\n");
	   nread = wip_readOpts( ev->channel, buffer, sizeof(buffer),
                          WIP_COPT_PEER_ADDR, & addr,
                          WIP_COPT_END);
		wip_inet_ntoa(addr , ipd, 16); //This API converts the u32 IP address to a dotted notation IP address.
		wm_sprintf(string,"[WIP] IP %s data %d\r\n",ipd,len);
		adl_atSendResponse ( ADL_AT_UNS, string); 

	   break;


  case WIP_CEV_ERROR:
    wip_debug( "[SAMPLE] Error %i on socket.\n", 
               ev->content.error.errnum);
    if( wip_getState( ev->channel) != WIP_CSTATE_READY) {
      wip_debug( "[SAMPLE] Error is fatal, closing\n");
      adl_tmrUnSubscribe( tmr_handler, evh_timer, ADL_TMR_TYPE_100MS);
      wip_close( ev->channel);
    }
    break;
  }
}

void appli_entry_point() {
  ascii string[100];
  socket = wip_UDPCreateOpts( evh_udp, NULL, 
                              WIP_COPT_PEER_STRADDR, PEER_STRADDR,
                              WIP_COPT_PEER_PORT,    PEER_PORT,
                              WIP_COPT_END);

  wm_sprintf(string,"[WIP] UDP handle 0x%x\r\n",socket);
adl_atSendResponse ( ADL_AT_UNS, string);   

}

Please provide OpenAT SDK version and firmware version as well.

OpenAT 4.20.03
Firmware 6.62_09gg
WIP 2.00.25

I have to add that the UDP channel state, after wip_close, retrieved by wip_getState is always 2 (WIP_CSTATE_TO_CLOSE).

Haven’t had time to look at your code so I can’t say if there’s any problems there.

But, you might want to ask your distributor for OpenAT 4.21 SDK (or newer if available)

OpenAT 4.20.04
Firmware 6.62
WIP 3.00.06

Thank you, I’ve upgraded SDK and the problem is the same. But I have something new. I noticed the problem is with DNS too.
So, if I put a numeric IP address as destination, I’m able to open UDP connection and to receive packets, than I close connection. The next times I open and close I can send packets but no receiving.
If I put a domain name as destination, it’s the same as before but after 3rd-4th times I receive this error

ERRLOG U:\projet\gsmmi\int\plu\serena\openat\WIP\src\ch_udp.c:491: DNS query synchronous error
ERRLOG U:\projet\gsmmi\int\plu\serena\openat\WIP\src\ch_udp.c:492: returned WIP_CERR_INVALID

and UDP socket handle is 0.

I also have lots of problems with DNS when connecting a client socket. I get WIP_CEV_ERROR when I try to connect. The first few connects work but once it starts failing it will continue to fail until a reset. I updated to the latest everything:

OpenAT 4.20.04
Firmware 6.62
WIP 3.00.06

but the problem remains. I’ve been having DNS problems since I started using WIP stack. This is very frustrating. I wish Wavecom would publish their test code so we (the users) could advise them how to construct more extensive regression test code. That way these problems would not be appear in every release.

Regards
Trevor