wip_bearerOpen returning WIP_BERR_BAD_STATE

Hi Guys,

I’m having some trouble connecting to a GPRS bearer using the WIP v5.1 plug-in.

Device: Q2687
Firmware: R74_00gg

M2M Studio 1.0
Build Version 1.0.2.200903311200

I’ve disabled the PIN code request on the SIM card used and have also tested that GPRS is enable by the service provider (was able to browse the net if I use the SIM in a USB 3G modem).

When I try to Open the bearer error code -28 is returned. “WIP_BERR_BAD_STATE - The bearer is not stopped” according to documentation (Open AT® IP Connectivity Development Guide (WIPlib v5.10)).

I then try to stop the bearer using the wip_bearerStop function. Error code -24 “WIP_BERR_BAD_HDL - Invalid handle” is returned. This I expect because the handle “myBearer” hasn’t been used before (first run of the program after download / restart).

I based my program on the “Examples of Application - 15.1 Initializing a GPRS Bearer” in the above mentioned documentation.

/* -------- */
/* Includes */
/* -------- */

#include "adl_global.h"
#include "keyboard.h"
#include "adl_ctx.h"
#include "keypad_control"
#include "wip_bearer.h"

/* --------- */
/* Constants */
/* --------- */




/* --------- */
/* Variables */
/* --------- */

u8 key_TraceLevel = 17; // Keyboard Library


/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024*3;


/***************************************************************************/

/* bearer events handler */
void myHandler( wip_bearer_t br, s8 event, void *context)
{
	TRACE (( 3, "In myHandler " ));

  switch( event)
  {
    case WIP_BEV_IP_CONNECTED:
      /*IP connectivity we can start IP application from here*/
    	TRACE (( 3, "WIP_BEV_IP_CONNECTED - IP connectivity we can start IP application from here" ));
    break;
    case WIP_BEV_IP_DISCONNECTED:
      /*stop IP application*/
    	TRACE (( 3, "WIP_BEV_IP_DISCONNECTED - Stop IP Application" ));
    break;
      /* other events: */
    default:
      /*cannot start bearer: report error to higher levels*/
    	TRACE (( 3, "DEFAULT - cannot start bearer: report error to higher levels" ));
    break;
  }
}

/* bearer handle */
wip_bearer_t myBearer;

/* Initialise and start GPRS bearer */
bool myConnectToGPRS( void)
{
	s8 bearerOpenReturn;
	s8 bearerStopReturn;
	s8 bearerCloseReturn;

	bearerOpenReturn = wip_bearerOpen( &myBearer, "GPRS", myHandler, NULL);

	TRACE (( 3, "bearerOpenReturn %d", bearerOpenReturn ));

	 /* if bearer is in bad state, close and retry */
	  if(  bearerOpenReturn == -28)
	  {
		bearerStopReturn = wip_bearerStop( myBearer);

	    /* cannot open bearer */
		TRACE (( 3, "Bearer is not stopped. Stop Bearer 'myBearer'" ));
		switch (bearerStopReturn)
		{
			case 0:
				TRACE (( 3, "Bearer 'myBearer' stopped successfully" ));
			break;
			default:
				TRACE (( 3, "bearerStopReturn %d", bearerStopReturn ));
			break;
		}

		TRACE (( 3, "Bearer is not stopped. Close Bearer 'myBearer'" ));
		bearerCloseReturn = wip_bearerClose( myBearer);

		switch (bearerCloseReturn)
		{
			case 0:
				TRACE (( 3, "Bearer 'myBearer' closed successfully" ));
			break;
			default:
				TRACE (( 3, "bearerCloseReturn %d", bearerOpenReturn ));
			break;
		}

		TRACE (( 3, "Wait 2seconds..." ));
		adl_ctxSleep(5 * 1000 / 18.5 );

		TRACE (( 3, "Retry Opening Bearer" ));
		bearerOpenReturn = wip_bearerOpen( &myBearer, "GPRS", myHandler, NULL);
	  }

	  TRACE (( 3, "bearerOpenReturn %d", bearerOpenReturn ));

  /* open bearer and install our event handler */
  if(  bearerOpenReturn != 0)
  {
    /* cannot open bearer */
	TRACE (( 3, "Cannot Open Bearer" ));
    return FALSE;
  }

  /* configure GPRS interface */
  TRACE (( 3, "Configure GPRS Interface" ));
  if( wip_bearerSetOpts ( myBearer,
								  WIP_BOPT_GPRS_APN, "internet",
								  WIP_BOPT_LOGIN, "",
								  WIP_BOPT_PASSWORD, "",
								  WIP_BOPT_END) != 0)
  {
    /* cannot configure bearer */
	TRACE (( 3, "Cannot Configure Bearer" ));
    wip_bearerClose( myBearer);
    return FALSE;
  }

  /* start connection */
  TRACE (( 3, "Start Connection" ));
  if( wip_bearerStart( myBearer) != 0)
  {
    /* cannot start bearer */
	TRACE (( 3, "Cannot Start Bearer" ));
    wip_bearerClose( myBearer);
    return FALSE;
  }

  /* connection status will be reported to the event handler */
  return TRUE;
}




/***************************************************************************/
/*  Function   : adl_main                                                  */
/*-------------------------------------------------------------------------*/
/*  Object     : Customer ADL application initialisation                   */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  adlInitType       |   |   |   |  Application starting mode             */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
   TRACE (( 1, "Waiting 10 sec. before start the application...." ));
   adl_ctxSleep(10 * 1000 / 18.5 );


	/* DTMF Keyboard test application */
    TRACE (( 1, "DTMF Keyboard sample main" ));
    TRACE (( 1, __DATE__ ));
    TRACE (( 1, __TIME__ ));

	/* Subscribe to Keyboard service */
    TRACE (( 1, "Subscribe to Keyboard Service" ));
    key_Subscribe ( dk_KeyboardHandler, 0, 0 );

    /* Call function to subscribe to GPRS Bearer */
    TRACE (( 1, "Call GPRS Subscribe Function" ));
    myConnectToGPRS();
}

TRACE logs

09/08/02,03:41:05:421	ADL	1	Binary header at 00260000
09/08/02,03:41:05:500	ADL	1	Waiting 10 sec. before start the application....
09/08/02,03:41:14:890	ADL	1	DTMF Keyboard sample main
09/08/02,03:41:14:890	ADL	1	Aug  2 2009
09/08/02,03:41:14:890	ADL	1	15:36:21
09/08/02,03:41:14:890	ADL	1	Subscribe to Keyboard Service
09/08/02,03:41:14:906	ADL	1	Call GPRS Subscribe Function
09/08/02,03:41:14:906	ADL	3	bearerOpenReturn -28
09/08/02,03:41:14:906	ADL	3	Bearer is not stopped. Stop Bearer 'myBearer'
09/08/02,03:41:14:921	ADL	3	bearerStopReturn -24
09/08/02,03:41:14:921	ADL	3	Bearer is not stopped. Close Bearer 'myBearer'
09/08/02,03:41:14:921	ADL	3	bearerCloseReturn -28
09/08/02,03:41:14:937	ADL	3	Wait 2seconds...
09/08/02,03:41:19:843	ADL	3	Retry Opening Bearer
09/08/02,03:41:19:843	ADL	3	bearerOpenReturn -28
09/08/02,03:41:19:843	ADL	3	Cannot Open Bearer

Any suggestions would be appreciated!

Thanks in advance guys!

Stef

Where is your call to wip_netInit :question:

Hi Awneil,

Thanks! I missed that, after including the wip_netInit call I’m on my way again :slight_smile:

Error -35 (WIP_BERR_PIN_NOT_READY) is being returned by wip_bearerStart. SIM card has PIN disabled.

Read in a post that I still have to wait for ADL_SIM_EVENT_FULL_INIT event from adl_simSubscribe before attempting wip_bearerOpen; even if PIN is disabled (which makes sense I suppose).

Will give that a try.

Thanks again for the help!

Stef

I think the fact that wip_bearerOpen can return WIP_BERR_BAD_STATE is undocumented?

Noted here: viewtopic.php?f=23&t=3803

Yes, it does - you cannot perform any GSM- or GPRS- related operation before the SIM is fully initialised!

However, note that it is possible for the application to miss the ADL_SIM_EVENT_FULL_INIT event - especially in RTE mode - so you should include a timeout in your wait…

viewtopic.php?f=44&t=3677&p=14242&hilit=ADL_SIM_EVENT_FULL_INIT#p14242

Note also that the PIN_OK and FULL_INIT events can be received in either order: viewtopic.php?f=44&t=931&p=3330&hilit=FULL_INIT#p3330

Hiya,

I’ve got an outstanding issue with Wavecom about WIP initialization in a newly flashed modem that may be applicable to your problem.

Q2686 Modem with F/W 7.1 - 7.4 & appropriate OpenAT dev kit.

If I reflash the modem firmware using DWLWin (or simply erase the application & flash objects using DWLWin) and reload my application, the WIP library bearer initialization ALWAYS fails with an invalid parameter error and won’t connect to the internet.

My workaround is to let the modem connect to the GSM network before downloading my application. Once the modem has connected to the network, I issue the following AT command:

AT+CGDCONT=1,"IP",fred.net"

and then download my application.
Once this command has been run, my application will reliably start and run (until the firmware is flashed)…

Took me ages to work this one out!

ciao, Dave

interesting. i’ve never noticed this issue…
i’m going to try this out after i get back from my vacation :slight_smile:

Hi Guys,

Added the adl_simSubscribe() function call from adl_main; wait for the ADL_SIM_EVENT_FULL_INIT event.

Once recieved I call myConnectToGPRS() which opens bearer, set’s options & starts bearer.

After call of wip_bearerStart I recieve WIP_BERR_OK_INPROGRESS event.

I then wait for 20 seconds to give the connection time to complete.

After that I recieve WIP_BEV_IP_CONNECTED event from myHandler :smiley:

09/08/03,09:39:38:671	ADL	1	Binary header at 00260000
09/08/03,09:39:38:703	ADL	1	Waiting 10 sec. before start the application....
09/08/03,09:39:46:671	ADL	1	DTMF Keyboard sample main
09/08/03,09:39:46:671	ADL	1	Aug  3 2009
09/08/03,09:39:46:718	ADL	1	21:37:47
09/08/03,09:39:46:718	ADL	1	Subscribe to Keyboard Service
09/08/03,09:39:46:718	ADL	3	wip_netInit () Successful
09/08/03,09:39:46:718	ADL	1	Subscribe to SIM Service
09/08/03,09:39:46:734	ADL	3	(evh_sim) Enter.
09/08/03,09:39:46:734	ADL	3	SIM NOT subscribed 2
09/08/03,09:39:46:765	ADL	3	SIM state 2
09/08/03,09:39:47:203	ADL	3	(evh_sim) Enter.
09/08/03,09:39:47:203	ADL	3	SIM NOT subscribed 5
09/08/03,09:39:47:203	ADL	3	SIM state 5
09/08/03,09:39:47:218	ADL	3	(evh_sim) Enter.
09/08/03,09:39:47:218	ADL	3	ADL_SIM_EVENT_FULL_INIT
09/08/03,09:39:47:218	ADL	3	SIM subscribed 3
09/08/03,09:39:47:234	ADL	3	SIM state 3
09/08/03,09:39:47:250	ADL	3	bearerOpenReturn 0
09/08/03,09:39:47:250	ADL	3	Configure GPRS Interface
09/08/03,09:39:47:265	ADL	3	Start Connection
09/08/03,09:39:47:265	ADL	3	WIP_BERR_OK_INPROGRESS
09/08/03,09:39:47:281	ADL	3	Wait 20 seconds
09/08/03,09:40:12:281	ADL	3	In myHandler 
09/08/03,09:40:12:296	ADL	3	WIP_BEV_IP_CONNECTED - IP connectivity we can start IP application from here

Thanks for all the input! It’s helped a lot!

Cheers,
Stef

Hiya,

Please do - I would be grateful for someone else to confirm it. It took me three or four days to track down why my code stopped working when I put it in a new module.

I’ve also seen the failure to connect issue when using the Wavecom WIP samples - but only on the FIRST time the sample code is run in a freshly flashed module. The second (and subsequent) time all is well…

ciao, Dave

Hello David,
I have the exact same problem as this one becasue my application is based on the sample(ftp client).

I found this problem when we started doing the production, alwasy can’t connect the first time in a freshly flashed module.
I monitored the trace, the following is what we get

(poll_creg_callback) Registered on GPRS network.
[GPRS]: open: → DISCONNECTED
[GPRS]: start: GPRS setup failed: -3
ASSERTION FAILURE LINE 208: 0==R || WIP_BERR_OK_INPROGRESS == R

which is from code:

r = wip_bearerStart( b);

ASSERT( 0 == r || WIP_BERR_OK_INPROGRESS == r);

Currently I just ask them to restart again, do you have any solution?

Thanks
Yong

this problem doesn’t occur if i upgrade the module firmware using at+wdwl. or erase application and settings using at+wopen.

can you confirm that it only occurs using dwlwin?

Here’s a debugging suggestion:

Use the old TMT, and enable the ATI Level 1 Traces:


(you can probably also do this in M2MStudio - I just don’t know how)

This will let you see the AT commands that WIP is using internally - and, most importantly, any error responses to those commands.

Also be sure that you’ve enabled all the WIP traces - see: Multiple HTTP Requests - every other one fails

You should also check precisely what return code you’re getting from wip_bearerStart - the ASSERT is just telling you that it’s neither OK nor WIP_BERR_OK_INPROGRESS…

In Developer Studio 1.2.0, it’s like this:

  1. Click the ‘Remote traces configuration’ button (crossed screwdriver & spanner) on the Traces view
  2. Uncheck ‘Display only application flows’
  3. You should now see ATI, and be able to check the ‘1’ box…